Skip to content

Commit fb61510

Browse files
Kowserclaude
andcommitted
Make the 12 system workers spawn-safe: entry classes replace AgentRuntime closures
Group B of the idea-5 spawn-safety design. Every AgentRuntime._register_* control worker was an async-def closure ('<locals>' qualname — unpicklable under 'spawn'): guardrails (combined + single), stop_when, gate, callback, termination, check_transfer, transfer (hybrid + swarm + unreachable), router, handoff_check, process_selection. Each becomes a picklable module-level entry class with async __call__ and plain-data attrs: - User callables (guardrail funcs, stop_when/gate/router fns, legacy callbacks) travel as FunctionRef when module-level, raw otherwise — raw only survives fork, and every registration site now runs probe_spawn_safety (group "system"), so lambdas fail fast at registration with the offender named (design §7 policy). - CallbackEntry carries handlers (by value) + legacy fn (by ref) and rebuilds the _chain_callbacks_for_position chain per call — the chain closure itself was unpicklable. _register_callback_worker's signature changes accordingly (single caller updated). - HandoffCheckEntry keeps blocked_counts as instance state (per worker process — the same semantics as the closure cell it replaces); HandoffConditions travel by value. - TerminationEntry carries the condition object by value; transfer workers become stateless TransferNoopEntry/TransferUnreachableEntry. Tests: async entry across a real spawn boundary, handoff decision + pickle round-trips, callback chain rebuild, fail-fast policy (lambda → SpawnSafetyError at registration). tests/unit: 2518 passed, 1 skipped. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d6ceb00 commit fb61510

4 files changed

Lines changed: 611 additions & 291 deletions

File tree

0 commit comments

Comments
 (0)