Skip to content

ci(codspeed): move the simulation bench gate to a dedicated self-hosted runner - #75

Open
sedghi wants to merge 10 commits into
mainfrom
ci/codspeed-self-hosted
Open

ci(codspeed): move the simulation bench gate to a dedicated self-hosted runner#75
sedghi wants to merge 10 commits into
mainfrom
ci/codspeed-self-hosted

Conversation

@sedghi

@sedghi sedghi commented Jul 9, 2026

Copy link
Copy Markdown
Member

Why

CodSpeed simulation mode derives its modeled CPU cache from the physical runner CPU. GitHub's shared runners randomly assign Intel Xeon 8370C vs AMD EPYC 7763, so identical source shifts instruction counts run-to-run and CodSpeed flags "Different runtime environments detected" — the noise behind the phantom regressions we've been triaging. Pinning the OS wasn't enough; the CPU model is the remaining variable.

Change

  • codspeed-bench (the blocking simulation gate) now runs on runs-on: [self-hosted, codspeed-bench] instead of ubuntu-24.04. One fixed box → every baseline and PR run on identical hardware → Simulation is stable.
  • Adds docs/ci/self-hosted-runner.md: box requirements (valgrind, node 22, isolated/pinned CPU), how to register the runner, and the cutover order.
  • Only the simulation gate moves; build/test/dist-size/browser-smoke stay on GitHub-hosted runners. (codspeed-walltime already targets codspeed-macro behind a repo variable — unchanged.)

⚠️ Do not merge until the runner is online

Cutover order matters:

  1. Register + start the self-hosted runner with the codspeed-bench label FIRST (see the doc). If this merges before a runner with that label exists, the codspeed-bench job queues indefinitely.
  2. Merge this.
  3. The main push re-seeds the CodSpeed baseline on the fixed hardware. The first PR comparisons after cutover show a one-time environment shift (old shared-runner baseline vs new fixed head) — expected, self-resolves once the baseline is re-seeded.

Rollback: revert runs-on to ubuntu-24.04.

Summary by CodeRabbit

  • New Features

    • Added automated CodSpeed benchmarking for pull requests, pushes to main, and manual runs.
    • Benchmarks target affected packages when possible and restore matching build artifacts.
    • Added safeguards to skip or report unavailable benchmark builds.
  • Chores

    • Improved reliability with pinned tool versions and coordinated execution.
    • Moved simulation benchmarks to a dedicated self-hosted runner.
  • Documentation

    • Added setup, operating, coordination, and rollback guidance for the self-hosted benchmark runner.

…d runner

Move the codspeed-bench job off GitHub's shared pool (ubuntu-24.04) onto a
fixed self-hosted runner labeled 'codspeed-bench'. Simulation instruction
counts derive from the runner CPU's cache model, and the shared pool
randomly assigns Intel vs AMD hardware, producing spurious cross-run
'Different runtime environments' deltas. A dedicated fixed box keeps every
run on identical hardware so the gate is stable. Adds docs/ci/self-hosted-runner.md
with the box requirements and cutover order.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fc3ac9a5-90ae-4472-9f87-760250e85ffa

📥 Commits

Reviewing files that changed from the base of the PR and between 46537cb and cb6757f.

📒 Files selected for processing (2)
  • .github/actionlint.yaml
  • .github/workflows/bench.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/bench.yml

📝 Walkthrough

Walkthrough

The PR adds a gated CodSpeed simulation workflow for the shared nashua runner. It pins benchmark tooling, coordinates jobs with a cross-repository filesystem lock, scopes workflow permissions, and documents runner setup, operation, cutover, and rollback.

Changes

Self-hosted CodSpeed benchmark workflow

