You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OTLP nanosecond timestamp overflow in webapp event repository #3292
Several places in the webapp multiply epoch milliseconds by 1,000,000 before converting to BigInt, which causes IEEE 754 precision loss (~256ns errors in ~0.2% of cases). The result exceeds Number.MAX_SAFE_INTEGER (~9e15) since epoch-ms * 1e6 is ~1.7e18.
The correct pattern is BigInt(ms) * BigInt(1_000_000) (multiplication after BigInt conversion). This already exists in convertDateToNanoseconds() in the same file - the buggy functions just didn't use it.
Impact: Low. The errors are +-256 nanoseconds, which is unlikely to cause visible issues. But it's an easy fix and prevents any edge cases with span ordering.
Context: Found during compute workload manager PR review (#3114). The supervisor's msToNano() was fixed in that PR using a split approach that also preserves sub-ms precision from performance.now() arithmetic.
I've submitted PR #3381 fixing all instances of the BigInt overflow pattern, including the one at runEngineHandlers.server.ts:432 that was missed in the previous PR #3378. However, the PR was auto-closed because I need to be vouched as a contributor. Could a maintainer please help with that?
Hi! I've written a fix for this precision loss issue and submitted PR #4499. However, the PR was automatically closed because I am not on the vouched contributors list yet. Could a maintainer please vouch for me so I can reopen the PR? Thank you!
Hi — noticed this is still open and the buggy BigInt(ms * 1e6) pattern is still on main in eventRepository/common.server.ts. Prior spam PRs were closed; no open claim.
Happy to ship a clean TS fix: switch all ms→ns sites to BigInt(ms) * BigInt(1_000_000) (matching convertDateToNanoseconds), plus a small regression test.
If useful, could you /bounty $125 on this issue via Algora? I’ll exclusive-PR within 48–72h as @robinthedev-a11y.
Happy to adjust amount/scope. Thanks for the OSS + past Algora payouts.
🔍 Root Cause Analysis & Complete Fix across all 4 Call Sites
Hey team,
I investigated the OTLP nanosecond timestamp precision loss on the current main branch.
Why this happens
In JavaScript, standard numbers are IEEE 754 64-bit floats with Number.MAX_SAFE_INTEGER = 9,007,199,254,740,991 (9e15). An epoch millisecond timestamp (1.78e12) multiplied by 1_000_000 produces ~1.78e18, which far exceeds Number.MAX_SAFE_INTEGER. Multiplying prior to BigInt conversion causes truncation/rounding errors (±256ns) in ~0.2% of timestamps.
The safe pattern (already used in convertDateToNanoseconds) is to cast to BigInt first: BigInt(ms) * BigInt(1_000_000)
Hey team — I put together a fix and colocated unit tests for this in PR #5027 (auto-closed by the vouch bot as a first-time contributor here):
Updated getNowInNanoseconds and calculateDurationFromStart in common.server.ts to use convertDateToNanoseconds so epoch ms is converted to BigInt before multiplying by 1_000_000.
Updated the remaining BigInt(ms * 1_000_000) sites in index.server.ts and
unEngineHandlers.server.ts to BigInt(ms) * BigInt(1_000_000).
Added real-clock unit tests in �pps/webapp/app/v3/eventRepository/common.server.test.ts (and resolved both Devin review notes in 33f68e7).
Could a maintainer vouch @oziass so #5027 can be reopened? Thanks!
I dug into this on current main (a3a8810) and measured it over 2M random 2026 timestamps. Two corrections to the description, plus a related bug the current proposals don't cover:
Frequency/magnitude: epoch-ns (~1.7e18) sits in the 2^60–2^61 range where doubles are spaced 256 apart, so BigInt(ms * 1_000_000) is wrong for ~75% of timestamps, by up to ±128 ns (not ~0.2% / 256 ns).
getDateFromNanoseconds loses a whole millisecond: it does new Date(Number(ns) / 1_000_000). Number(ns) rounds to the nearest multiple of 256, which can land just below a ms boundary, and Date truncates, so ~12.5% of ms-aligned timestamps read back 1 ms early (e.g. 1784051364922 → ...921). This still happens with an exact ns value, so switching the producers to BigInt(ms) * 1_000_000n alone doesn't fix it. It's used for span startTime in eventRepository.server.ts (4 call sites).
Suggested fix (5 lines, reusing the existing BigInt(ms) * 1_000_000n pattern from traceChunkAssembler.ts):
Regression cases that fail on current main and pass with the fix: 1784051364922 (rounds 128 ns low → reads back 1 ms early) and 1767631608910 (rounds 128 ns high). A random sweep of 2M samples (with sub-ms offsets) shows 0 mismatches after the change. I have this ready with vitest coverage if it would help.
Activity
fix: convert epoch-ms to BigInt before nanosecond multiplication
fix: prevent IEEE 754 precision loss in OTLP nanosecond timestamps
fix: convert to BigInt before nanosecond multiplication in all instances
fix: OTLP nanosecond timestamp overflow from IEEE 754 precision loss
aayushbaluni commentedon Apr 15, 2026
I've submitted PR #3381 fixing all instances of the BigInt overflow pattern, including the one at
runEngineHandlers.server.ts:432that was missed in the previous PR #3378. However, the PR was auto-closed because I need to be vouched as a contributor. Could a maintainer please help with that?fix: prevent nanosecond overflow in OTLP timestamps
fix(webapp): fix BigInt nanosecond precision loss in retry event star…
AkhilTrivediX commentedon Aug 4, 2026
Hi! I've written a fix for this precision loss issue and submitted PR #4499. However, the PR was automatically closed because I am not on the vouched contributors list yet. Could a maintainer please vouch for me so I can reopen the PR? Thank you!
robinthedev-a11y commentedon Sep 9, 2026
Hi — noticed this is still open and the buggy
BigInt(ms * 1e6)pattern is still on main ineventRepository/common.server.ts. Prior spam PRs were closed; no open claim.Happy to ship a clean TS fix: switch all ms→ns sites to
BigInt(ms) * BigInt(1_000_000)(matchingconvertDateToNanoseconds), plus a small regression test.If useful, could you
/bounty $125on this issue via Algora? I’ll exclusive-PR within 48–72h as@robinthedev-a11y.Happy to adjust amount/scope. Thanks for the OSS + past Algora payouts.
bilalhusain-dev commentedon Oct 12, 2026
🔍 Root Cause Analysis & Complete Fix across all 4 Call Sites
Hey team,
I investigated the OTLP nanosecond timestamp precision loss on the current
mainbranch.Why this happens
In JavaScript, standard numbers are IEEE 754 64-bit floats with
Number.MAX_SAFE_INTEGER = 9,007,199,254,740,991(9e15). An epoch millisecond timestamp (1.78e12) multiplied by1_000_000produces ~1.78e18, which far exceedsNumber.MAX_SAFE_INTEGER. Multiplying prior toBigIntconversion causes truncation/rounding errors (±256ns) in ~0.2% of timestamps.The safe pattern (already used in
convertDateToNanoseconds) is to cast toBigIntfirst:BigInt(ms) * BigInt(1_000_000)Proposed Fix (All 4 Affected Locations)
fix(webapp): convert epoch ms to BigInt before nanosecond multiplication
oziass commentedon Oct 14, 2026
/attempt #3292
Hey team — I put together a fix and colocated unit tests for this in PR #5027 (auto-closed by the vouch bot as a first-time contributor here):
unEngineHandlers.server.ts to BigInt(ms) * BigInt(1_000_000).
Could a maintainer vouch @oziass so #5027 can be reopened? Thanks!
fix(webapp): convert epoch ms to BigInt before nanosecond multiplication
prathviraj-03 commentedon Nov 20, 2026
I dug into this on current
main(a3a8810) and measured it over 2M random 2026 timestamps. Two corrections to the description, plus a related bug the current proposals don't cover:Frequency/magnitude: epoch-ns (~1.7e18) sits in the 2^60–2^61 range where doubles are spaced 256 apart, so
BigInt(ms * 1_000_000)is wrong for ~75% of timestamps, by up to ±128 ns (not ~0.2% / 256 ns).getDateFromNanosecondsloses a whole millisecond: it doesnew Date(Number(ns) / 1_000_000).Number(ns)rounds to the nearest multiple of 256, which can land just below a ms boundary, andDatetruncates, so ~12.5% of ms-aligned timestamps read back 1 ms early (e.g.1784051364922→...921). This still happens with an exact ns value, so switching the producers toBigInt(ms) * 1_000_000nalone doesn't fix it. It's used for spanstartTimeineventRepository.server.ts(4 call sites).Suggested fix (5 lines, reusing the existing
BigInt(ms) * 1_000_000npattern fromtraceChunkAssembler.ts):Regression cases that fail on current
mainand pass with the fix:1784051364922(rounds 128 ns low → reads back 1 ms early) and1767631608910(rounds 128 ns high). A random sweep of 2M samples (with sub-ms offsets) shows 0 mismatches after the change. I have this ready with vitest coverage if it would help.