Skip to content

ci: run CodeSpeed benchmarks on Nx agents#7763

Draft
beaussan wants to merge 14 commits into
mainfrom
codex/codespeed-nx-agents
Draft

ci: run CodeSpeed benchmarks on Nx agents#7763
beaussan wants to merge 14 commits into
mainfrom
codex/codespeed-nx-agents

Conversation

@beaussan

@beaussan beaussan commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Moves automatic CodeSpeed benchmark CI into the main PR workflow so it runs through Nx Agents.
  • Leaves the existing Benchmarks workflow as manual-only, preserving the old action-based path for ad hoc runs.
  • Adds explicit test:codspeed:* targets for client-nav, SSR, memory client, and memory server benchmarks, backed by a scripts/nx/run-codspeed-benchmark.mjs CLI wrapper.

Impact

  • Architecture: CodeSpeed now wraps the local Vitest benchmark process inside the Nx task that lands on an agent, avoiding a nested codspeed run -- pnpm nx ... scheduler call.
  • Performance / benchmark isolation: Assignment rules route test:codspeed:* targets to linux-medium-js agents with parallelism: 1 to limit same-agent CPU and memory pollution.
  • Auth / CI metadata: The PR test job uses job-scoped id-token: write and forwards an explicit GitHub OIDC + repository metadata allowlist. --with-env-vars="auto" was tried and rejected because it also forwards runner-private GitHub file-command paths such as GITHUB_ENV, GITHUB_OUTPUT, GITHUB_PATH, and GITHUB_EVENT_PATH, which caused the agent workflow to fail before tasks executed.
  • CodeSpeed parity: The Nx wrapper mirrors the action's command shape by passing a single shell command string to codspeed run, setting GH_MATRIX/GH_STRATEGY metadata, and synthesizing the PR event payload with the real PR head/base SHAs instead of the pull-request merge SHA.
  • V1 scope: Automatic PR CI now schedules only @benchmarks/client-nav:test:codspeed:react and @benchmarks/client-nav:test:codspeed:vue. The other CodeSpeed targets remain defined for manual/local iteration, but client-nav Solid currently needs agent build-output follow-up and SSR currently fails in CodeSpeed analysis mode on agents.
  • User-facing changes: None.

Testing

  • node --check scripts/nx/run-codspeed-benchmark.mjs
  • Parsed changed benchmark package.json files with Node.
  • Parsed changed workflow YAML files with Ruby YAML.
  • Verified the pinned CodeSpeed 4.17.0 installer SHA256.
  • git diff --check
  • Fake codspeed smoke test confirmed wrapper argv and synthetic PR event payload contain the expected command string, matrix metadata, PR head SHA, and PR base SHA.
  • Commit 48dcfcd3fb tried --with-env-vars="auto"; PR CI failed in Nx Cloud before any distributed tasks executed because the auto env set included runner-private GitHub file-command variables.
  • Commit e6ccd73de5 restored the explicit env list; GitHub PR CI passed and the CodeSpeed Nx tasks ran successfully, but the external CodeSpeed check reported no detected benchmarks.
  • Commit 88c7e404b8 aligned wrapper metadata/command shape with the action; CodeSpeed then detected real benchmarks, while broad scheduling exposed agent-only failures in Solid client-nav and SSR.
  • Latest commit f82011f2b4 narrows automatic PR scheduling to the v1 client-nav React/Vue targets and is awaiting CI.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ea6ed7b-f0a9-410e-a9b3-38b1eeb42fad

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/codespeed-nx-agents

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 88c7e40

