Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/webapp/app/v3/eventRepository/common.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function extractContextFromCarrier(carrier: Record<string, unknown>) {
}

export function getNowInNanoseconds(): bigint {
return BigInt(new Date().getTime() * 1_000_000);
return BigInt(new Date().getTime()) * BigInt(1_000_000);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Same BigInt precision bug remains unfixed in runEngineHandlers.server.ts

This PR fixes the BigInt(x * 1_000_000) precision loss pattern in three locations, but the exact same bug exists at apps/webapp/app/v3/runEngineHandlers.server.ts:467:

startTime: BigInt(time.getTime() * 1000000),

This should be BigInt(time.getTime()) * BigInt(1000000) for consistency with the other fixes. The intermediate time.getTime() * 1000000 exceeds Number.MAX_SAFE_INTEGER (~9e15) since current timestamps produce values around ~1.7e18, causing up to ~512 nanoseconds of precision loss. While nanosecond-level jitter may not matter for event timestamps in practice, it's inconsistent to fix three instances and leave a fourth.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

}

export function getDateFromNanoseconds(nanoseconds: bigint): Date {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/app/v3/eventRepository/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,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,
});

Expand Down