From 65e5e3872f7f369d12f737c20c24846899bf36e0 Mon Sep 17 00:00:00 2001 From: aayushbaluni <73417844+aayushbaluni@users.noreply.github.com> Date: Wed, 15 Apr 2026 17:39:55 +0530 Subject: [PATCH] fix: convert to BigInt before nanosecond multiplication in all instances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #3292 Multiple functions compute nanosecond timestamps as BigInt(milliseconds * 1_000_000). When milliseconds exceed Number.MAX_SAFE_INTEGER / 1_000_000 (≈ 9.007e9, i.e. any date after ~1970-04-15), the multiplication overflows IEEE 754 precision before the BigInt conversion captures it. Fix all instances (including runEngineHandlers.server.ts:432 which was missed in the previous PR #3378) by converting to BigInt first: BigInt(milliseconds) * BigInt(1_000_000) Made-with: Cursor --- apps/webapp/app/v3/eventRepository/common.server.ts | 8 +++++--- apps/webapp/app/v3/eventRepository/index.server.ts | 2 +- apps/webapp/app/v3/runEngineHandlers.server.ts | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/webapp/app/v3/eventRepository/common.server.ts b/apps/webapp/app/v3/eventRepository/common.server.ts index 3ba8a50c7f7..471d86e58a1 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; @@ -47,7 +47,9 @@ export function calculateDurationFromStart( export function calculateDurationFromStartJsDate(startTime: Date, endTime: Date = new Date()) { const $endtime = typeof endTime === "string" ? new Date(endTime) : endTime; - return ($endtime.getTime() - startTime.getTime()) * 1_000_000; + return Number( + (BigInt($endtime.getTime()) - BigInt(startTime.getTime())) * BigInt(1_000_000) + ); } export function convertDateToNanoseconds(date: Date): bigint { diff --git a/apps/webapp/app/v3/eventRepository/index.server.ts b/apps/webapp/app/v3/eventRepository/index.server.ts index 70ea6440321..edc0280baf2 100644 --- a/apps/webapp/app/v3/eventRepository/index.server.ts +++ b/apps/webapp/app/v3/eventRepository/index.server.ts @@ -215,7 +215,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, }); diff --git a/apps/webapp/app/v3/runEngineHandlers.server.ts b/apps/webapp/app/v3/runEngineHandlers.server.ts index e728160f00f..d6ff41bc196 100644 --- a/apps/webapp/app/v3/runEngineHandlers.server.ts +++ b/apps/webapp/app/v3/runEngineHandlers.server.ts @@ -429,7 +429,7 @@ export function registerRunEngineEventBusHandlers() { const eventRepository = resolveEventRepositoryForStore(run.taskEventStore); await eventRepository.recordEvent(retryMessage, { - startTime: BigInt(time.getTime() * 1000000), + startTime: BigInt(time.getTime()) * BigInt(1_000_000), taskSlug: run.taskIdentifier, environment, attributes: {