Layer / File(s) Summary
Benchmark gating and execution
.github/workflows/bench.yml, .github/workflows/pr-checks.yml, .github/actionlint.yaml, .github/CODEOWNERS
Adds change classification, build-artifact polling, package selection, pinned tooling, artifact restoration, scoped CodSpeed simulation benchmarking, actionlint labels, and CI ownership rules.
Cross-repository benchmark locking
tools/ci/with-nashua-lock.sh, docs/ci/self-hosted-runner.md
Adds a strict-mode lock wrapper with timeout handling, holder metadata, and automatic lock release. Documents shared lock operation and permissions.
Runner environment and lifecycle
docs/ci/self-hosted-runner.md
Documents supported packages, CodSpeed tooling, hardware stability, runner registration, service setup, cutover, and rollback procedures.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PullRequest
  participant BenchWorkflow
  participant PRChecks
  participant NashuaRunner
  participant LockWrapper
  participant CodSpeed
  PullRequest->>BenchWorkflow: Trigger benchmark workflow
  BenchWorkflow->>BenchWorkflow: Classify changes and select packages
  BenchWorkflow->>PRChecks: Poll matching build artifacts
  PRChecks-->>BenchWorkflow: Report build readiness
  BenchWorkflow->>NashuaRunner: Start scoped benchmark job
  NashuaRunner->>LockWrapper: Acquire shared filesystem lock
  LockWrapper->>CodSpeed: Run pinned simulation benchmark
  CodSpeed-->>LockWrapper: Return benchmark status
  LockWrapper->>LockWrapper: Release lock
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: moving the CodSpeed simulation benchmark gate to a dedicated self-hosted runner.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/codspeed-self-hosted

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.

@codspeed-hq

codspeed-hq Bot commented Jul 9, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 40.12%

⚠️ 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

❌ 3 regressed benchmarks
✅ 50 untouched benchmarks
⏩ 66 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation decode CT-512x512-near-lossless.JLS (.81 near-lossless) — cold 19.8 ms 37.9 ms -47.78%
Simulation decode CT-512x512-near-lossless.JLS (.81 near-lossless) — warm 19.8 ms 37.9 ms -47.76%
Simulation HTJ2K Lossless (.201) 141.4 ms 179.7 ms -21.3%

Tip

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


Comparing ci/codspeed-self-hosted (cb6757f) with main (a88a461)2

Open in CodSpeed

Footnotes

  1. 66 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.

  2. No successful run was found on main (9c086c9) during the generation of this report, so a88a461 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Comment thread .github/workflows/pr-checks.yml Outdated
- flock: add tools/ci/with-nashua-lock.sh (same lock path as cornerstone3D and
  OHIF), wrapping the bench command inside the CodSpeed action's `run:`; plus
  timeout-minutes: 180 to bound the added lock wait.
- node: pin both codspeed jobs to 22.23.1 — a range reuses whatever 22.x is in
  the box's persistent tool cache, and V8 patch releases move the numbers.
- yarn: provision per-job via Corepack; nashua has none and setup-node installs
  node + npm only.
- docs: document the shared-box mutex, and correct the valgrind requirement —
  CodSpeed installs its own patched build, pre-installed by hand and held here.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/pr-checks.yml:
- Line 484: Update the detect-changes TOOLCHAIN_PATHS configuration to include
tools/ci/with-nashua-lock.sh (or the tools/ci/ directory), so changes to the
lock wrapper set any=true and trigger the benchmark command using it.

In `@docs/ci/self-hosted-runner.md`:
- Around line 24-27: Update the supported OS list in the self-hosted runner
documentation to remove Debian 11, leaving Ubuntu 22.04/24.04 and Debian 12 as
the documented releases. Keep the surrounding architecture and CodSpeed
compatibility guidance unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6589db6b-8e7e-46cb-8c5e-ee4d0b38d965

📥 Commits

Reviewing files that changed from the base of the PR and between 9c086c9 and b4e5387.

📒 Files selected for processing (3)
  • .github/workflows/pr-checks.yml
  • docs/ci/self-hosted-runner.md
  • tools/ci/with-nashua-lock.sh

Comment thread .github/workflows/pr-checks.yml Outdated
Comment thread docs/ci/self-hosted-runner.md Outdated
@wayfarer3130

Copy link
Copy Markdown
Contributor

@sedghi - with this PR, we have a self hosted runner which becomes exposed:
.github/workflows/pr-checks.yml:354 — HIGH: public repo (gh repo view confirms PUBLIC) with a pull_request trigger now runs PR-authored code on a non-ephemeral self-hosted runner that the doc requires to share an OS user with the cornerstone3D and OHIF runners — so a fork PR can read those runners' .credentials/.credentials_rsaparams and poison the persistent tool/node_modules caches. Removing passwordless sudo doesn't mitigate any of it.
How do we only allow running it after approval?

