Skip to content

fix: prevent BigInt nanosecond precision loss in OTLP timestamps#3294

Closed
nielskaspers wants to merge 1 commit intotriggerdotdev:mainfrom
nielskaspers:fix/issue-3292-bigint-nanosecond-overflow
Closed

fix: prevent BigInt nanosecond precision loss in OTLP timestamps#3294
nielskaspers wants to merge 1 commit intotriggerdotdev:mainfrom
nielskaspers:fix/issue-3292-bigint-nanosecond-overflow

Conversation

@nielskaspers
Copy link
Copy Markdown

Summary

Fix IEEE 754 precision loss when converting epoch milliseconds to nanoseconds by performing BigInt conversion before multiplication instead of after.

Issue

Fixes #3292

Changes

  • getNowInNanoseconds(): convert to BigInt before multiplying by 1,000,000
  • calculateDurationFromStart(): same BigInt-first conversion
  • recordRunDebugLog(): same BigInt-first conversion

All three fixes now match the existing correct pattern in convertDateToNanoseconds() (line 54 of common.server.ts).

Testing

  • The change is purely arithmetic ordering — BigInt(ms) * BigInt(1_000_000) instead of BigInt(ms * 1_000_000)
  • No behavioral change for values within Number.MAX_SAFE_INTEGER; eliminates ~256ns errors for the ~0.2% of cases where float multiplication exceeded safe integer range

…on 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 triggerdotdev#3292

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 29, 2026

⚠️ No Changeset found

Latest commit: 8176a6b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

Hi @nielskaspers, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions bot closed this Mar 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cb06c50c-c676-4ea9-a7bb-cef9a6fb8492

📥 Commits

Reviewing files that changed from the base of the PR and between 2366b21 and 8176a6b.

📒 Files selected for processing (2)
  • apps/webapp/app/v3/eventRepository/common.server.ts
  • apps/webapp/app/v3/eventRepository/index.server.ts

Walkthrough

The pull request refactors BigInt conversion order in timestamp calculations across the event repository module. In both common.server.ts and index.server.ts, three functions are updated to convert millisecond timestamps to BigInt before multiplying by 1_000_000, rather than multiplying the number first and then converting the result. Functions affected are getNowInNanoseconds(), calculateDurationFromStart(), and recordRunEvent(). No control flow, logic, or return behavior was modified.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OTLP nanosecond timestamp overflow in webapp event repository

1 participant