Skip to content

fix(vitest): route thread workers through main process#9169

Merged
juan-fernandez merged 2 commits into
masterfrom
juan-fernandez/vitest-worker-exporter-threads
Jul 1, 2026
Merged

fix(vitest): route thread workers through main process#9169
juan-fernandez merged 2 commits into
masterfrom
juan-fernandez/vitest-worker-exporter-threads

Conversation

@juan-fernandez

@juan-fernandez juan-fernandez commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Routes Vitest thread-pool workers through the Test Optimization test-worker exporter so they report back to the Vitest main process instead of reporting directly to the intake or Datadog Agent.

This updates the legacy Tinypool instrumentation to mark Vitest worker environments before eager workers are spawned, adds a Vitest worker MessagePort path for legacy thread workers, and tightens Vitest integration coverage so both forks and threads must be reported as framework worker events.

Motivation

Vitest forks workers already used ci-visibility/exporters/test-worker, and Vitest 4 thread workers behaved correctly. Older Vitest thread workers did not get a worker-identifying environment marker, so dd-trace/ci/init selected the normal exporter and those workers reported directly.

The root cause is that legacy Tinypool thread workers do not expose TINYPOOL_WORKER_ID in process.env, and Vitest 1.x/2.x do not export the Vitest class from the CLI chunk where our runFiles wrapper attaches. Marking the Tinypool worker options before construction gives all supported Vitest worker pools the same reporting behavior.

@dd-octo-sts

dd-octo-sts Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 6.43 MB
Deduped: 7.5 MB
No deduping: 7.5 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.2.0 | 104.26 kB | 843.44 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

@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Jul 1, 2026

Copy link
Copy Markdown

Tests

Fix all issues with BitsAI

⚠️ Warnings

🧪 1 Test failed in 1 job

Test Optimization | integration-playwright   GitHub Actions

All test failures are known flaky — job may pass on retry.

❄️ Known flaky: playwright@latest final status tag sets final_status tag only on last ATR retry when EFD is enabled but not active and ATR is active from integration-tests/playwright/playwright-final-status.spec.js   View in Datadog
Expected 1 > 1

