Skip to content

fix(webapp): convert epoch ms to BigInt before nanosecond multiplication - #5027

Closed
oziass wants to merge 1 commit into
triggerdotdev:mainfrom
oziass:job_42
Closed

oziass wants to merge 1 commit into
triggerdotdev:mainfrom
oziass:job_42

Conversation

@oziass

@oziass oziass commented Oct 14, 2026 •

Copy link
Copy Markdown

Multiplying epoch milliseconds by 1_000_000 as a Number exceeds Number.MAX_SAFE_INTEGER, so the product is rounded to a multiple of 256 before it is converted to BigInt. Span start times and durations could therefore be off by up to a few hundred nanoseconds.

This updates getNowInNanoseconds and calculateDurationFromStart in common.server.ts to use convertDateToNanoseconds, and converts milliseconds to BigInt before multiplying by BigInt(1_000_000) in index.server.ts and runEngineHandlers.server.ts.

Fixes #3292
/claim #3292

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

Added colocated unit tests in apps/webapp/app/v3/eventRepository/common.server.test.ts covering exact epoch conversion, a real-clock nanosecond assertion, duration precision, and minimum duration. No fake timers are used. All four tests pass with NODE_ENV=test node ../../node_modules/vitest/vitest.mjs run app/v3/eventRepository/common.server.test.ts from apps/webapp.

The test directory is included in Vitest discovery. The updated fork branch is oziass:job_42 at 33f68e7456275e66cee691c943e964f74f3ddfed.


Changelog

Fixed floating-point precision loss when converting millisecond timestamps to nanoseconds in the webapp event repository and run engine handlers.


Screenshots

N/A

Multiplying epoch milliseconds by 1e6 as a Number exceeds
Number.MAX_SAFE_INTEGER, so the product is rounded to a multiple of 256
before it is converted to BigInt. Span start times and durations could
therefore be off by up to a few hundred nanoseconds.

Fixes triggerdotdev#3292
@changeset-bot

changeset-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d68ba3d

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 @oziass, 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 Oct 14, 2026
@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 82c5142a-1394-4ac7-b71f-8325b2a5efb5
📥 Commits

Reviewing files that changed from the base of the PR and between 3a1f00b and d68ba3d.

📒 Files selected for processing: 4
  • apps/webapp/app/v3/eventRepository/common.server.ts
  • apps/webapp/app/v3/eventRepository/index.server.ts
  • apps/webapp/app/v3/runEngineHandlers.server.ts
  • apps/webapp/test/eventRepositoryCommon.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Devin Review

Comment on lines +23 to +24
vi.useFakeTimers();
vi.setSystemTime(unsafeMs);

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.

🔍 Clock fakes in conversion test

The getNowInNanoseconds test replaces the clock with fake timers. The repository's testing rules prohibit fakes; use a real-clock assertion or a testable clock input.

Devin Review


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

Comment on lines +1 to +6
import { afterEach, describe, expect, it, vi } from "vitest";
import {
calculateDurationFromStart,
convertDateToNanoseconds,
getNowInNanoseconds,
} from "~/v3/eventRepository/common.server";

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.

🔍 Conversion tests are not colocated

The new conversion tests live outside the event repository. The repository's testing guide requires new test files beside the source they exercise.

Devin Review


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

@oziass

oziass commented Oct 14, 2026

Copy link
Copy Markdown
Author

Updated in 33f68e7 to resolve both review findings:

  • Colocated the unit test beside the source at �pps/webapp/app/v3/eventRepository/common.server.test.ts and registered it in the Vitest include list.
  • Removed �i.useFakeTimers() in getNowInNanoseconds() and replaced it with a real-clock precision assertion.

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