From 8176a6b2060a4912d700befcbb711112ca532ad9 Mon Sep 17 00:00:00 2001 From: Niels Kaspers Date: Sun, 29 Mar 2026 19:32:02 +0300 Subject: [PATCH] fix: convert to BigInt before multiplying to avoid nanosecond precision loss MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Epoch milliseconds multiplied by 1,000,000 as a Number exceed Number.MAX_SAFE_INTEGER (9,007,199,254,740,991), causing IEEE 754 floating-point precision loss before the BigInt conversion. The fix converts to BigInt first, then multiplies — matching the existing correct pattern in convertDateToNanoseconds(). Fixes #3292 Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/webapp/app/v3/eventRepository/common.server.ts | 4 ++-- apps/webapp/app/v3/eventRepository/index.server.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/webapp/app/v3/eventRepository/common.server.ts b/apps/webapp/app/v3/eventRepository/common.server.ts index 3ba8a50c7f7..5d5d0e201f1 100644 --- a/apps/webapp/app/v3/eventRepository/common.server.ts +++ b/apps/webapp/app/v3/eventRepository/common.server.ts @@ -21,7 +21,7 @@ export function extractContextFromCarrier(carrier: Record) { } export function getNowInNanoseconds(): bigint { - return BigInt(new Date().getTime() * 1_000_000); + return BigInt(new Date().getTime()) * BigInt(1_000_000); } export function getDateFromNanoseconds(nanoseconds: bigint): Date { @@ -35,7 +35,7 @@ export function calculateDurationFromStart( ) { const $endtime = typeof endTime === "string" ? new Date(endTime) : endTime; - const duration = Number(BigInt($endtime.getTime() * 1_000_000) - startTime); + const duration = Number(BigInt($endtime.getTime()) * BigInt(1_000_000) - startTime); if (minimumDuration && duration < minimumDuration) { return minimumDuration; diff --git a/apps/webapp/app/v3/eventRepository/index.server.ts b/apps/webapp/app/v3/eventRepository/index.server.ts index 2f457e23593..5fca0e8a761 100644 --- a/apps/webapp/app/v3/eventRepository/index.server.ts +++ b/apps/webapp/app/v3/eventRepository/index.server.ts @@ -214,7 +214,7 @@ async function recordRunEvent( runId: foundRun.friendlyId, ...attributes, }, - startTime: BigInt((startTime?.getTime() ?? Date.now()) * 1_000_000), + startTime: BigInt(startTime?.getTime() ?? Date.now()) * BigInt(1_000_000), ...optionsRest, });