Repository navigation
Agent suggestions
Public previewDescription
When a Claude agent-host turn spawns a background subagent, the parent finishes its own turn. Once the subagent settles and the parent resumes producing output, every SDK message is discarded, so the chat shows nothing further for the rest of the work. The transcript on disk records all of it, so restarting the agent host makes the whole response appear at once.
Steps to reproduce
- In a Claude agent-host session, send a prompt that makes the agent spawn background subagents, for example "use subagents to audit these two directories in parallel, read-only".
- Watch the chat while it works.
Expected: the parent's output keeps appearing as the subagents report back.
Actual: the response stops at whatever the parent said before spawning, typically one or two lines, and nothing more ever renders. No error appears in any log, at any log level.
Restart the agent host and reopen the session: the complete response appears, rebuilt from the transcript.
Root cause
ClaudeSdkPipeline._processMessages derives the turn from the prompt queue head:
const parent = this._queue.peekParent();
const turnId = parent?.turnId;A parent that spawns background subagents ends its own turn, so the queue drains and turnId becomes undefined for everything that follows.
ClaudeSdkMessageRouter.handle then drops the message outright:
if (turnId === undefined) {
return;
}That early return is silent at every log level, which is why the failure leaves no trace anywhere.
Evidence
Captured on a live host with AgentHostStateManager's envelope logging temporarily raised to info:
| Host's last emitted envelope | 9:15:13 p.m. |
| Parent produced 4 assistant messages | transcript, 9:15:17 to 9:15:21 p.m. |
| Envelopes emitted for those messages | none |
The three AgentSideEffects drop paths (Dropping stale ..., Dropping completion for cancelled turn ...) were also raised to info for the same run and never fired, confirming the message dies earlier, in the router.
Replaying that session's transcript offline through mapSessionMessagesToTurns produces the turn with all 35 response parts (3 markdown, 23 tool calls, 9 reasoning). The data is intact; only the live path loses it.
Related
PR #331872 hooks this same early return for system / task_notification, so a background subagent's chip completes. That is a narrower case of the same gap: once a turn id is available, claudeSubagentSignals already maps task_notification normally, so a general fix here supersedes it.
Version
Visual Studio Code 1.1.3 (stable), server commit 110a328ea54b42367b803ec53ee0bf52ef26b419, dev container on linux-arm64. Root cause confirmed against main.
AI disclosure: this issue and the related code were written with the assistance of AI.
Public patches and patcher scripts
Public patch catalog and patcher scripts · Source patch index. The public collection includes the maintained patchers, rollback instructions, regression scripts, and historical snapshots. Build restrictions and exact installer coverage are documented there.
Activity
RyanEwen commentedon Aug 31, 2026
Another way into this, which the fix in #332075 cannot cover: closing the window while background subagents are running.
Closing the window tears down the agent host, and with it every subagent that was mid-flight. When the window reopens, the SDK resumes and the parent's remaining output arrives, but there is no turn left to attach it to. Observed in a dev container today:
Four results, all with no turn, spread over eleven minutes after the window came back. In the same session's AHP log,
chat/turnStartedappears 10 times andchat/turnCompletetwice, so eight turns were left open and never closed. The chat shows nothing further for any of them.Why the pending fix does not help here
I am running #332075 as a local patch, and I verified it was live in the process that produced the log above: the resume-anchor marker is present in the running
agentHostMain.js, and the bundle was patched three days before that host started.It still cannot help, because the anchor is in-memory. The turn is recorded on the subagent registry when a background subagent starts, and that registry lives in the agent host process:
turnId === undefined, and there is no anchor left to route it toSo #332075 fixes the case where the parent's turn ends while the host keeps running, which is the common one, but not the case where the host itself restarts. Both produce the same user-visible symptom, which is why I am adding it here rather than filing separately.
What this suggests
The anchor needs to survive a host restart to cover this, which means deriving it rather than remembering it. The transcript already records which turn a subagent was spawned in, so on reconnect the host could recover the mapping from the transcript instead of relying on state it happened to be holding when the window closed.
Closing a window while agents are working is an ordinary thing to do, and today it silently strands whatever they produce afterwards, with the turns left open in the UI.
AI disclosure: this comment and the related investigation were written with the assistance of AI.
RyanEwen commentedon Sep 2, 2026
I can now reproduce this ratio on demand, from a different trigger, which I think strengthens the case that the missing terminal path is a defect in its own right rather than only a consequence of the window closing.
Driving a real window through a scripted scenario, with a prompt that causes several subagents to be spawned:
Seven subagent turns opened, two completed, five left open, plus the parent's follow-up turn. No window was closed and no host restarted; everything stayed up throughout. The chat shows nothing further for any of the open turns, and waiting does not change it.
The mechanism is the one I have filed separately as #333931: the subagent's tool call is announced and then never executed, so the spawning tool never produces a
tool_result, sosubagent_completednever fires, andcompleteSubagentSessionis the only thing that can close a subagent turn.The reason I think this matters here: the two triggers differ, but the end state is identical, and in both cases nothing in the product can recover it. A turn whose producing work is gone stays open forever, because the only thing resembling a watchdog reports a hang reason to telemetry and dispatches no action. Whatever fixes the underlying stall, a terminal path for an abandoned turn looks worth having on its own.
Reproduced on 1.135.0 (
08d4889f9ec4a1685d257b9b95de036c8e1ce1e5), and separately against a fully stock reverted bundle to rule out my local patches.AI disclosure: this comment and the related investigation were written with the assistance of AI.
RyanEwen commentedon Sep 3, 2026
Adding the host-side mechanism, observed live rather than derived from source.
A background subagent's signals are dropped wholesale once its own chat has no active turn. In
AgentSideEffects, a signal carrying aparentToolCallIdresolves the subagent chat and then gates on that chat's active turn:The
returnis unconditional, so with no active turn the signal is neither dispatched nor buffered. The sibling_pendingSubagentSignalspath immediately below covers only the case where the subagent chat does not exist yet, not the case where it exists without a turn.From a single session today:
model_call_completed,chat/responsePart,chat/toolCallStart,chat/toolCallReadyandchat/toolCallCompletesubagent_completedsignalsThe user-visible result is this issue's title exactly: the parent appears to just end, and nothing further ever renders. It does not self-heal when the subagent eventually finishes, because
subagent_completedis dropped by the same gate, so the chip never resolves either.I recovered the subagent's full output afterwards from the SDK transcript on disk, which is unaffected by this gate. So the work is being done and recorded; only the path to the UI is lost.
Worth separating this from #334072, which fixes the client-side observation lifetime. This gate is host-side and would still drop the signals regardless of that change.
AI disclosure: this comment and the related investigation were written with the assistance of AI.
RyanEwen commentedon Sep 4, 2026
Confirmed live on 1.136.1, with four things that change the shape of this issue.
1. The lost traffic is mostly the parent's own turn, not subagent chatter.
When background subagents finish, the SDK injects a
task-notificationuser prompt and starts a new top-level turn. That prompt never passes throughClaudePromptQueue: the whole 3065-line host log for the run contains exactly twoqueue yieldedlines, both from before the drain. SopeekParent()returns undefined andclaudeSdkMessageRouter.ts:74drops everything.In the run I captured, the discarded output was three assistant text blocks, five
Bashcalls, aReadand anAskUserQuestion, over six minutes. That reframes the fix: it is not "recover a turn id", it is "open a turn the host did not start". The replay path already does exactly this,ReplayBuilderopens a turn per user envelope, which is why restarting the host makes the missing content appear.2.
AskUserQuestionis silently auto-denied by the same empty queue.claudeAgentSession.ts:1326resolvesCancelwhenever!hasActiveTurn, andhasActiveTurnis!this._queue.isEmpty. The model asked the user a question; the tool result came back 7 ms later asThe user cancelled the questionwithtoolDenialKind: permission-rule. The user was never shown anything. This is a second, independent casualty on thecanUseToolcontrol path, not the message stream.3. Every drop path in
AgentSideEffectslogs attrace, so absence of drops proves nothing.agentSideEffects.ts:704,:734,:901and:648are alltrace. A host running atinfoproduces a log with zero evidence of the discarding. I twice treated "0 dropped signals" as meaningful before checking the level.4. "The host log goes silent" is the wrong framing.
The
for awaitloop keeps running for the entire silent period. The tell is:emitted from inside the loop body when
settleHead()pops nothing. Messages keep arriving; there is simply no queue entry to attach them to. Anyone debugging this by looking for a stalled loop will not find one.For completeness,
claudeToolCallRegistry.clearPendingwipes cross-message tool attribution on everyresult, including in-flight tool calls belonging to background subagents.drainForegroundSpawnsdeliberately spares background spawns from its equivalent wipe;clearPendinghas no such exemption. That is a separate defect in the same moment, not a cause of this one.AI disclosure: this comment and the related investigation were written with the assistance of AI.
mmontagnana commentedon Sep 29, 2026
Still reproducing on VS Code 1.139.1 (stable, macOS arm64), model
claude-opus-5-5. Note: the agent host runs Claude Agent SDK 0.3.282, swapped in manually because the bundled 0.3.258 doesn't support Opus 5.5 (#338638). The bug itself predates that: it was confirmed here on 1.136.1 with the stock SDK.The parent spawned two background subagents and ended its turn. From the session transcript on disk:
task-notificationwith<status>completed</status>delivered to the parentNone of the 16:59–17:07 output was rendered. The chat stopped at the parent's last message before the subagents finished ("waiting for the two agents…"). Both subagent chips still showed a spinner and "Working for 37m 8s" long after they had finished.
This is worse than a cosmetic glitch. Believing the agents were still running, I waited for 17 minutes. When the agent then referred to "the fixes", I had no idea what it meant, and I approved the next step (opening PRs) without having seen the report, which included an unresolved issue and a required merge order. Nothing in the UI hinted that output was missing.
Reload Window does not recover. The agent host runs as a utility process owned by the main process (here, up since 09:51), so it survives a window reload. The session and all three subagent chips (including one from a turn two hours earlier) stay "in progress" with a tool call shown as
Running, even though everytool_usein the subagent transcripts has itstool_result. Only a full quit restarts the host. There is no "Restart Agent Host" command, and one would be a useful stopgap.A full quit recovers, as described above. On quit, VS Code warned "A session is in progress. Are you sure you want to quit?", because of the phantom state. The session looked like it was doing work, although nothing was running. After restarting, the session is idle and the missing turn is rebuilt from the transcript. The same goes for all three subagent chats: they are no longer stuck on
Runningand now end with their final report (SubagentHandback). So the subagents' output had been dropped live too, not only the parent's. The replay has three cosmetic differences:<task-notification><task-id>…</task-id><tool-use-id>…XML, shown as if it were a user message;<system-reminder> Your final report is delivered through SubagentHandback…block, again rendered as a user message;+1 for landing #331872 / #332075.
AI disclosure: the timeline was reconstructed from the session transcript with the assistance of AI.
counterfactual5 commentedon Oct 13, 2026
Another path to
result for sdkUuid=undefined: a queued prompt settled by a task-notification turn, and a retry loop that re-announces the same agentVS Code 1.141.0, agent host with Claude Agent SDK 0.3.281. This is a different trigger from the empty-queue case described above.
1. The notification turn's empty
resultsettles the queued user promptOn resume, the CLI reported a background agent from the previous process as stopped. My prompt was queued at that point. The notification turn ran first, and its
resulthad nouser_message_uuidand no text.settleHead()still popped my prompt on that result, so my turn completed empty. The real answer arrived 12 s later with an empty queue:The answer is in the session transcript at 16:57:24. I replayed the same sequence through the real
ClaudeSdkPipeline(task_notification → result without UMU → answer whoseuser_message_uuidis my prompt) and got the same log and no rendered text.2. Re-sending re-announces the same agent, which repeats step 1
Before every re-send the host logged
truncateChat kept [0..request_b045…] (anchor=3dc2b215…). That anchor is the last assistant message before the dropped turn, soresumeSessionAtcuts the notification and the answer out of the resumed chain. The CLI then reports the same agent as stopped again, apparently because "already reported" is derived from the<task-notification>entries in the loaded chain. In this session the same agent was reported 5 times (once legitimately, then after each of 4 re-sends). All 5 entries share the sameparentUuid(the anchor). Each time, the empty result settled the new prompt within ~2 s, and 4 answers ended up assdkUuid=undefined.SDK-only reproduction, without VS Code: start a background agent and exit the CLI while it runs. Then:
resumeSessionAt= last assistant message before that notification → the same notification again, as a sibling of the first3. The SDK already guards this truncation
With
resumeDropsTurnset to the discarded prompt's UUID, the truncating resume is refused:The first discarded entry is the
<task-notification>. The agent host passesresumeSessionAtbut neverresumeDropsTurn. The guard also requires a UUID-shaped turn id, and it rejectsrequest_<uuid>, which the host currently uses as the SDK user-message uuid.Suggested direction
user_message_uuidinstead of queue position. Nothing underplatform/agentHostreads it today. A turn's owner is the UMU on its first top-level frame and on itsresult. A turn that starts without one is SDK-initiated, and itsresultshould not settle a user prompt.resumeDropsTurnwhen truncating, and fall back to a plain resume when it is refused.On #336753
From reading the diff (not run end-to-end):
_adoptSdkTurnonly adopts when the queue is empty, so in step 1 the answer would show up as a separate turn after an empty reply. A second prompt queued at that point would still be credited with the answer. The anchor change only applies to adopted turns, and a notification turn with no assistant output is never adopted, so I'd expect the loop in step 2 to persist.I can share the replay harness and the SDK scripts.
gogetenk commentedon Oct 27, 2026
Still reproducing on VS Code 1.143.1 (Windows 11, Anthropic account, Sonnet), fresh
--user-data-dir, with a minimal prompt:Both files are written and the transcript gets
<status>completed</status>for both. The chat stops at "launched", the "Write a.txt" chip stays on "Working" with its command shown as Running, and "Write b.txt" never gets a chip at all: only oneStarting subagent turnis logged, for the first tool call.No user message and no
resume rebuildduring the run. Details in #344508, closed as a duplicate of this one.not-happy commentedon Nov 2, 2026
Independent confirmation on VS Code 1.144.0 (commit
2c33b50b, Windows Server 2022 x64,anthropic.claude-code2.1.312). Two data points that broaden the scope:1. Provider/model-agnostic. This environment routes the Claude harness through a custom
ANTHROPIC_BASE_URLproxy with a non-official model ID. The drop behaves exactly as described here, so it is not tied to first-party Anthropic models or accounts.2. Plain
run_in_backgroundshell tasks trigger it too — not only Agent subagents. The session ran long Maven builds as background Bash tasks; the parent ended its turn while they were still running.Timeline from
agenthost.log+ the on-disk session transcript (2026-11-02, local time):Everything the model produced during the SDK-initiated turn (10:59:01–11:00:05) is present in the transcript but nothing rendered in the chat — consistent with
peekParent()returningundefinedafter the queue drains and the silent early return inclaudeSdkMessageRouter.ts(still present on currentmain):A fresh user prompt at 11:00:53 (next
queue yielded) was required to make the session visibly respond again.Also observed, for contrast:
<task-notification>entries arriving mid-turn showenqueue→removein the transcript (consumed by the in-flight turn) and are handled correctly. Only the idle-wake path is dropped, matching the analysis above.Watching #336753.
g27182818 commentedon Nov 4, 2026
Another symptom of the same cause, reproduced on server build
a717861c07586a53d83b80d742cd3f59b20a6273, Linux remote, Claude Code agent host.Repro: in an agent-host session, spawn one background subagent whose only job is
date -u; sleep 240; date -u, and end the parent turn straight away. Send a few messages while it runs.Observed: the subagent finishes; the parent receives its report and a
completedtask-notification. In the UI:Host log (
agenthost.log): every user turn appears as aqueue yielded … turnId=X/result for sdkUuid=Xpair. The parent turn that ran once the subagent finished has no turn attached:This matches the root cause above: once the parent's turn has closed,
turnIdcomes from the queue head, which is empty, so the messages are dropped. Here that includes the subagent's later tool results and the parent'stoolCallCompletefor the Agent call, so the card can never finish. I saw the samesdkUuid=undefinedresult in an earlier occurrence (2026-10-14, VS Code 1.141.0).No
resume rebuildoccurred in this run (pid unchanged), so this is independent of #339309.not-happy commentedon Nov 5, 2026
A coverage-gap note tying #345986 to this issue, in case it helps triage.
#345986 (which fixes #339309) is now cross-referenced here, but the core drop path reported in this issue survives that PR. Its changes are confined to
claudeAgentSession.ts,claudePromptQueue.tsandclaudeSdkPipeline.ts: deferring deferrable rebuilds while background tasks are live, and settling queued prompts byuser_message_uuidso an SDK-initiated turn'sresultcan no longer masquerade as the reply to a pending user prompt. It does not touchclaudeSdkMessageRouter.tsand does not open a turn for SDK-initiated output arriving on an empty queue. The silent early return is still on currentmain(claudeSdkMessageRouter.ts, lines 82-84 as of today):So the exact scenario I confirmed above (VS Code 1.144.0, custom
ANTHROPIC_BASE_URLwith a non-official model ID, plainrun_in_backgroundBash tasks — no Agent subagents involved) still loses the whole idle-wake turn:#345986 removes one aggravating factor — a follow-up send while tasks are live no longer rebuilds the session and SIGKILLs them — but for a session that is simply idle when a background task settles, the continuation output is still dropped wholesale, at every log level, and the chat stays dead until the next user prompt.
On the PR that does target this issue, #336753: last commit Sep 18, last activity Sep 21, currently conflicting with
main, and no human review so far. Note also that #345986 touches the same two files (claudePromptQueue.ts,claudeSdkPipeline.ts), so whichever lands second will need another rebase — the two fixes are complementary (keep tasks alive + match results to prompts, vs. render SDK-initiated turns) rather than alternatives.TylerLeonhardt since both community PRs are stalled, is there an internal fix planned for rendering SDK-initiated reply turns (the idle-wake
task-notificationcontinuation)? If a narrower scope than #336753 would be preferable, I can help with verification — I have a reliable log-based repro on Windows Server 2022 with a proxied endpoint.the-corp-mark commentedon Nov 10, 2026
Still reproducing on VS Code 1.145.2 (commit
c4453f8e, macOS arm64), modelclaude-opus-5-5, with eight background subagents launched in parallel.The parent's own turn completes normally, then every turn the SDK starts afterwards arrives with no turn id:
No
Dropping …line is logged, which matches the silent return inclaudeSdkMessageRouter.ts. All eight subagent transcripts end with a successful hand-back between 10:21:34 and 10:21:38, yet all eight chips stay on "Working", each frozen on an earlier step: either a shell call still shown as Running, or "Working on it…". The parent's seven progress updates and its final reply are all in the transcript on disk, but none of them render.Is #336753 still the intended fix? It has been waiting for review since September, and this now reproduces with every background-subagent prompt.
GNeras commentedon Nov 27, 2026
Still reproduces on 1.148.0 (661626d), Ubuntu 25.10, local window, bundled SDK 0.3.304. The early return is now at
claudeSdkMessageRouter.ts:82.Repro (my prompt was in Spanish, hence "lanzado" and "hecho" below): "Launch a background subagent (with
run_in_background) that runssleep 20and then replies "hecho" (done). Don't wait for it: end your turn right away saying "lanzado" (launched). When the subagent finishes, tell me in one sentence what it replied." The turn ends with "lanzado". The subagent's box never appears, and the reply when it finishes is never shown.What the router dropped (Nov 26, one chat):
assistantfrom the subagent (parent_tool_use_id= the Agent call),tool_use: Bashsystem/task_progress,system/task_startedsystem/task_notificationtool_resultand its finalassistanttext ("hecho")system/task_updated,system/task_notification,system/background_tasks_changedsystem/init,system/statusof the turn the CLI starts on its ownassistantreply ("The subagent has finished and replied «hecho».")resultsuccess/end_turn, withorigin: {kind: "task-notification", producer: "session-task"}About #348923: it maps only
type: 'system'messages when there's no turn. In this capture that would complete the subagent's box, but the subagent's own messages (its tool calls and final text) and the CLI's whole turn (reply andresult) would still be dropped.A direction that works for me. The agent host already supports provider-started turns (
ChatTurnStartedfrom the provider,AgentSideEffects._trackProviderStartedTurn,agentSideEffects.ts:940), and the protocol hasMessageKind.SystemNotification, which the Copilot session already uses. I've been running this at runtime since yesterday, wrappingClaudeSdkMessageRouter.handle:task_*system messages, go through the last turn of the chat, so the subagent's box appears, shows its progress and completes.assistant/user/stream_eventarrives with no turn, it fireschat/turnStartedwith a new turn id andmessage: {text: "Background task completed: <summary>", origin: {kind: "systemNotification"}}, routes the CLI's turn through it, and completes it on itsresult(or when a real user turn starts).With it, the repro shows the subagent and then a Background task completed turn with Claude's reply. The agent host logged it 3 times on the first day. Known gap: a message the user sends while that CLI-started turn is running can still be lost.