fix(test-optimization): use unmocked monotonic clock for telemetry durations #11495
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 344 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.350
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #11495"
general
weight: 0.35
juan-fernandez
What does this PR do?
process.hrtime.bigintat module load inpackages/dd-trace/src/ci-visibility/telemetry.js(monotonicNow), returning elapsed milliseconds relative to a module-load origin (Number(hrtimeBigint() - clockOriginNs) / 1e6) so fake timers patchingDate.now(),performance.now(), orprocess.hrtime(including on Node.js 18 whereperformance.now()readsprocess.hrtime()) cannot skew durations.Date.now()andperformance.now()telemetry duration measurements withmonotonicNow()across all Test Optimization_MStelemetry emitters:-
packages/dd-trace/src/ci-visibility/exporters/agentless/writer.js-
packages/dd-trace/src/ci-visibility/exporters/agentless/coverage-writer.js-
packages/dd-trace/src/encode/agentless-ci-visibility.js-
packages/dd-trace/src/encode/coverage-ci-visibility.js-
packages/dd-trace/src/ci-visibility/exporters/git/git_metadata.js-
packages/dd-trace/src/ci-visibility/requests/get-library-configuration.js-
packages/dd-trace/src/ci-visibility/intelligent-test-runner/get-skippable-suites.js-
packages/dd-trace/src/ci-visibility/early-flake-detection/get-known-tests.js-
packages/dd-trace/src/ci-visibility/test-management/get-test-management-tests.js-
packages/dd-trace/src/ci-visibility/requests/upload-coverage-report.js-
packages/dd-trace/src/plugins/util/git.jsDate.now()for the two 5000msexecFileSyncretry deadline budgets ingit.jsso fake-timer deadline tests and behavior remain unchanged.telemetry.spec.js,writer.spec.js, andcoverage-writer.spec.js(capturing a controllableprocess.hrtime.bigintstub at module load and asserting exact elapsed durations across fake-timer ticks and restoration), and updatesget-known-tests.spec.jsto stubmonotonicNow.Motivation
Test suites commonly use fake timers (
sinon.useFakeTimers, Jest fake timers, Vitest fake timers) that patch globalDate.now(),performance.now(), andprocess.hrtimeto jump forward/backward in simulated time (or reset to epoch0). When a Test Optimization request or payload encoding spans a fake-timer installation, tick, or restoration,Date.now() - startTimeproduces wildly skewed durations (negative values or multi-decade epochs) in_mstelemetry distributions. Capturing the nativeprocess.hrtime.bigintreference at module load isolates internal telemetry timing from test timer mocks across all supported Node.js versions.Additional Notes
Validated on Node.js v24.14.1 (
7.0.0-preand v55.0.0compatibility on all modified Test Optimization specs),eslint, andeditorconfig.Made with Cursor