Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
One-shot session never settles: background-agent notifications delivered mid-turn are not read
Date: 2026-10-16. Status: fixed in 11.0.0 — fix(pane): settle turns whose background agents finish mid-turn reads the attachment/queued_command form; feat(pane): report agent_count_mismatch when agent counts disagree adds suggested-fix item 3 as a warning only (it never settles a turn). Verified offline (the replay below: agents 2/2, settled by turn_duration at line 654) and live on 2026-10-17 (a bare CLI team run with the live recipe: the child transcript, Claude Code 2.1.301, held one async launch and its notification as attachment/queued_command, zero user notifications; the slot COMPLETED in 42 s with DONE, no anomalies). Diagnosis verdict: Confirmed (offline replay of the real transcript through the production reducer and settle rule).
Summary
One-shot create_session 779a03f0 stayed RUNNING after its child had finished, and ended only by cancel_session. The injected plugin message is NOT the cause. The cause is that the child had launched two background agents earlier in the same turn, and Claude Code 2.1.301 delivered the <task-notification> of each of them while the turn was still running, as attachment records of type queued_command, not as main-chain user records. The transcript follower counts a background agent as completed only from a user record (applyUser -> applyNotification), so it kept agentsLaunched 2, agentsCompleted 0. pathPrimary refuses to settle while agents are unbalanced, so neither turn_duration (08:19:00, 08:19:24) could ever settle the turn; the reported activity was background.
Symptom (as reported, and in the session records)
list_sessions: 779a03f0RUNNINGfor 70 s+ after the last assistant message.get_output:output "",turnsCompleted 0.- Ended only by
cancel_sessionat2026-10-16T08:20:30.953Z. ~/.claudish/sessions/779a03f0/meta.json:"status": "cancelled","turnsCompleted": 0,"terminalReason": "cancelled","toolCallCount": 97,"turnSource": "transcript","lastActivityAt": "2026-10-16T08:19:25.401Z","timeoutSeconds": 1800.events.jsonl:STARTING->RUNNING07:54:47.148Z, assistant records to 08:19:24.718Z, thenRUNNING->CANCELLED08:20:30.953Z. No settle in between.
Environment
- claudish 10.6.1 MCP server (reported); the diagnosis read worktree
claudish-mcp-updateat HEAD87d31943. - Claude Code 2.1.301 (every record of the child transcript carries
"version":"2.1.301"). - magmux 0.15.1 (reported).
- Child model
[email protected](spawn routing chain[email protected][email protected][email protected]+or@openai/gpt-6.1-sol), magus claudish plugin enabled inside the child.
Timeline (child transcript f2f921c4-...jsonl; "line" is the JSONL line number)
| time (Z) | line | record | effect on the follower turn view |
|---|---|---|---|
| 07:54:46.847 | 11 | user, origin.kind:"human", "Your task is in the file ...turn-1.md..." |
witness; acceptedAt set |
| 07:56:42.873 | child calls create_session -> 969aa273 (FAILED prompt_not_accepted 07:57:16) |
ordinary MCP tool_use + tool_result, balanced | |
| 08:10:38.845 | 497 | tool_result toolUseResult.isAsync:true, agentId:"ae0168d27fc09161c" |
agentsLaunched 1 |
| 08:10:49.324 / .581 | 503-504 | TaskStop ae0168d27fc09161c -> "Successfully stopped task" |
nothing |
| 08:10:50.745 | 517 | attachment queued_command, prompt <task-notification><task-id>ae0168d27fc09161c</task-id>...<status>killed</status> |
ignored (no attachment branch) |
| 08:11:04.038 | 516 | tool_result isAsync:true, agentId:"ab9d8b94e58c3540a" |
agentsLaunched 2 |
| 08:15:13.581 | 561 | attachment queued_command, <task-id>ab9d8b94e58c3540a</task-id>...<status>completed</status> |
ignored |
| 08:15:44.725 | 597 | same agent, completed again (after a SendMessage resume) |
ignored |
| 08:15:58.756 | 609 | same agent, completed again | ignored |
| 08:18:39.831 | 647 | TaskStop ab9d8b94e58c3540a -> "No task found" (Claude Code already holds it finished) |
nothing |
| 08:19:00.501 | 652 | assistant end_turn "Applied the test-only fixes..." |
lastAssistant |
| 08:19:00.566 | 653 | system/stop_hook_summary |
stopHookSummaryAfterLast true |
| 08:19:00.571 | 654 | system/turn_duration 1453731 ms, NO pendingBackgroundAgentCount (Claude Code: 0 pending) |
td set; agents 2/0 -> not settled, activity background |
| 08:19:10.593 | 663 | user, origin.kind:"plugin", "The claudish plugin sent a message: 1 slot finished... 969aa273" |
wakingAfterLast true (correct: the model did continue) |
| 08:19:16.583 - 08:19:24.295 | 665-671 | get_diagnostics tool round; assistant end_turn "Confirmed: this is the delayed notification..." |
waking cleared by the assistant record |
| 08:19:24.366 | 673 | system/turn_duration 13778 ms, no pendingBackgroundAgentCount |
td set; agents still 2/0 -> not settled, activity background |
| 08:20:30.953 | cancel_session |
RUNNING -> CANCELLED |
Root cause
Location: packages/cli/src/pane/transcript-follower.ts:494-524 (applyRecord has no branch for attachment records), consumed by packages/cli/src/pane/settle-rule.ts:145 (pathPrimary returns null while !agentsBalanced(t)).
Observed
The transcript has exactly two background-agent launches (lines 497, 516) and zero main-chain
userrecords containing<task-notification>. Every notification for those two agents is anattachmentrecord withattachment.type:"queued_command"whoseattachment.promptstarts<task-notification>(lines 517, 561, 597, 609), each mirrored by aqueue-operationenqueue/remove pair.applyRecord(transcript-follower.ts:494-524) dispatches onlyassistant(516),user(517),system/local_command(518),system/stop_hook_summary(519-520) andsystem/turn_duration(521). Anattachmentrecord falls through every branch.An agent is counted on launch at
transcript-follower.ts:417and completed only inapplyNotification(transcript-follower.ts:442-447), reached only fromapplyUser(transcript-follower.ts:470) throughisTaskNotification(transcript-follower.ts:226-228), i.e. only for auserrecord.agentsBalanced(settle-rule.ts:72-74) isagentsLaunched === agentsCompleted. With aturn_durationpresent,decideSettlereturnspathPrimary(...) ?? notYet(settle-rule.ts:172), andpathPrimaryreturns null on!agentsBalanced(t)(settle-rule.ts:145) before it ever consults the screen. Path S is unreachable once aturn_durationexists (line 172 returns first).activityOfreportsbackgroundfor this state (settle-rule.ts:96-98).Offline replay of the real transcript through
applyRecord/turnView/decideSettle(recipe 2 below):cut waking agents launched / completed decision after line 654 (08:19:00 turn_duration)false 2 / 0 {settled:false, activity:"background"}after line 663 (plugin message) true 2 / 0 {settled:false, activity:"thinking"}after line 673 (08:19:24 turn_duration)false 2 / 0 {settled:false, activity:"background"}end of file false 2 / 0 {settled:false, activity:"background"}end of file, counterfactual agentsCompleted := agentsLaunchedfalse 2 / 2 {settled:true, by:"turn_duration", stopReason:"end_turn", anomalies:[]}acceptedAtstays2026-10-16T07:54:46.847ZandpendingToolstays null at every cut.Screen facts computed with the production classifier (
inputBox,hasChoiceDialog,isWorking, exactly aspane-session.ts:1171-1180builds them) on the saved final screen~/.claudish/sessions/779a03f0/screen.txt:boxEmpty:true, choiceDialog:false, working:false, box rows 45-47. The magus band (◆ claudish · 1 failed,#969aa2 ✕ failed ...) sits above the box and is neither a choice dialog nor a working row.
The four candidates
- (a) screen corroboration fails because of the mod band: rejected. The final screen corroborates (observation 6) and the counterfactual settles with that same screen (observation 5). Intermediate frames were not captured, but they cannot matter:
pathPrimaryreturns beforecorroboratedis called (settle-rule.ts:145-146). - (b) the injected plugin message keeps
wakingAfterLasttrue or resetsacceptedAt: rejected. It setswaking(transcript-follower.ts:471-474), which is right because the model did answer it, and the assistant record at 08:19:16 clears it (transcript-follower.ts:379).acceptedAtnever changes (observation 5). The plugin message delayed the turn by 24 s; the turn was already unsettleable at 08:19:00. - (c)
pendingToolor the agent count left unbalanced by the child owncreate_sessionMCP call: rejected as stated. Every MCP tool_use (create_session,capture_session,get_diagnostics) has its result;pendingToolis null. The agents ARE unbalanced, but by the two built-in backgroundAgentlaunches, not by the MCP call. - (d) confirmed: a background-agent completion arrives as
attachment/queued_commandwhen Claude Code folds its queue into a turn that is still running; the follower never reads attachments, so the agent tally can never balance and P can never fire.
Inferred (not directly observed)
- Claude Code writes a notification as a
userrecord (origin.kind:"task-notification", as in fixturetools-session.jsonl, 2.1.290) when it arrives while the REPL is idle and becomes a new prompt, and as anattachment/queued_commandwhen it arrives while a turn is in flight and rides the next API request of that turn. Each notification here sits between a tool round and the next assistant record of the same turn, which fits. The attachment form is not new in 2.1.301: corpus fixturecorpus-redacted/auto-compaction-in-turn.jsonl(2.1.263) already contains onequeued_command<task-notification>attachment. - Claude Code itself counted 0 pending agents at both
turn_durationrecords (it writes the field only above 0,pane-session.md"Background work (D23)"), so the claudish tally and the Claude Code count diverged. - Without the cancel the session would have hit
timeoutSeconds: 1800at about 08:24:44Z and endedtimeout, still with no output. get_outputwas""because the answer is assembled when the turn settles; no settle, no answer.
Reproduction
1. Live recipe (not run for this report: no live model session was started)
Needs the claudish MCP server and any routable model. The magus claudish plugin is NOT needed to trigger the defect.
From the harness, call
create_session(one-shot) with model[email protected](any model works) and this prompt:Launch one background agent with the Agent tool (run_in_background: true), description "noop", prompt "Reply OK and stop." Immediately after it is launched, run the Bash command
sleep 20in the foreground. Then reply with exactly DONE.The foreground
sleep 20keeps the turn in flight while the agent finishes, so its notification is folded into the turn asattachment/queued_command. A variant closer to 779a03f0: launch the background agent, immediately callTaskStopon its id, then reply DONE (thekillednotification is queued mid-turn, as at line 517).Wait until
capture_sessionshowsDONEand an empty input box.At least 40 s later call
list_sessionsandget_output.
Expected: state COMPLETED, turnsCompleted 1, get_output returns DONE.
Actual (predicted from the confirmed mechanism): state RUNNING, activity background, get_output returns output "" and turnsCompleted 0, until cancel_session or the session timeout.
Confirm the trigger fired: the child transcript (transcriptPath in meta.json) must hold a "type":"attachment" record with "type":"queued_command" whose prompt starts <task-notification>. If the notification arrived instead as a user record (origin.kind:"task-notification"), the agent finished after the turn ended and the session settles normally; lengthen the sleep.
The recipe this investigation started from (the child calls create_session on a model that fails fast, e.g. no-such-model-zz9, then replies DONE at once, magus claudish plugin enabled) does NOT reproduce the defect on its own: the plugin message is a user record after the turn ended, which the follower reads as a wake and settles at the next turn_duration once agents are balanced (observation 5, counterfactual row). It reproduces only when the child also ran a background agent whose notification was folded into a running turn.
2. Offline recipe (run; its output is the table in observation 5)
Script (tracked): ai-docs/reports/2026-10-16-session-unsettled-replay.ts. It imports initialFollowerState, openTurnState, applyRecord, turnView from packages/cli/src/pane/transcript-follower.ts and decideSettle from settle-rule.ts; builds screen facts from screen.txt with screen-model.ts applyCapture and the screen-classifier.ts predicates; opens turn 1 at offset 0 with the witness text of line 11; folds the records up to each cut; and calls decideSettle with transcriptQuietMs = chatQuietMs = 120000, paneExited:false.
cd /Users/jack/mag/claudish/.claude/worktrees/claudish-mcp-update
bun ai-docs/reports/2026-10-16-session-unsettled-replay.ts \
/Users/jack/mag/claudish/.claude/worktrees/claudish-mcp-update \
/Users/jack/.claude/projects/-Users-jack-mag-claudish--claude-worktrees-claudish-mcp-update/f2f921c4-efb3-4103-b089-c9397b667f56.jsonl \
/Users/jack/.claudish/sessions/779a03f0/screen.txt
Without the script, the decisive facts are three jq calls:
T=/Users/jack/.claude/projects/-Users-jack-mag-claudish--claude-worktrees-claudish-mcp-update/f2f921c4-efb3-4103-b089-c9397b667f56.jsonl
# launches: 2 (ae0168d27fc09161c, ab9d8b94e58c3540a)
jq -c "select(.toolUseResult|type==\"object\") | select(.toolUseResult.isAsync==true) | .toolUseResult.agentId" "$T"
# task-notification user records: 0
jq -c "select(.type==\"user\" and ((.message.content|tostring)|test(\"task-notification\")))" "$T" | wc -l
# where the notifications are: 5 attachment/queued_command records, 4 of them task-notifications (line 608 is an agent-message)
jq -c "select(.type==\"attachment\" and .attachment.type==\"queued_command\") | .attachment.prompt[0:80]" "$T"
Impact
- Every pane session that settles through
decideSettle(pane-session.ts:1200): one-shot and interactivecreate_session,teamslots, channel sessions, whenever the child launches a background agent (built-inAgentwithrun_in_background, or any agent Claude Code runs async) that finishes, or is stopped withTaskStop, while the same turn is still running. That is the normal pattern of a delegate that delegates: it launches a runner, keeps working or sleeps, and the runner finishes mid-turn. - Symptom: RUNNING with activity
backgroundforever, emptyget_output,turnsCompleted 0; the session ends only bycancel_sessionortimeout. Ateamslot in this state holdsjudge/run-and-judgeuntil its timeout; an interactive session queues every latersend_inputbehind a turn that never settles. - Prompt-injecting plugins inside the child (the magus claudish status mod) are not the trigger. They co-occur because a child that uses claudish itself is also the kind that runs background runners.
- It fails silently: no anomaly, no error, and
backgroundreads as legitimate waiting.
Suggested fix (no code)
- In the follower, read main-chain
attachmentrecords whoseattachment.typeisqueued_commandand whoseattachment.promptcontains<task-notification>: take the<task-id>and complete the agent / drop the background shell exactly asapplyNotificationdoes. Do NOT mark the turn waking on it: the attachment rides an API request already in flight, and the assistant record that answers it follows anyway. One agent may notify several times (lines 561, 597, 609); theagentsDoneset already counts it once. Read the attachment, not thequeue-operationrecords, so a queued item that is removed without reaching the model is not counted. - Treat a terminal
<status>killed</status>(TaskStop) likecompletedfor balancing; the currentapplyNotificationalready ignores status, keep it that way. - Defence in depth, optional: at
turn_duration, Claude Code own count (field absent means 0 pending) disagreeing with the claudish tally should at least record an anomaly (for exampleagent_tally_mismatch) so the next divergence is visible. Whether an absent field may override the tally is a design decision forpane-session.mdD23; this report does not recommend it alone, because the tally exists to mirror that count, not to be replaced by it. - Tests: a fixture cut from this real transcript (redacted), asserting
agentsCompleted === agentsLaunchedafter line 609 andsettled:true, by:"turn_duration"after line 654; also assert the already-present attachment incorpus-redacted/auto-compaction-in-turn.jsonlis read. Updatepane-session.md"Background work (D23)" and "Waking records" to name both delivery forms of a notification.
Evidence paths
- Child transcript:
/Users/jack/.claude/projects/-Users-jack-mag-claudish--claude-worktrees-claudish-mcp-update/f2f921c4-efb3-4103-b089-c9397b667f56.jsonl(lines 11, 497, 503-504, 516, 517, 561, 597, 609, 647, 652-654, 663, 665-673) - Session records:
/Users/jack/.claudish/sessions/779a03f0/(meta.json,events.jsonl,spawn.json,screen.txt,output.log) - Nested failed session:
/Users/jack/.claudish/sessions/969aa273/ - Code:
packages/cli/src/pane/transcript-follower.ts:226-228, 417, 442-447, 449-475, 494-524, 526-536;packages/cli/src/pane/settle-rule.ts:72-74, 92-101, 141-148, 162-178;packages/cli/src/pane/pane-session.ts:1171-1216 - Fixtures with each notification form:
packages/cli/src/pane/test-fixtures/transcripts/tools-session.jsonl(user, 2.1.290);packages/cli/src/pane/test-fixtures/transcripts/corpus-redacted/auto-compaction-in-turn.jsonl(attachment/queued_command, 2.1.263) - Rationale:
ai-docs/architecture/pane-session.md, sections "Settle" and "Background work (D23)" - Offline replay script:
ai-docs/reports/2026-10-16-session-unsettled-replay.ts