Skip to content

perf(supervisor): start bots without holding the supervisor lock - #80

Merged
httpsphl merged 1 commit into
mainfrom
perf/supervisor-spawn
Oct 1, 2026
Merged

httpsphl merged 1 commit into
mainfrom
perf/supervisor-spawn

Conversation

@httpsphl

@httpsphl httpsphl commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Second performance round, slice 1.

What

A reconcile pass used to write each bot's files (settings.json, mcp.json, rules), build its environment block (CreateEnvironmentBlock), create the process and its Job Object, all while holding the supervisor lock, one bot after another. With Defender each start can take hundreds of milliseconds. During that time everything that reads the supervisor waited:

  • bot states (bots.list, system.status)
  • the MCP token check on every tool call
  • is_current on every live-text event
  • the courier, which also holds the store lock at that point, so the store stalled too

Now each start has three steps (supervisor/start.rs):

  1. Under the lock: decide what to start. The slot is marked launching.
  2. Without the lock: write the files and make the process.
  3. Under the lock: record the process, as before.

Edge cases:

  • A bot deleted while it starts has its process killed when it is recorded.
  • A mode, model or effort changed meanwhile restarts the new process as soon as it is recorded (spec 7.4).

start moved out of spawn.rs (which was over 300 lines) into start.rs. The spec gains step 7 in 7.4.

Tests

New tests/supervisor_launch.rs uses a FakeRuntime spawn that the test holds open:

  • supervisor.status answers while the process is still being made;
  • a bot deleted during its start loses its process and its slot.

The full suite, clippy and fmt pass.

Manual check (real Claude)

With the dev daemon, a crew of 3+ bots paused, unpause the crew. All bots reach idle as before, and the app's bot list keeps updating while they start.

Writing a bot's files, building its environment block and creating its
process ran under the supervisor lock, for every bot a reconcile pass
started. Meanwhile every status read, MCP token check, live-text event
and courier delivery waited. The pass now decides under the lock, makes
the process without it and records it under the lock again. A bot
deleted while it starts loses its process; a launch setting changed
meanwhile restarts the new one.
@httpsphl
httpsphl merged commit e4d7ffa into main Oct 1, 2026
3 checks passed
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