✅ delay /empty.css response to fix WebKit early-timings flake#4631
Merged
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1dedbfc870
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
WebKit clamps `PerformanceResourceTiming` timestamps and `performance.now()` to 1ms (privacy/Spectre mitigation). For the zero-byte `/empty.css` served over fast (Linux CI) loopback, the entire request occasionally completes in a single 1ms tick, collapsing every timestamp to the same value. The SDK then truthfully emits `duration: 0` and `download.start: 0`, and the strict `> 0` assertion in `expectToHaveValidTimings` fails — top flaky E2E this week (28/24/21 occurrences for the async/npm/bundle variants). Adding a 50ms server-side delay guarantees `startTime < responseEnd` even under 1ms clamping. Keeps `expectToHaveValidTimings` strict, so a real regression that zeroed duration would still be caught on every browser.
1dedbfc to
34b1150
Compare
duration > 0 on WebKit early-timings test
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 34b1150 | Docs | Datadog PR Page | Give us feedback! |
Bundles Sizes Evolution
🚀 CPU PerformancePending... 🧠 Memory PerformancePending... |
bdibon
approved these changes
May 19, 2026
rgaignault
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fix the top 3 flaky E2E tests of the last 7 days:
rum resources › retrieve early requests timings(async / npm / bundle), with 28 / 24 / 21 occurrences across many branches.https://app.datadoghq.com/ci/test-runs?query=%40test.flaky%3Atrue%20%40git.repository.id_v2%3Agithub.com%2Fdatadog%2Fbrowser-sdk%20%40test.name%3A%22rum%20resources%20%E2%80%BA%20retrieve%20early%20requests%20timings%22
https://app.datadoghq.com/ci/test-runs?query=%40test.flaky%3Atrue%20%40git.repository.id_v2%3Agithub.com%2Fdatadog%2Fbrowser-sdk
Root cause (verified on CI)
WebKit clamps
PerformanceResourceTimingtimestamps andperformance.now()to 1ms resolution (privacy/Spectre mitigation). For the zero-byte/empty.cssserved over fast Linux CI loopback, the entire request occasionally completes inside a single 1ms tick. When that happens, every timestamp on the entry (startTime,requestStart,responseStart,responseEnd, …) clamps to the same value, and the SDK truthfully emitsduration: 0anddownload.start: 0. The existing Safari fallback incomputeResourceEntryDuration(packages/rum-core/src/domain/resource/resourceUtils.ts:76) only fires whenstartTime < responseEnd, so it cannot help when they're equal.Repro evidence
Verified on CI via PR #4630 (instrumentation +
--repeat-each=30 --retries=0,webkit-pinned+chromium):Sample failing entry from the without-fix run:
Compare with Chromium (100 μs resolution — actual sub-ms digits):
Approach: server-side delay on
/empty.cssAdd a 50 ms
setTimeoutbefore the response in the mock server. With a 50 ms gap betweenstartTimeandresponseEnd, WebKit's 1 ms clamping cannot collapse them —responseStartandresponseEndare guaranteed to fall in different ticks, so the SDK reports real non-zerodurationanddownload.start.Alternatives considered:
duration >= 0: would silently mask a real bug if the SDK started reportingduration: 0on Chromium/Firefox (raised by automated review on the earlier iteration of this PR).durationto a minimum in the SDK: fabricates data for customer dashboards; doesn't fixdownload.start: 0either.The server delay keeps
expectToHaveValidTimingsstrict on every browser, so any future regression that zeroes a duration would still be caught.Changes
test/e2e/lib/framework/serverApps/mock.ts: wrap the/empty.cssresponse in a 50 mssetTimeout. Comment explains the WebKit clamping and links the failure mode.Test instructions
yarn test:e2e -g "retrieve early requests timings" --project=webkit-pinned --repeat-each=10— 10/10 passed.webkit-pinnedandchromiumwith--repeat-each=30 --retries=0(compared with 17/90 webkit failures before the fix).Checklist