Skip to content

Commit a87496b

Browse files
fix(webapp): convert epoch-ms to BigInt before nanosecond multiply
Avoids IEEE 754 precision loss when ms * 1e6 exceeds Number.MAX_SAFE_INTEGER. Closes #3292
1 parent a7c734c commit a87496b

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: fix
4+
---
5+
6+
Improve accuracy of run timeline timestamps by converting times to nanoseconds without floating-point rounding errors.

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

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

2727
export function getNowInNanoseconds(): bigint {
28-
return BigInt(new Date().getTime() * 1_000_000);
28+
return BigInt(new Date().getTime()) * BigInt(1_000_000);
2929
}
3030

3131
export function getDateFromNanoseconds(nanoseconds: bigint): Date {
@@ -39,7 +39,7 @@ export function calculateDurationFromStart(
3939
) {
4040
const $endtime = typeof endTime === "string" ? new Date(endTime) : endTime;
4141

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

4444
if (minimumDuration && duration < minimumDuration) {
4545
return minimumDuration;

‎apps/webapp/app/v3/runEngineHandlers.server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ export function registerRunEngineEventBusHandlers() {
555555
);
556556

557557
await eventRepository.recordEvent(retryMessage, {
558-
startTime: BigInt(time.getTime() * 1000000),
558+
startTime: BigInt(time.getTime()) * BigInt(1_000_000),
559559
taskSlug: run.taskIdentifier,
560560
environment,
561561
attributes: {

0 commit comments

Comments
 (0)