Skip to content

Commit 8176a6b

Browse files
nielskaspersclaude
andcommitted
fix: convert to BigInt before multiplying to avoid nanosecond precision loss
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) <noreply@anthropic.com>
1 parent 2366b21 commit 8176a6b

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

apps/webapp/app/v3/eventRepository/common.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function extractContextFromCarrier(carrier: Record<string, unknown>) {
2121
}
2222

2323
export function getNowInNanoseconds(): bigint {
24-
return BigInt(new Date().getTime() * 1_000_000);
24+
return BigInt(new Date().getTime()) * BigInt(1_000_000);
2525
}
2626

2727
export function getDateFromNanoseconds(nanoseconds: bigint): Date {
@@ -35,7 +35,7 @@ export function calculateDurationFromStart(
3535
) {
3636
const $endtime = typeof endTime === "string" ? new Date(endTime) : endTime;
3737

38-
const duration = Number(BigInt($endtime.getTime() * 1_000_000) - startTime);
38+
const duration = Number(BigInt($endtime.getTime()) * BigInt(1_000_000) - startTime);
3939

4040
if (minimumDuration && duration < minimumDuration) {
4141
return minimumDuration;

apps/webapp/app/v3/eventRepository/index.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ async function recordRunEvent(
214214
runId: foundRun.friendlyId,
215215
...attributes,
216216
},
217-
startTime: BigInt((startTime?.getTime() ?? Date.now()) * 1_000_000),
217+
startTime: BigInt(startTime?.getTime() ?? Date.now()) * BigInt(1_000_000),
218218
...optionsRest,
219219
});
220220

0 commit comments

Comments
 (0)