Skip to content

Keep agent-runtime test bridges at the test worker's CPU priority - #8198

Merged
ymichael merged 1 commit into
mainfrom
bb/fix-agent-runtime-timing-flakes
Nov 25, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/fix-agent-runtime-timing-flakes

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Since #8068 graduated agentCpuPriority (merged 2026-11-24 04:53 UTC), deprioritizeAgentWorkload renices every provider process to nice 10 unconditionally. Before that it was a no-op unless the daemon turned it on, so @bb/agent-runtime test bridges ran at the Vitest worker's priority. Now each bridge a test spawns runs below the nice-0 Vitest workers. On a contended 4-vCPU Linux runner (turbo runs four suites at once), the bridges get a small share of CPU, so bridge startup and exit take seconds and tests with wall-clock bounds fail. macOS ignores nice across processes, so this never reproduces locally.

In the failing run for #8158 (run 45680230926, attempt 1), every bridge-spawning test near the start of both files took 8–12 s; they normally take 0.2–2 s:

  • uses the construction deadline for thread/'resume' (requestTimeoutMs=undefined) hit the 15 s test timeout. Its siblings took 10.3 s and 8.3 s.
  • fires onProcessExit when provider crashes spent about 10 s in ensureProvider. It then gave the exit callback only the waitForRuntimeState default of 1 s. That window has to cover the bridge's process.exit plus the close event, which the runtime itself allows up to PROVIDER_PROCESS_CLOSE_GRACE_MS (1 s) to report.

Main CI has hit the same problem. Of the 60 most recent failed main CI runs (Nov 16–25), the 49 before Nov 24 had no @bb/agent-runtime failures. On Nov 24, 7 of 10 failed main runs were runtime.process-lifecycle.test.ts tests timing out at 15 s on Linux: ranks provider processes ahead of bb for the out-of-memory killer (4 runs), keeps an old-hash bridge process that still owns a thread (3), retires a threadless bridge process superseded by a new artifact hash, and waits for provider retirement before starting a same-key replacement. The two tests named above did not appear in that scan.

What changed

  • packages/agent-runtime/src/test/keep-provider-process-priority.ts, registered as a Vitest setupFiles entry, stubs deprioritizeAgentWorkload from @bb/process-utils. Test bridges now run at the worker's priority, as they did before Graduate six early adopter experiments #8068. Production renicing is unchanged. No agent-runtime test asserts nice values; @bb/process-utils keeps its own workload-priority test.
  • fires onProcessExit when provider crashes now awaits the onProcessExit callback instead of polling it against a 1 s deadline, and asserts it fired once.

The construction-deadline test is unchanged. With bridges back at normal priority it runs in about 1.7 s. Its 1.5 s scripted response delay is what lets it tell the 120 s construction deadline from the 30 s request default, and that delay was not part of the failure.

How you verified

I reproduced this on Linux in an OrbStack node:22-bookworm container pinned to 4 CPUs (--cpuset-cpus=0-3 --init), with nice-0 busy-loop burners standing in for the other suites. At 6 burners, a nice-10 CPU job ran 5.3× slower than the same job at nice 0.

load renice on (main) renice off / this PR
6 burners, 7 runtime test files, ×2 122/122 pass, tests 118 s 122/122 pass, tests 41 s
12 burners, same files, ×2 2 failed each run (command-contract real-time tests), tests 222–231 s 122/122 pass, tests 57 s
64 burners, the target tests, ×2 pass, at CI-like timings: fires onProcessExit 5.7–7.2 s, construction tests 7.5–9.5 s 0.7–2.8 s
110 burners, the target tests all 5 fail: The bridge never received thread/start / thread/resume, and 15 s timeouts for fires onProcessExit and handles JSON-RPC error responses pass, ×2 runs on this PR's code
  • With renice on at 110 burners, the time from ensureProvider resolving to onProcessExit firing was 484 ms in one run and 1762 ms in another. The second would fail the old 1 s wait. With renice off at 110 burners it was 175 ms.
  • A temporary probe confirmed the stub works on Linux: a spawned provider ran at nice 0 with the setup file and nice 10 without it.
  • With this PR on Linux at 12 burners: 305/305 passed. That run skipped runtime.codex-topology and runtime.skill-roots-capability, which need plugin packages the container's filtered install did not have.
  • Locally: pnpm exec turbo run typecheck lint --filter=@bb/agent-runtime passed, and pnpm exec turbo run test --filter=@bb/agent-runtime passed: 23 files, 316 passed, 1 skipped (the Linux-only OOM test).

Not changed here: apps/host-daemon lifecycle scripts get the same nice-10 renice, and other runtime.process-lifecycle tests still poll exit callbacks with the 1 s default. Both are the same kind of issue, but neither failed in the runs above once bridges were back at normal priority.

AGENT GENERATED

🤖 Generated with Claude Code

Since #8068 graduated agentCpuPriority, deprioritizeAgentWorkload renices
every provider process to nice 10 unconditionally. In @bb/agent-runtime
tests that puts each spawned bridge below the nice-0 Vitest workers. On a
contended 4-vCPU Linux CI runner the bridges get a small share of CPU,
so bridge startup and exit take seconds and tests with wall-clock bounds
time out. macOS ignores nice across processes, so this never reproduces
locally.

The agent-runtime Vitest setup now stubs deprioritizeAgentWorkload, so
test bridges run at the worker's priority as they did before #8068.
Production renicing is unchanged.

"fires onProcessExit when provider crashes" also stops polling with the
1s waitForRuntimeState default. That window covered the bridge's
process.exit and the close event, which the runtime itself allows up to
PROVIDER_PROCESS_CLOSE_GRACE_MS (1s) to report. The test now awaits the
callback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 85521e8 into main Nov 25, 2026
33 checks passed
@ymichael
ymichael deleted the bb/fix-agent-runtime-timing-flakes branch November 25, 2026 21:40
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