mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-08-07 12:33:46 +08:00
After the Lead spawns teammate agents, if the current round terminates with plain text (stop_reason != tool_use), agent_loop returns and the REPL falls back to a blocking input(). Teammates run as daemon threads and finish later, so the results they send to the Lead's inbox stay unconsumed until the user submits their next input. The cause is that result delivery is bound to the turn loop, whose lifetime ends when the model stops calling tools, while a teammate completes on its own clock. Blocking a teammate is harmless because it runs as a background thread; the problem is specific to the Lead, which owns the user prompt. The fix follows real Claude Code (useInboxPoller, described in the appendix): decouple input() from turn execution. MessageBus.peek(agent) reports whether the inbox has unread messages without consuming them. In __main__, input() moves to a dedicated daemon thread and an inbox poller thread peeks the Lead's inbox every second; both push to one shared event queue. The main thread runs one turn per event, woken by either user input or an incoming teammate message, so teammate results become new turns without waiting for the user. Repeated inbox wakeups are idempotent: an empty read is skipped when a prior read_inbox already drained the messages. Only the Lead's main loop changes; the teammates' idle loops are untouched.
35 KiB
35 KiB