Skip to content

fix(network-activity-plugin): align Nitro timestamps with wall time - #561

Merged
V3RON merged 2 commits into
callstackincubator:mainfrom
lorenc-tomasz:bugfix/nitro-network-timestamps
Oct 15, 2026
Merged

V3RON merged 2 commits into
callstackincubator:mainfrom
lorenc-tomasz:bugfix/nitro-network-timestamps

Conversation

@lorenc-tomasz

@lorenc-tomasz lorenc-tomasz commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fix incorrect start times and excessively stretched timelines for Nitro HTTP and WebSocket traffic in Network Activity.

Calculate the timestamp origin using Date.now() - performance.now() so Nitro events align with built-in network events.

Related Issue

No related issue.

Context

On affected React Native iOS runtimes, performance.timeOrigin and performance.now() can use different clock bases. The adapter previously trusted timeOrigin whenever it was available, causing Nitro timestamps to shift relative to wall-clock time.

The fix derives the offset from the clock Nitro actually uses. Event timestamps remain in epoch milliseconds, and elapsed durations are preserved.

Includes regression coverage for shifted, aligned, and missing timeOrigin values across HTTP requests, cancellations, and WebSocket events, plus a patch changeset.

Testing

  • pnpm checks:affected — passed.
  • pnpm test:affected — 268 tests passed.
  • pnpm release:plan — passed.
  • Repeated 25 adapter, formatting, and timeline tests in each of six time zones: UTC, Europe/Warsaw, America/New_York, Asia/Kolkata, Asia/Kathmandu, and Pacific/Kiritimati.
  • Verified clock formatting across daylight-saving transitions and date boundaries; elapsed timeline durations remained correct.
  • Confirmed the regression tests fail before the fix and pass afterward.

Manual:

  • Verified on Android and iOS in our React Native application using the equivalent patch-package fix.
  • Verified Nitro GET and POST requests in the Rozenite playground on an iPhone 16 Pro Max simulator running iOS 18.6, 26.1 and 27.0. Network Activity displayed the correct local start times and request durations.

@lorenc-tomasz
lorenc-tomasz marked this pull request as ready for review October 15, 2026 11:34
…conversion

The monotonic clock behind performance.now() pauses while the device
sleeps, so an offset cached at module load drifts from Date.now() for
the rest of the session.

@V3RON V3RON 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.

Thanks, the diagnosis holds. In React Native, NativePerformance::now() on Apple uses mach_absolute_time(), which pauses during sleep, while timeOrigin() subtracts libc++'s steady_clock (CLOCK_MONOTONIC_RAW, which counts sleep). So timeOrigin + now() lags wall time by the device's total sleep since boot. Android uses CLOCK_MONOTONIC for both, so it doesn't have this particular mismatch.

I pushed one follow-up commit: the offset is now sampled on every conversion instead of once at module load. The monotonic clock pauses during sleep on both iOS and Android, so a cached offset drifts after the device locks mid-session. The commit also adds a regression test for that case and updates the stale timeOrigin comment in recorder.ts.

@V3RON
V3RON self-requested a review October 15, 2026 11:46
@lorenc-tomasz

Copy link
Copy Markdown
Contributor Author

Thanks :)

@V3RON
V3RON merged commit 4ca9479 into callstackincubator:main Oct 15, 2026
1 check passed
@lorenc-tomasz
lorenc-tomasz deleted the bugfix/nitro-network-timestamps branch October 15, 2026 18:20
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.

2 participants