Command Status Duration Result
nx run-many --projects=@benchmarks/client-nav -... ✅ Succeeded 8m 23s View ↗
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 3m 14s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 24s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-16 09:57:32 UTC

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: 4bfa68ef9da4
  • Measured at: 2026-07-16T09:47:01.360Z
  • Baseline source: history:a3e24c35a58d
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 87.35 KiB -26 B (-0.03%) 87.21 KiB 273.70 KiB 76.01 KiB ▁██████▄▄▄▄
react-router.full 91.06 KiB -42 B (-0.05%) 90.92 KiB 285.59 KiB 79.19 KiB ▁██████▁▁▁▁
solid-router.minimal 35.53 KiB -38 B (-0.10%) 35.40 KiB 105.90 KiB 31.94 KiB ▁██████▁▁▁▁
solid-router.full 40.58 KiB -31 B (-0.07%) 40.46 KiB 121.11 KiB 36.51 KiB ▁██████▁▁▁▁
vue-router.minimal 53.00 KiB -69 B (-0.13%) 52.87 KiB 149.94 KiB 47.63 KiB ▂██████▁▁▁▁
vue-router.full 58.94 KiB -99 B (-0.16%) 58.81 KiB 168.70 KiB 52.76 KiB ▅██████▁▁▁▁
react-start.minimal 101.99 KiB -41 B (-0.04%) 101.85 KiB 322.13 KiB 88.23 KiB ▁██████▁▁▁▁
react-start.deferred-hydration 102.72 KiB -40 B (-0.04%) 101.87 KiB 323.50 KiB 88.88 KiB ▁██████▁▁▁▁
react-start.full 105.36 KiB -87 B (-0.08%) 105.23 KiB 332.06 KiB 91.12 KiB ▄██████▁▁▁▁
react-start.rsbuild.minimal 99.68 KiB -64 B (-0.06%) 99.51 KiB 316.57 KiB 85.74 KiB ▃██████▁▁▁▁
react-start.rsbuild.minimal-iife 100.08 KiB -67 B (-0.07%) 99.91 KiB 317.51 KiB 86.11 KiB ▃██████▁▁▁▁
react-start.rsbuild.full 102.89 KiB -70 B (-0.07%) 102.72 KiB 326.63 KiB 88.52 KiB ▃██████▁▁▁▁
solid-start.minimal 49.61 KiB -104 B (-0.20%) 49.48 KiB 152.07 KiB 43.83 KiB ▅██████▁▁▁▁
solid-start.deferred-hydration 52.87 KiB -106 B (-0.20%) 49.53 KiB 160.11 KiB 46.89 KiB ▅██████▁▁▁▁
solid-start.full 55.42 KiB -95 B (-0.17%) 55.29 KiB 169.12 KiB 48.90 KiB ▆██████▁▁▁▁
vue-start.minimal 71.03 KiB -104 B (-0.14%) 70.90 KiB 207.19 KiB 62.89 KiB ▇██████▁▁▁▁
vue-start.full 75.03 KiB -101 B (-0.13%) 74.90 KiB 219.83 KiB 66.37 KiB ▅██████▁▁▁▁

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

@pkg-pr-new

pkg-pr-new Bot commented Jul 8, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@7763

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7763

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7763

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@7763

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7763

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@7763

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@7763

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7763

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@7763

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@7763

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@7763

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@7763

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@7763

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@7763

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@7763

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@7763

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@7763

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@7763

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7763

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@7763

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7763

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@7763

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7763

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7763

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@7763

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@7763

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@7763

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@7763

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7763

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@7763

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@7763

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7763

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@7763

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@7763

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7763

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@7763

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7763

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7763

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@7763

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@7763

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@7763

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@7763

commit: f82011f

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

@codspeed-hq

codspeed-hq Bot commented Jul 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
❌ 1 regressed benchmark
✅ 23 untouched benchmarks
⏩ 154 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation client-route-tree-scale navigation loop (react) 74 ms 77.3 ms -4.36%
Simulation client-loaders navigation loop (react) 55.5 ms 52.8 ms +5.1%
Simulation client-async-pipeline navigation loop (vue) 45.9 ms 44.4 ms +3.23%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing codex/codespeed-nx-agents (f82011f) with main (0b178a7)

