Repository navigation
Keep the server responsive when agents saturate the CPU (behind an experiment) - #6215
Merged
ymichael merged 4 commits intoNov 9, 2026
Merged
Conversation
This was referenced Oct 24, 2026
ymichael
marked this pull request as draft
November 7, 2026 19:42
Contributor
|
This is an automated message. We have closed this pull request because it has been open for more than two weeks. |
…periment) Behind the agentCpuPriority experiment, the host daemon starts provider bridge workers and environment lifecycle scripts at nice 10 (below-normal on Windows), and on macOS the launcher starts the server and daemon with application scheduling (taskpolicy -a). The server sends the value in the session handshake and provider-session-policy.replace (protocol 265) and mirrors it to <data dir>/agent-cpu-priority.json for the launcher. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Provider bridge workers serve several threads, so a live toggle does not reach new threads on a running worker; describe the restart requirement for both halves in Settings and the docs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 9, 2026
## Human comments ## What was wrong The nightly stale-PR cleanup (`.github/workflows/close-stale-prs.yml`) measured age from `created_at` only. A PR reopened after its first closure was therefore closed again at the next scheduled run. #6215 was created Oct 24, closed Oct 27, reopened Nov 7, and closed by the bot on Nov 8 with "open for more than two weeks" after less than a day open. ## What changed Before closing a candidate, the job reads the PR's issue events and treats the PR as open since its latest `reopened` event (or `created_at` if never reopened). PRs reopened within the fourteen-day window are skipped and logged as "Recently reopened". The creation-date prefilter is unchanged, so events are fetched only for PRs older than fourteen days. ## How you verified - Ran the embedded script's `open_since` against live data: #6215 resolves to its 2026-11-07T19:42:06Z reopen (so the Nov 8 run would have skipped it); #6307 (never reopened, closed today) still resolves to its creation time. - Preview run (`APPLY=false`) of the full script against `get-bb/bb` completes without errors. - Checked the last five cleanup runs: #6215 is the only reopened PR that was closed. - `pnpm exec oxfmt .github/workflows/close-stale-prs.yml --check`, `git diff --check` > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/server-stalls-under-many-concurrent-agents-thr_vw834vqyax
branch
from
November 9, 2026 18:05
940e378 to
42e2796
Compare
ymichael
marked this pull request as ready for review
November 9, 2026 18:06
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/server-stalls-under-many-concurrent-agents-thr_vw834vqyax
branch
November 9, 2026 18:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
On 2026-10-23, from 12:16 to 12:53, 15–19 agent threads ran at once. The server main thread was busy for most of the window: event-loop utilization was 0.84–0.88, and the saved CPU profiles show the loop non-idle about 45% of wall time. Yet it consumed only 0.06 CPU-seconds per wall second. The stall logs for 12:30–12:50 show the same thing per task: the longest synchronous work in each stall got 6–7% of its wall time as CPU. A 30 ms timeline build took about 500 ms, and slow
TRANSACTION IMMEDIATEqueries ran at 5% CPU/wall with about 1,200–1,500 involuntary context switches per second. The server was runnable but not scheduled.nicedoes not help. The clutch scheduler first picks among thread groups in the same QoS bucket, so a busy plain process gets only its fair share against dozens of agent, build and test processes. With 48 CPU burners at nice 0, 10 and 19, a server-like probe's 20 ms chunks stretched to 40–80 ms in every case. Clamping agents to utility QoS protected the server but made the agents' own parallel CPU work 2.3–3× slower, so that is not acceptable.nice, but provider processes and lifecycle scripts ran at the same priority as the server.This PR now also contains #6216, and both halves sit behind one experiment.
Timeline builds, Nov 7 2026. A separate investigation found the same cause behind production timeline builds running 4–7x slower than in-process. A build that needs about 160 ms of CPU took 663 ms in production, at 0.39 CPU/wall with 1,810 involuntary context switches and no page faults or disk reads. With 32 normal-priority CPU burners on 16 cores, the same build took 596–703 ms in-process. Under
taskpolicy -ait took 220–232 ms, at 0.99 CPU/wall.What changed
Experiment
agentCpuPriority. It is off by default, including for early adopters, so it runs only where someone turns it on. It has a Settings → Experiments label and description, an app fallback, and entries indocs/configuration.md,docs/debugging-and-qa.mdand the bb guide.Agent processes at nice 10 (from #6216; below-normal priority class on Windows):
@bb/process-utilsdeprioritizeAgentWorkload(pid)sets nice 10, but only whilesetAgentWorkloadsLowered(true)is in effect.bb terminal createor the SDK, which agents use for dev servers.agentCpuPriorityin the session-open response and inprovider-session-policy.replace. That message is already pushed on everyconfig-changed, which an experiment change triggers. It follows the same path asidleProviderSessionTimeoutMinutes.HOST_DAEMON_PROTOCOL_VERSIONto 265. Servers accept only the matching version, so an older daemon is rejected at session open until it updates, and older daemons never lower anything.Server and daemon with app scheduling on macOS (
taskpolicy -a):/usr/sbin/taskpolicy -a, the application resource-management policy.taskpolicyexecs in place, so the PID, stdio, the IPC channel and signal handling are unchanged.NO_PROXYentries Keep bb Node processes alive with scheme-less proxies and bypass the proxy for loopback #6394 adds for--use-env-proxy. With the experiment off, the launcher spawns exactly as on main.{"enabled":…}to<data dir>/agent-cpu-priority.jsonat startup and whenever the resolved experiment value changes.Other platforms, or a missing
taskpolicy, spawn directly as before.Plugin SDK moves to 0.6.135: the new experiment key appears in the bundled
Experimentstype, and the npm version guard requires the bump.How you verified
All numbers were re-measured on Nov 7 2026 at 940e378 (origin/main 55135d1 merged in) on an M4 Max (12P+4E). Each
pnpm start:worktreerun used this checkout's fresh, empty dev data dir.This machine was busy with other threads throughout: load average 32–67 before any burners started. Rows marked "0 extra" include that background load.
Real worktree server, macOS. 4 concurrent keep-alive clients on
GET /api/v1/system/configfor 12 s, with and without 96 extra self-terminating CPU burners, two rounds each. The experiment was toggled withPUT /api/v1/settings/experimentsand bb was restarted between arms.The load client is a plain process, so under burners it gets starved too, and the first
taskpolicy -around with a plain client shows that. Real clients are browser or Electron windows, which macOS already schedules as apps. So the headline rows run the client undertaskpolicy -aas well, to measure only the server.taskpolicy -ataskpolicy -ataskpolicy -ataskpolicy -aThe plain-client plain-server baseline ran first, while the background load was lowest, at 32–58.
Linux (OrbStack VM, 16 vCPUs,
node:22-slim). A server-like probe does 20 ms CPU chunks every 50 ms, against 64 CPU burners, two rounds each:Toggling on the real stack (
ps -axo pid,ppid,pri,ni,commandandps -M). Threads ran in a project on a temp git repo:bb terminal create --command)zsh -lc sleep 45under codex)zsh -c sleep 44)<data dir>/agent-cpu-priority.jsonchanged to{"enabled":true}and back to{"enabled":false}as soon as each PUT returned.Tests:
logged-process:/usr/sbin/taskpolicy -a <node>(macOS). Under the wrapper, the PID and IPC still work.--use-env-proxychild under the wrapper still gets the loopbackNO_PROXYentries. This test fails on the pre-merge wrapper, which dropped the toolchain env.workload-priority:agentCpuPriorityto connected daemons, parsed through the contract schema, and rewrites the launcher file.onAgentCpuPriority, and a policy without the field is ignored.Typecheck and tests pass via Turbo for
@bb/server,@bb/host-daemon,bb-app,@bb/process-utils,@bb/app,@bb/agent-runtime,@bb/host-daemon-contract,@bb/domainand@bb/templates, run withenv -u BB_ACCOUNT_POOL_PARENT_URL -u BB_SERVER_URL -u BB_CLI. The plugin SDK npm version guard passes at 0.6.134; after rebasing onto main, which took 0.6.134 for another change, the bump is 0.6.135.Not re-measured here: agent throughput under nice 10, and Windows below-normal priority.
🤖 Generated with Claude Code