Home

mweinbach / agent-coworker

publicmweinbach/agent-coworker
Overview Code History Branches Pull requestsIssuesInsights
main
HomeOverview Code PRsIssues

fix(agents): close spawn-cap race with synchronous slot reservation

4 months ago

f4906ee
Authored
mweinbach6/9/2026, 9:59:35 PM
The concurrency cap counted children, then awaited several times before
registering the new binding. Concurrent spawn() calls (e.g. a model emitting N
spawnAgent calls executed in parallel) all observed the same pre-registration
count and all passed, exceeding MAX_ACTIVE_CHILDREN_PER_PARENT and weakening the
fork-bomb guard (flagged by Cursor Bugbot on PR #159).

Reserve a slot synchronously at the (now combined registered + in-flight) check,
before any await, and release it in a finally once the binding is registered or
the spawn fails. Splits the post-check body into spawnReserved(). Adds a
parallel-spawn regression test that fails without the reservation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Parent590dc5b

2 files changed
  • src/server/agents/AgentControl.ts+27−1
  • test/agentControl.test.ts+63−0