Open in CodSpeed

Footnotes

  1. 154 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

nx-cloud[bot]

This comment was marked as outdated.

@nx-cloud nx-cloud Bot 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.

Nx Cloud is proposing a fix for your failed CI:

We identified that setting WITH_INSTRUMENTATION=1 unconditionally activates @codspeed/vitest-plugin across all 15 Vitest sub-projects in the workspace-level config, causing each project to register a global teardown handler that the CodSpeed CLI binary doesn't deduplicate — resulting in Error: teardown called twice on the second teardown call. This fix restricts WITH_INSTRUMENTATION=1 to memory mode only, where valgrind instrumentation genuinely requires it, allowing simulation-mode benchmarks to complete successfully since the CodSpeed CLI detects benchmark results from vitest stdout directly.

Note

We are verifying this fix by re-running a subset of the 4 failed tasks that were analyzed.

Suggested Fix changes
diff --git a/scripts/nx/run-codspeed-benchmark.mjs b/scripts/nx/run-codspeed-benchmark.mjs
index d0cc888a..67c739c3 100644
--- a/scripts/nx/run-codspeed-benchmark.mjs
+++ b/scripts/nx/run-codspeed-benchmark.mjs
@@ -75,23 +75,35 @@ if (process.env.CODSPEED_TOKEN) {
   codspeedArgs.push('--token', process.env.CODSPEED_TOKEN)
 }
 
+// WITH_INSTRUMENTATION=1 activates @codspeed/vitest-plugin's global setup/teardown
+// in every Vitest project. The workspace-level vitest configs use multi-project mode
+// (main + many scenario sub-projects), so each project registers a teardown handler.
+// The CodSpeed action suppresses redundant teardown calls internally, but the CLI
+// binary does not. Restrict WITH_INSTRUMENTATION to memory mode (valgrind) only;
+// simulation mode detects benchmarks from vitest stdout without the plugin.
+const withInstrumentation = benchmarkConfig.mode === 'memory'
+
 codspeedArgs.push(
   '--',
-  `NODE_ENV=production WITH_INSTRUMENTATION=1 vitest bench --config ./${vitestConfig}`,
+  `NODE_ENV=production${withInstrumentation ? ' WITH_INSTRUMENTATION=1' : ''} vitest bench --config ./${vitestConfig}`,
 )
 
 await execFile(codspeed, codspeedArgs, {
   cwd: join(rootDir, benchmarkConfig.cwd),
   env: {
     ...process.env,
-    GH_MATRIX: process.env.GH_MATRIX ?? JSON.stringify({
-      benchmark,
-      framework,
-    }),
-    GH_STRATEGY: process.env.GH_STRATEGY ?? JSON.stringify({
-      'fail-fast': false,
-    }),
-    WITH_INSTRUMENTATION: '1',
+    GH_MATRIX:
+      process.env.GH_MATRIX ??
+      JSON.stringify({
+        benchmark,
+        framework,
+      }),
+    GH_STRATEGY:
+      process.env.GH_STRATEGY ??
+      JSON.stringify({
+        'fail-fast': false,
+      }),
+    ...(withInstrumentation ? { WITH_INSTRUMENTATION: '1' } : {}),
   },
 })
 
@@ -103,7 +115,10 @@ async function ensureGithubEventPath() {
   const eventDir = await mkdtemp(join(tmpdir(), 'codspeed-github-event-'))
   const eventPath = join(eventDir, 'event.json')
   const repository = process.env.GITHUB_REPOSITORY ?? ''
-  const repositoryId = Number.parseInt(process.env.GITHUB_REPOSITORY_ID ?? '0', 10)
+  const repositoryId = Number.parseInt(
+    process.env.GITHUB_REPOSITORY_ID ?? '0',
+    10,
+  )
   const pullRequestNumber = getPullRequestNumber()
   const event = {
     repository: {

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally PMPO-6Kdt

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

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.

1 participant