Lead loses async results when a turn ends without a tool call (#291, #46)#428
Merged
Bill-Billion merged 1 commit intoJun 25, 2026
Conversation
|
@Bill-Billion is attempting to deploy a commit to the crazyboym's projects Team on Vercel. A member of the Team first needs to authorize it. |
3118ab4 to
a995603
Compare
…reAI-lab#291) 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.
a995603 to
464a615
Compare
Bill-Billion
added a commit
to Bill-Billion/learn-claude-code
that referenced
this pull request
Jun 26, 2026
Bring in upstream s15 inbox poller fixes (shareAI-lab#291, shareAI-lab#46, shareAI-lab#428, shareAI-lab#429).
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.
Addresses #291, and the same stranding for background tasks (#46).
After the Lead spawns teammates or dispatches a background task, if the round ends with plain text (stop_reason != tool_use), agent_loop returns and the REPL falls back to a blocking input(). The async work finishes later on daemon threads, and the results (teammate inbox messages, completed background tasks) stay unconsumed until the user types again. collect_background_results() runs only in the tool-use branch, so a plain-text turn never picks up a finished background task either.
Change (only s15_agent_teams/code.py), following real Claude Code's useInboxPoller: decouple input() from turn execution.
Only the Lead's main loop changes. Teammates' idle loops are untouched, since blocking a background thread is harmless and the problem is specific to the Lead, which holds the user prompt.
Verification with the real API, sending no user input between the task prompt and quit:
Out of scope: terminal prompt/output still interleaves (needs a TUI; real Claude Code uses Ink). Three-language README not updated.