Not introduced in this PR.

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 73.08%
Overall Coverage: 88.02% (-0.03%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 00b50d9 | Docs | Datadog PR Page | Give us feedback!

@juan-fernandez
juan-fernandez marked this pull request as ready for review July 1, 2026 09:43
@juan-fernandez
juan-fernandez requested a review from a team as a code owner July 1, 2026 09:43
@juan-fernandez
juan-fernandez enabled auto-merge (squash) July 1, 2026 09:44
@pr-commenter

pr-commenter Bot commented Jul 1, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-07-01 10:27:33

Comparing candidate commit 00b50d9 in PR branch juan-fernandez/vitest-worker-exporter-threads with baseline commit 038b5ba in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2249 metrics, 37 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-24

  • unstable execution_time [-179.761ms; +188.939ms] or [-6.832%; +7.181%]

scenario:appsec-appsec-enabled-26

  • unstable execution_time [-204.373ms; +209.972ms] or [-8.110%; +8.332%]

scenario:appsec-appsec-enabled-with-attacks-26

  • unstable execution_time [-155.861ms; +159.007ms] or [-5.410%; +5.519%]

scenario:appsec-control-20

  • unstable execution_time [-163.310ms; +148.298ms] or [-9.351%; +8.491%]

scenario:appsec-control-24

  • unstable execution_time [-102373.255µs; +103081.521µs] or [-8.444%; +8.502%]

scenario:appsec-control-26

  • unstable execution_time [-112070.687µs; +113549.687µs] or [-9.290%; +9.413%]

scenario:debugger-line-probe-with-snapshot-default-24

  • unstable cpu_user_time [-2623.792ms; +3739.291ms] or [-29.115%; +41.493%]
  • unstable execution_time [-2674.314ms; +3823.530ms] or [-27.508%; +39.328%]
  • unstable instructions [-22.1G instructions; +31.9G instructions] or [-29.890%; +43.229%]
  • unstable max_rss_usage [-9.272MB; +13.490MB] or [-5.711%; +8.310%]
  • unstable throughput [-1119.183op/s; +793.297op/s] or [-31.878%; +22.596%]

scenario:debugger-line-probe-with-snapshot-default-26

  • unstable cpu_user_time [-2.131s; +4.607s] or [-21.315%; +46.075%]
  • unstable execution_time [-2.185s; +4.672s] or [-20.427%; +43.674%]
  • unstable instructions [-18.8G instructions; +41.1G instructions] or [-22.568%; +49.275%]
  • unstable max_rss_usage [-7.778MB; +14.445MB] or [-4.833%; +8.976%]
  • unstable throughput [-1012.519op/s; +473.446op/s] or [-32.376%; +15.139%]

scenario:debugger-line-probe-with-snapshot-minimal-26

  • unstable cpu_user_time [-2957.753ms; +2980.052ms] or [-29.783%; +30.007%]
  • unstable execution_time [-3012.373ms; +3023.765ms] or [-28.390%; +28.498%]
  • unstable instructions [-26206.1M instructions; +26077.1M instructions] or [-31.552%; +31.397%]
  • unstable max_rss_usage [-8239.860KB; +8295.860KB] or [-5.103%; +5.138%]
  • unstable throughput [-662.333op/s; +665.751op/s] or [-20.969%; +21.077%]

scenario:debugger-line-probe-without-snapshot-24

  • unstable cpu_user_time [-1712.989ms; +558.017ms] or [-21.583%; +7.031%]
  • unstable execution_time [-1731.842ms; +561.605ms] or [-20.107%; +6.520%]
  • unstable instructions [-14.6G instructions; +4.7G instructions] or [-22.615%; +7.291%]
  • unstable throughput [-164.506op/s; +505.821op/s] or [-4.287%; +13.182%]

scenario:debugger-line-probe-without-snapshot-26

  • unstable cpu_user_time [-2.169s; +4.455s] or [-21.519%; +44.202%]
  • unstable execution_time [-2.176s; +4.485s] or [-20.192%; +41.621%]
  • unstable instructions [-19.4G instructions; +40.2G instructions] or [-23.101%; +47.759%]
  • unstable max_rss_usage [-6.625MB; +14.492MB] or [-4.125%; +9.023%]
  • unstable throughput [-965.016op/s; +480.485op/s] or [-31.200%; +15.535%]

scenario:dogstatsd-with-tags-20

  • unstable cpu_user_time [-334.191ms; +403.610ms] or [-6.785%; +8.195%]
  • unstable execution_time [-334.401ms; +401.506ms] or [-6.694%; +8.037%]
  • unstable throughput [-137963.734op/s; +116033.521op/s] or [-8.200%; +6.897%]

scenario:sampling-rate-limited-20

  • unstable cpu_user_time [-69.045ms; +97.077ms] or [-4.869%; +6.845%]
  • unstable execution_time [-68.912ms; +97.362ms] or [-4.850%; +6.852%]

scenario:spans-finish-later-26

  • unstable max_rss_usage [-5.759MB; +9.245MB] or [-3.906%; +6.272%]

scenario:test-optimization-large-suite-20

  • unstable max_rss_usage [-3.370MB; +7.128MB] or [-4.241%; +8.970%]

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1d375adc8

ℹ️ 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".

Comment thread packages/datadog-instrumentations/src/vitest.js Outdated
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.46154% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.72%. Comparing base (038b5ba) to head (00b50d9).
⚠️ Report is 12 commits behind head on master.

Files with missing lines Patch % Lines
packages/datadog-instrumentations/src/vitest.js 88.23% 8 Missing ⚠️
.../src/ci-visibility/exporters/test-worker/writer.js 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9169      +/-   ##
==========================================
- Coverage   93.73%   93.72%   -0.02%     
==========================================
  Files         892      892              
  Lines       51236    51311      +75     
  Branches    11924    11945      +21     
==========================================
+ Hits        48026    48089      +63     
- Misses       3210     3222      +12     
Flag Coverage Δ
aiguard 34.87% <ø> (-0.08%) ⬇️
aiguard-integration 41.79% <ø> (+0.01%) ⬆️
apm-bucket-0 34.84% <ø> (-0.08%) ⬇️
apm-bucket-1 40.33% <ø> (-0.07%) ⬇️
apm-bucket-2 37.34% <ø> (-0.07%) ⬇️
apm-capabilities-tracing 48.68% <90.00%> (+<0.01%) ⬆️
apm-integrations-aerospike 33.12% <ø> (-0.08%) ⬇️
apm-integrations-confluentinc-kafka-javascript 40.02% <ø> (-0.08%) ⬇️
apm-integrations-couchbase 33.24% <ø> (-0.08%) ⬇️
apm-integrations-http 41.95% <ø> (-0.07%) ⬇️
apm-integrations-kafkajs 40.26% <ø> (-0.12%) ⬇️
apm-integrations-next 29.50% <ø> (-0.03%) ⬇️
apm-integrations-prisma 35.03% <ø> (-0.07%) ⬇️
apm-integrations-tedious 33.89% <ø> (-0.07%) ⬇️
appsec 57.70% <ø> (-0.05%) ⬇️
appsec-express_fastify_graphql 53.67% <ø> (-0.06%) ⬇️
appsec-integration 36.18% <5.88%> (-0.04%) ⬇️
appsec-kafka_ldapjs_lodash 43.58% <ø> (-0.07%) ⬇️
appsec-mongodb-core_mongoose_mysql 48.74% <ø> (-0.06%) ⬇️
appsec-next 28.00% <ø> (-0.07%) ⬇️
appsec-node-serialize_passport_postgres 47.91% <ø> (-0.06%) ⬇️
appsec-sourcing_stripe_template 45.47% <ø> (-0.06%) ⬇️
debugger 44.37% <ø> (-0.04%) ⬇️
instrumentations-bucket-0 28.15% <ø> (-0.08%) ⬇️
instrumentations-bucket-1 37.40% <ø> (-0.07%) ⬇️
instrumentations-bucket-10 40.35% <ø> (-0.07%) ⬇️
instrumentations-bucket-11 27.95% <ø> (-0.08%) ⬇️
instrumentations-bucket-12 28.67% <ø> (-0.07%) ⬇️
instrumentations-bucket-13 27.78% <ø> (-0.08%) ⬇️
instrumentations-bucket-2 30.23% <ø> (-0.07%) ⬇️
instrumentations-bucket-3 35.90% <ø> (-0.07%) ⬇️
instrumentations-bucket-4 28.56% <ø> (+0.42%) ⬆️
instrumentations-bucket-5 36.28% <ø> (-0.07%) ⬇️
instrumentations-bucket-6 38.25% <ø> (-0.07%) ⬇️
instrumentations-bucket-7 36.01% <ø> (-0.07%) ⬇️
instrumentations-bucket-8 36.95% <ø> (-0.07%) ⬇️
instrumentations-bucket-9 39.45% <ø> (-0.07%) ⬇️
instrumentations-instrumentation-couchbase 46.48% <ø> (-0.07%) ⬇️
instrumentations-integration-esbuild 24.88% <5.88%> (+0.02%) ⬆️
llmobs-ai_anthropic_bedrock 39.53% <ø> (-0.06%) ⬇️
llmobs-google-genai_langchain_vertex-ai 36.97% <ø> (-0.06%) ⬇️
llmobs-openai 39.58% <ø> (-0.07%) ⬇️
llmobs-sdk 43.59% <ø> (-0.08%) ⬇️
master-coverage 93.72% <88.46%> (?)
openfeature 37.76% <ø> (+0.01%) ⬆️
openfeature-unit 50.39% <ø> (ø)
platform-core_esbuild_instrumentations-misc 23.33% <5.88%> (-0.03%) ⬇️
platform-integration 47.42% <ø> (+0.01%) ⬆️
platform-shimmer_unit-guardrails_webpack 18.88% <5.88%> (-0.02%) ⬇️
plugins-bucket-0 36.37% <ø> (-0.02%) ⬇️
plugins-bucket-1 39.60% <ø> (+<0.01%) ⬆️
plugins-bucket-11 38.46% <ø> (-0.07%) ⬇️
plugins-bucket-17 39.15% <ø> (-0.07%) ⬇️
plugins-bucket-18 42.01% <ø> (-0.07%) ⬇️
plugins-bucket-19 39.56% <ø> (-0.07%) ⬇️
plugins-bucket-20 43.25% <ø> (-0.07%) ⬇️
plugins-bucket-4 37.71% <ø> (-0.07%) ⬇️
plugins-bullmq_cassandra_cookie 39.76% <ø> (-0.07%) ⬇️
plugins-cookie-parser_crypto_dd-trace-api 33.22% <ø> (-0.08%) ⬇️
plugins-fetch_fs_generic-pool 36.05% <ø> (-0.07%) ⬇️
plugins-google-cloud-pubsub_grpc_handlebars 43.11% <ø> (-0.06%) ⬇️
plugins-hapi_hono_ioredis 37.78% <ø> (-0.07%) ⬇️
plugins-jest_knex_langgraph 32.60% <ø> (-0.07%) ⬇️
plugins-ldapjs_light-my-request_limitd-client 27.91% <ø> (-0.02%) ⬇️
plugins-lodash_mariadb_memcached 35.11% <ø> (-0.14%) ⬇️
plugins-mongodb_mongodb-core_mongoose 36.31% <ø> (-0.09%) ⬇️
plugins-multer_mysql_mysql2 35.14% <ø> (-0.08%) ⬇️
plugins-nats_node-serialize_opensearch 37.14% <ø> (-0.02%) ⬇️
plugins-passport-http_pino_postgres 35.53% <ø> (-0.08%) ⬇️
plugins-process_pug_redis 34.26% <ø> (-0.08%) ⬇️
plugins-undici_url_valkey 35.88% <ø> (-0.07%) ⬇️
plugins-vm_winston_ws 37.55% <ø> (-0.07%) ⬇️
profiling 43.62% <ø> (-0.06%) ⬇️
serverless-aws-sdk-aws-sdk 33.29% <ø> (-0.06%) ⬇️
serverless-aws-sdk-bedrockruntime 32.16% <ø> (-0.07%) ⬇️
serverless-aws-sdk-client 37.16% <ø> (-0.05%) ⬇️
serverless-aws-sdk-dynamodb 34.09% <ø> (-0.12%) ⬇️
serverless-aws-sdk-eventbridge 27.25% <ø> (-0.07%) ⬇️
serverless-aws-sdk-kinesis 37.40% <ø> (-0.07%) ⬇️
serverless-aws-sdk-lambda 34.59% <ø> (-0.07%) ⬇️
serverless-aws-sdk-s3 32.59% <ø> (-0.07%) ⬇️
serverless-aws-sdk-serverless-peer-service 39.56% <ø> (+0.01%) ⬆️
serverless-aws-sdk-sns 38.25% <ø> (-0.07%) ⬇️
serverless-aws-sdk-sqs 38.00% <ø> (-0.07%) ⬇️
serverless-aws-sdk-stepfunctions 33.18% <ø> (-0.07%) ⬇️
serverless-aws-sdk-util 47.95% <ø> (ø)
serverless-bucket-0 39.46% <ø> (+<0.01%) ⬆️
serverless-lambda 34.33% <ø> (-0.09%) ⬇️
test-optimization-cucumber 52.30% <ø> (+0.11%) ⬆️
test-optimization-cypress 49.41% <ø> (-0.04%) ⬇️
test-optimization-jest 55.37% <50.00%> (+0.10%) ⬆️
test-optimization-mocha 53.38% <50.00%> (+0.07%) ⬆️
test-optimization-playwright-playwright-atr 43.33% <50.00%> (+0.09%) ⬆️
test-optimization-playwright-playwright-efd 43.61% <50.00%> (+0.09%) ⬆️
test-optimization-playwright-playwright-final-status 43.96% <50.00%> (+0.32%) ⬆️
test-optimization-playwright-playwright-impacted-tests 43.16% <50.00%> (+<0.01%) ⬆️
test-optimization-playwright-playwright-reporting 43.26% <50.00%> (+0.09%) ⬆️
test-optimization-playwright-playwright-test-management 44.82% <50.00%> (+0.19%) ⬆️
test-optimization-playwright-playwright-test-span 44.51% <50.00%> (+0.08%) ⬆️
test-optimization-selenium 45.26% <0.00%> (+0.04%) ⬆️
test-optimization-testopt 47.99% <23.07%> (+0.04%) ⬆️
test-optimization-vitest 50.69% <83.33%> (+0.14%) ⬆️

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-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: PASS

More details

The getWrappedOn refactor is the most load-bearing correctness decision in this PR: the new global MessagePort.prototype.on wrapping (wrapMessagePortOn) would have swallowed ALL of Vitest's own array messages on any MessagePort if the old "always return for arrays" logic had been kept — the selective handleWorkerReport-based early return is what makes the global wrap safe.

Was this helpful? React 👍 or 👎

📊 Validated against 41 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit d1d375a · What is Autotest? · Any feedback? Reach out in #autotest

anmarchenko
anmarchenko previously approved these changes Jul 1, 2026
@juan-fernandez

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 00b50d9685

ℹ️ 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".

@juan-fernandez
juan-fernandez enabled auto-merge (squash) July 1, 2026 10:25
@juan-fernandez
juan-fernandez merged commit dd01d58 into master Jul 1, 2026
804 of 805 checks passed
@juan-fernandez
juan-fernandez deleted the juan-fernandez/vitest-worker-exporter-threads branch July 1, 2026 10:30
This was referenced Jul 2, 2026
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.

2 participants