Skip to content

fix(scripts): server benchmark no longer fails when the server is slow to record its runtime state - #41574

Merged
juliusmarminge merged 1 commit into
mainfrom
perf/bench-project-add-race
Nov 23, 2026
Merged

juliusmarminge merged 1 commit into
mainfrom
perf/bench-project-add-race

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

node scripts/server-metrics.ts ab --rounds 3 <v0.1.11> <main> failed today on Linux, macOS and Windows, each time on a different round and scenario, with:

server-metrics: the quiet scenario failed: .../node src/bin.ts project add exited with 78: ...
    at ...ServerOwnership.ts:206:11
    at RunningServer.changeState (.../apps/server/src/cli/project.ts:307:41)

When that happens ab writes no a.json/b.json, and the whole run (up to an hour) is lost.

Cause. The harness waits only for the server's HTTP / to answer, then runs project add --base-dir. The server answers HTTP before it records userdata/server-runtime.json:

  • serverRuntimeStartup.ts:645 waits for the HTTP listener, then runs prepareTrial and publishes the welcome event, and only reaches activate at :670.
  • layerRuntimeState waits for that activation and then publishes the runtime state (server.ts:955-978).
  • Until then, RunningServer.changeState finds no live runtime state and makes the change locally. acquireServerOwnership then hits the lock the server took at startup (server.ts:923), and the command fails with ServerAlreadyRunningError (exit 78).

This ordering is the same on main (server.ts, serverRuntimeStartup.ts and runningServer.ts publish in the same order there). The failures landed on v0.1.11 only by timing, so B could have failed the same way.

Fix. After the first HTTP answer, the harness also waits until userdata/server-runtime.json exists, which is the point where the CLI starts talking to the running server. It uses the same wait budget as the HTTP wait, and if the file never appears it fails with the server's stderr. readyMs still measures the first HTTP answer, so earlier results stay comparable. The file has been at that path since before v0.0.40, so old releases are covered too. I did not retry on exit 78: that would also hide a real second server holding the lock.

No test: the change is a wait inside startServer, and the script's tests cover only the pure report helpers. I did not run a full benchmark because the benchmark machines were busy. vp run check:changed passes.

Investigated and fixed by Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

…w to record its runtime state

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

After the server responds to HTTP, startServer waits for userdata/server-runtime.json. If the file does not appear within the retry limit, startServer raises a MetricsError that includes captured server stderr.

Changes: Server metrics startup

Layer / File(s) Summary
Wait for runtime state
scripts/server-metrics.ts
After HTTP readiness, startServer checks for userdata/server-runtime.json every 100 ms, up to 3,000 times. If the file does not appear, it raises a MetricsError containing captured stderr.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related PRs

  • pingdotgg/t3code#41159: Adds the benchmark harness in scripts/server-metrics.ts, which this change modifies.

Suggested reviewers: macroscopeapp

Merge Risk: Minimal · up to 77829

The benchmark script now waits for the server's runtime-state file before continuing, so a delayed write no longer aborts an entire run. If the file never appears, it fails with the server's stderr. This only affects the developer benchmarking script, and I found no concrete merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change and its purpose: the server benchmark no longer fails when the server is slow to record its runtime state. The raw summary confirms the change adds a wait for userdata/serve…
Description check Passed The description follows the repository template closely. It has a clear Problem section with the exact command, the observed error, and the reproduction environment (Linux, macOS, Windows). Its Change…
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.
Full details: Title check

Explanation

The title names the change and its purpose: the server benchmark no longer fails when the server is slow to record its runtime state. The raw summary confirms the change adds a wait for userdata/server-runtime.json inside startServer, so the title matches the main change. It uses the conventional commit form, and it is specific enough for a teammate scanning history. The title is 98 characters, which is slightly long but acceptable.

Full details: Description check

Explanation

The description follows the repository template closely. It has a clear Problem section with the exact command, the observed error, and the reproduction environment (Linux, macOS, Windows). Its Change section explains the root cause and the fix, and it explains why exit 78 is not retried. Its Verification section gives the checks run (vp run check:changed, no new test) and states what was not checked (full benchmark, because machines were busy). The Scope section is weaker: it does not link a tracked issue for the bug, and it does not explain why no issue is needed. The template asks for that link or justification. The author also cites a source, the commit path, and an agent attribution, which matches the template's agent note. Overall the description is mostly complete, with one gap in Scope.

Resolution

Optional improvement: add a link to the issue that tracks this bug, or state why an issue is not needed for this small fix of an obvious bug.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fa2ee19 and 77829b9.

Files selected for processing: 1

  • scripts/server-metrics.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@juliusmarminge
juliusmarminge merged commit f158ef1 into main Nov 23, 2026
36 checks passed
@juliusmarminge
juliusmarminge deleted the perf/bench-project-add-race branch November 23, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant