Skip to content

fix: prevent nanosecond timestamp overflow in event repository - #4499

Closed
AkhilTrivediX wants to merge 1 commit into
triggerdotdev:mainfrom
AkhilTrivediX:fix/timestamp-overflow
Closed

fix: prevent nanosecond timestamp overflow in event repository#4499
AkhilTrivediX wants to merge 1 commit into
triggerdotdev:mainfrom
AkhilTrivediX:fix/timestamp-overflow

Conversation

@AkhilTrivediX

Copy link
Copy Markdown

Resolves #3292

Fixes IEEE 754 precision loss that was occurring when multiplying epoch milliseconds by 1,000,000 in float-land before casting to BigInt.

The fix properly casts the epoch milliseconds to BigInt before multiplying by BigInt(1_000_000), completely preventing the ~256ns errors in timestamp values.

This affects:

  • getNowInNanoseconds()
  • calculateDurationFromStart()
  • recordRunDebugLog()
  • Retry event recording in runEngineHandlers.server.ts

@changeset-bot

changeset-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 57d2b11

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

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Hi @AkhilTrivediX, 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 Aug 4, 2026

@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 found 2 potential issues.

Open in Devin Review


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.

🟡 Server-only change ships without a release-notes entry

This change only touches server code under apps/webapp/ but no .server-changes/ note was added (see CONTRIBUTING.md and AGENTS.md), so the fix will be missing from the user-visible release notes.
Impact: Users reading the release notes won't see that the timestamp accuracy issue was fixed.

Repository rule: server-only PRs require a .server-changes entry

CONTRIBUTING.md states: "If your PR only changes server components (apps/webapp/, apps/supervisor/, etc.) with no package changes, add a .server-changes/ file so the change appears in release notes." The diff modifies only apps/webapp/app/v3/eventRepository/common.server.ts, apps/webapp/app/v3/eventRepository/index.server.ts and apps/webapp/app/v3/runEngineHandlers.server.ts, and the branch adds no file under .server-changes/. The file needs frontmatter area: webapp and type: fix plus a one-line user-facing description.

Prompt for agents
The PR changes only server code under apps/webapp, so per CONTRIBUTING.md and AGENTS.md it needs a markdown file in .server-changes/ (e.g. .server-changes/fix-event-timestamp-precision.md) with frontmatter 'area: webapp' and 'type: fix', and a one-line, user-facing body describing the behavior change (e.g. run timeline timestamps are now recorded exactly instead of being off by a fraction of a microsecond). Follow the writing guidance in .server-changes/README.md.
Open in Devin Review

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

...attributes,
},
startTime: BigInt((startTime?.getTime() ?? Date.now()) * 1_000_000),
startTime: BigInt(startTime?.getTime() ?? Date.now()) * 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.

🔍 Fix changes stored timestamp values; verify no downstream equality/dedup depends on old rounded values

Timestamps produced by getNowInNanoseconds/recordRunEvent/the retry event now carry exact nanosecond values instead of values rounded to the nearest 256ns. Any persisted data written before this change (ClickHouse/Postgres task events) keeps the old rounded values, so exact-equality comparisons or joins between newly written start times and previously derived values (e.g. span start/end matching, dedup keys built from start time) could behave differently across the deploy boundary. Callers I checked compute durations or ranges rather than exact matches, so this appears safe, but it's worth a second look at anything keying on startTime exactly.

Open in Devin Review

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

@coderabbitai

coderabbitai Bot commented Aug 4, 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 Plus

Run ID: ab3eef60-cca1-4f02-a9e0-468554a42aab

📥 Commits

Reviewing files that changed from the base of the PR and between fbd6df3 and 57d2b11.

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

Walkthrough

Timestamp conversion logic now converts millisecond values to BigInt before multiplying by 1,000,000. The change applies to current timestamps, duration calculations, recorded run events, and retry event timestamps.

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

@AkhilTrivediX

Copy link
Copy Markdown
Author

Just realized someone else had already submitted a fix for this (#3381) and is just waiting for a vouch as well. Apologies for the duplicate!

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

2 participants