Skip to content

fix(events): prevent float precision loss in nanosecond timestamp conversion#4315

Closed
okxint wants to merge 1 commit into
triggerdotdev:mainfrom
okxint:fix/bigint-nanosecond-precision
Closed

fix(events): prevent float precision loss in nanosecond timestamp conversion#4315
okxint wants to merge 1 commit into
triggerdotdev:mainfrom
okxint:fix/bigint-nanosecond-precision

Conversation

@okxint

@okxint okxint commented Jul 21, 2026

Copy link
Copy Markdown

Fixes #3292

new Date().getTime() * 1_000_000 is computed as a JS number before being passed to BigInt(). The result (~1.7e18) exceeds Number.MAX_SAFE_INTEGER (9.007e15), so IEEE 754 precision loss corrupts the timestamp before the BigInt is even created.

The correct helper convertDateToNanoseconds() already exists in common.server.ts and uses BigInt(date.getTime()) * BigInt(1_000_000) — converting to BigInt first, then multiplying — which preserves full precision.

Changes:

  • common.server.ts getNowInNanoseconds: replace inline multiply with convertDateToNanoseconds(new Date())
  • common.server.ts calculateDurationFromStart: replace inline multiply with convertDateToNanoseconds($endtime)
  • index.server.ts recordRunEvent: replace inline multiply with convertDateToNanoseconds(startTime ?? new Date()) + import the helper

…version

Multiplying milliseconds by 1_000_000 before BigInt conversion loses precision
because the result (~1.7e18) exceeds Number.MAX_SAFE_INTEGER. Switch all three
call sites to use convertDateToNanoseconds(), which does BigInt(ms) * BigInt(1_000_000)
and keeps the arithmetic in BigInt-land throughout.
@changeset-bot

changeset-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9822ab3

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 @okxint, 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 Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 57d486c0-a73b-4a09-9d6d-14089b33a002

📥 Commits

Reviewing files that changed from the base of the PR and between cc74842 and 9822ab3.

📒 Files selected for processing (3)
  • .server-changes/fix-bigint-nanosecond-precision.md
  • apps/webapp/app/v3/eventRepository/common.server.ts
  • apps/webapp/app/v3/eventRepository/index.server.ts

Walkthrough

The change replaces floating-point millisecond-to-nanosecond conversions with convertDateToNanoseconds for current timestamps, duration calculations, and recorded run-event start times. Existing bigint arithmetic, duration clamping, fallback date behavior, and public function signatures remain unchanged. A change-log entry documents the precision fix.

✨ 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.

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

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.

✅ Devin Review: No Issues Found

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

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