Skip to content

fix(vitest): flush worker traces before file completion - #11394

Draft
juan-fernandez wants to merge 2 commits into
masterfrom
juan-fernandez/fix-vitest-worker-trace-buffer
Draft

juan-fernandez wants to merge 2 commits into
masterfrom
juan-fernandez/fix-vitest-worker-trace-buffer

Conversation

@juan-fernandez

@juan-fernandez juan-fernandez commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Send each completed Vitest trace as a plain object through the existing worker IPC transport. This avoids the file-sized JSON buffer and removes the parent process's two JSON parses per trace message. Final flushing waits for outstanding IPC sends.

Convert tracer IDs to hex strings before sending. Apply the previous JSON conversion to individual spans with non-finite metrics, negative zero, structured metadata, or span events. That preserves null for non-finite metrics and JSON's nested value conversion, including toJSON() hooks.

Motivation

Fixes #11390. A file's accumulated trace JSON can exceed V8's maximum string length, dropping all test and suite events. Early Flake Detection retries amplify the payload and keep affected tests from becoming known.

Additional Notes

Benchmark

Compared the final native IPC implementation with the previous per-trace JSON version of this PR (082d7f73b6) and a prototype that parses JSON once. Six trials per variant and pool ran on arm64 macOS with Node 24.14.1 and Vitest 5.1.1. Each run used one worker with isolation disabled, 32 new tests with 550 child spans each, and three EFD retries. Every run delivered 129 test events with distinct trace IDs, 70,400 child spans, and one suite, module, and session event to the mock intake.

Pool Previous JSON path JSON parsed once Native IPC Native peak RSS
Forks 1,229 ms 1,151 ms 1,079 ms (-12%) 296 MiB (-24%)
Threads 1,047 ms 963 ms 970 ms (-7%) 349 MiB (-20%)

The time and peak RSS columns report medians. The percentage changes use the previous JSON path as the baseline. An initial codec screen found that MessagePack reduced wire size but added CPU cost. Sending eight traces per message also raised peak memory for large traces, so the Vitest worker sends one trace per message.

Validation

  • Exporter, JSON encoder, and Test Optimization utility specs passed on Node 24.14.1 with both current and v5 tracer versions (170 each).
  • Fork/thread reporting and EFD retry/error integration checks passed on Vitest 5.1.1 and 1.6.0, plus a v5 run with Vitest 1.6.0 (12 cases total).
  • A 1,100-trace stress check exported a workload equivalent to 638 MB of JSON with one native IPC message per trace. The largest serialized message was 574 KB.
  • npm run lint and git diff --check passed. npm run lint:editorconfig requires a running Docker daemon, which was unavailable.

@dd-octo-sts

dd-octo-sts Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 9.56 MB
Deduped: 10.31 MB
No deduping: 10.31 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.5.3 | 131.25 kB | 531.9 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.15%. Comparing base (f6b4fb5) to head (31bcddb).
⚠️ Report is 16 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #11394    +/-   ##
========================================
  Coverage   99.15%   99.15%            
========================================
  Files        1136     1136            
  Lines      188132   188445   +313     
  Branches       86       86            
========================================
+ Hits       186543   186861   +318     
+ Misses       1589     1584     -5     
Flag Coverage Δ
ai-guard 63.33% <ø> (+0.07%) ⬆️
apm-capabilities 55.18% <97.46%> (+0.06%) ⬆️
apm-integrations 81.96% <ø> (+0.03%) ⬆️
appsec 59.24% <50.00%> (+0.12%) ⬆️
debugger 70.89% <ø> (+0.04%) ⬆️
instrumentation 60.17% <50.00%> (+0.13%) ⬆️
llmobs 82.51% <ø> (+0.02%) ⬆️
master-coverage 99.15% <100.00%> (?)
openfeature 68.07% <ø> (+0.11%) ⬆️
platform 68.15% <ø> (+0.07%) ⬆️
profiling 66.51% <ø> (+0.09%) ⬆️
serverless 66.67% <66.66%> (+0.04%) ⬆️
test-optimization 82.03% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 98.56% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 31bcddb | Docs | View more details | Give us feedback!

@pr-commenter

pr-commenter Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-11-24 08:53:55

Comparing candidate commit 31bcddb in PR branch juan-fernandez/fix-vitest-worker-trace-buffer with baseline commit f6b4fb5 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2480 metrics, 7 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-20

  • unstable max_rss_usage [-69.038MB; +51.232MB] or [-27.876%; +20.686%]

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20

  • unstable max_rss_usage [-31153.028KB; +32695.695KB] or [-8.628%; +9.056%]

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-26

  • unstable max_rss_usage [-33.729MB; -0.697MB] or [-10.998%; -0.227%]

scenario:encoders-0.4-immediate-flush-20

  • unstable max_rss_usage [-1.287MB; +10.326MB] or [-1.551%; +12.441%]

scenario:openfeature-initialization-configuration-20

  • unstable max_rss_usage [-4.070MB; +6.666MB] or [-5.273%; +8.636%]

scenario:openfeature-scale-full-26

  • unstable max_rss_usage [-31.105MB; +35.356MB] or [-14.385%; +16.351%]

scenario:plugin-graphql-long-with-depth-on-max-26

  • unstable max_rss_usage [-25.749MB; +40.755MB] or [-13.755%; +21.771%]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Vitest worker drops all test events for a file when its spans exceed the max string length

1 participant