jbocce added 3 commits August 6, 2026 15:45
Tags can be moved upstream; the SHA freezes both the CI code and the instrumentation environment the baseline was measured under.
Adds CODEOWNERS routing /.github/ and /tools/ci/ to named owners; binds via the require_code_owner_reviews branch protection flag on main.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
docs/ci/self-hosted-runner.md (1)

3-3: 🔒 Security & Privacy | 🔵 Trivial | 💤 Low value

Document the existing PR trust boundary for this runner.

.github/workflows/bench.yml already limits fork PR code paths to read-only pull_request actions, defers CI-defining changes unless the author has write access, and downloads PR-checks artifacts from the base workflow. Add that rule to this runner doc before registration so the shared runner use case is transparent.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/ci/self-hosted-runner.md` at line 3, Update the self-hosted runner
documentation before the registration instructions to describe the existing PR
trust boundary enforced by the codspeed-bench workflow: fork PRs use read-only
pull_request actions, CI-defining changes are deferred unless the author has
write access, and PR-checks artifacts come from the base workflow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/bench.yml:
- Line 217: Add a .github/actionlint.yaml configuration declaring codspeed-bench
and nashua under self-hosted-runner.labels, so actionlint recognizes the custom
labels used by the runs-on declaration in the workflow.
- Around line 217-229: Harden the benchmark job gated by
needs.gate.outputs.proceed and needs.gate.outputs.ready so fork pull requests
cannot execute on the shared self-hosted runner; require the pull request head
repository to match github.repository, or use a protected environment with
required reviewers. Update actions/checkout@v4 to set persist-credentials:
false, and preserve the existing same-repository and non-pull-request execution
paths.
- Around line 295-358: Validate each package name in the scope-computation step
before appending it to flags, accepting only plain scoped package names and
rejecting invalid values such as newlines or shell metacharacters. Pass the
resulting scope flags to the CodSpeed action through an environment variable
rather than interpolating steps.scope.outputs.flags into the run command. Apply
the equivalent validation and environment-based flag passing to the matching
walltime benchmark flow.

---

Nitpick comments:
In `@docs/ci/self-hosted-runner.md`:
- Line 3: Update the self-hosted runner documentation before the registration
instructions to describe the existing PR trust boundary enforced by the
codspeed-bench workflow: fork PRs use read-only pull_request actions,
CI-defining changes are deferred unless the author has write access, and
PR-checks artifacts come from the base workflow.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 09965bbf-1d2b-45be-9e7a-f2fe4fd188fd

📥 Commits

Reviewing files that changed from the base of the PR and between b4e5387 and 443733d.

📒 Files selected for processing (4)
  • .github/CODEOWNERS
  • .github/workflows/bench.yml
  • .github/workflows/pr-checks.yml
  • docs/ci/self-hosted-runner.md

Comment thread .github/workflows/bench.yml
Comment thread .github/workflows/bench.yml
Comment thread .github/workflows/bench.yml Outdated

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/workflows/pr-checks.yml (1)

371-375: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Pin the build Node.js version to the benchmark version.

codspeed-walltime and codspeed-bench benchmark the dist-* artifacts produced by the build job. If actions/setup-node@v4 resolves node-version: '22' to a different Node 22 patch than 22.23.1, CodSpeed can compare artifacts generated with different tooling. Set the build job to 22.23.1 too.

Proposed fix
-          node-version: '22'
+          node-version: '22.23.1'
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/pr-checks.yml around lines 371 - 375, Update the build
job’s actions/setup-node configuration to use Node.js version 22.23.1, matching
the existing codspeed-bench pin and the benchmark jobs. Keep the artifact build
flow unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In @.github/workflows/pr-checks.yml:
- Around line 371-375: Update the build job’s actions/setup-node configuration
to use Node.js version 22.23.1, matching the existing codspeed-bench pin and the
benchmark jobs. Keep the artifact build flow unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 96061fe8-6d2b-4fac-ab71-e4df79596e1b

📥 Commits

Reviewing files that changed from the base of the PR and between 443733d and 46537cb.

📒 Files selected for processing (2)
  • .github/workflows/bench.yml
  • .github/workflows/pr-checks.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/bench.yml

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.

3 participants