vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Agents Window: agent host respawns the harness mid-session; two processes resume the same session ('agentHostManagement' timed out after 1000ms)

Open TaffarelJr opened this issue 3 weeks ago • 4 comments

Does this issue occur when all extensions are disabled?: No. The Agents Window needs an agent harness extension; this happens with Claude Code (anthropic.claude-code 2.1.322).

  • VS Code Version: 1.146.0 (69047191fc427f2f92828279aae1d90d8eeda7ab)
  • OS Version: Windows 11 Enterprise 10.0.26200

Summary

In the Agents Window, the agent host respawns the harness for a chat session while the old one is still alive. Both processes then resume the same session at once. Each time, a Channel name 'agentHostManagement' timed out after 1000ms toast may appear. It has happened for about two weeks, across several VS Code updates.

Evidence

Two harness processes are resuming the same session right now. Both are children of Code.exe --type=utility --utility-sub-type=node.mojom.NodeService, and both have identical command lines (--resume <same session id> --input-format ... --permission-prompt-tool ...):

PID Started (local) Session
69384 14:34:17 A
55664 14:34:18 A
29384 14:02:14 B (a different session, not involved)

In one session today, the harness's own state recorded:

  • at least 3 respawns, recorded by the harness as "didn't finish before the previous session ended". The last came while this report was being written;
  • about 24 switches of the session's folder between c:\... and C:\..., the same folder spelled two ways;
  • a respawn that started during a running turn. The old process finished its turn and wrote its reply to the session, but the UI never showed it. The chat looked frozen for an hour;
  • 5 permission prompts recorded as "the user declined". The user saw no prompt.

Effect on users

  • Messages sent go to the replaced process and are never answered.
  • Replies never appear in the chat.
  • Two processes edit the same files and undo each other's changes.

Steps to reproduce

Not yet reliable. The toast and the respawns are most frequent when a single tool call runs for more than about a minute. Trace logs will be added at the next occurrence: the log folder for this VS Code session was empty.

Expected

One harness process per session, and none respawned while the old one is alive. If a respawn is unavoidable, the old process should be stopped first and its pending output kept.

Related, on the harness side: anthropics/claude-code#105697 (messages missing from the transcript and UI).

TaffarelJr avatar Nov 12 '26 21:11 TaffarelJr

One more fact from the same session, an hour later.

Both processes in the table were started by one message. A user message sent at 21:34 UTC started PIDs 69384 and 55664 one second apart, both resuming session A. 69384 took that message and finished its turn, then exited. 55664 received the next message with no record of that turn in its own context; the turn is only in the session's stored history. While this happened, the chat showed only Thinking.

Trace logs will follow at the next occurrence.

TaffarelJr avatar Nov 12 '26 21:11 TaffarelJr

Trace logs from a stall, with Log Level: Trace set after a restart. The same session was stuck on Thinking with no reply for two hours, although the harness finished the turn: its tool calls and its reply are in the session's stored history.

agenthost.log when the message was sent (session ID redacted):

19:12:18.517 [trace] [AgentService] dispatchAction: type=chat/turnStarted
19:12:19.027 [info]  [Claude] session <id>: rebuild isResume=true agent=(none)
19:12:19.514 [error] [ClaudeSdkPipeline:<id>] _processMessages crashed: Error: Claude SDK stream ended without a result message
19:12:19.945 [info]  [Claude] session <id>: rebuild isResume=true agent=(none)

For the next two minutes, while the harness ran the turn, the host mapped six SDK messages for the session, all system and command_lifecycle. It relayed no assistant, user, stream_event or result message, and never completed the turn.

The same session, on two later messages after the same restart:

Message Host log Reply shown
The stalled one above rebuild, crash, rebuild No
Two hours later rebuild, rebuild, no crash Yes
Three hours after that crash, rebuild, rebuild Yes

So the session is rebuilt twice for every message. The stall is the one case where the crash came between the two rebuilds. The output then appears to go to a pipeline the window no longer reads.

I can share the full log folder privately if a maintainer needs it.

TaffarelJr avatar Nov 13 '26 07:11 TaffarelJr

Seen on macOS (Apple silicon, macOS 26.7.1) on VS Code 1.145.0 (a717861c0758…), so this predates 1.146.0, as the description says.

Two claude processes resumed the same session, started two seconds apart. They match the two rebuild isResume=true lines in agenthost.log:

11:45:58.997 [info]  [Claude] session dc1d8834…: rebuild isResume=true agent=(none)
11:45:59.572 [error] [ClaudeSdkPipeline:dc1d8834…] _processMessages crashed: Error: Claude SDK stream ended without a result message
11:46:00.415 [info]  [Claude] session dc1d8834…: rebuild isResume=true agent=(none)
PID 79922  started 11:45:58  --resume=dc1d8834…
PID 79992  started 11:46:00  --resume=dc1d8834…

Both were still running when I checked afterwards. A second double rebuild at 12:40:19–12:40:20 left one process (PID 15102).

After the second one, the next user message went to a process with no record of the previous exchange. The transcript shows the 12:44:09 user message has the same parentUuid as the 12:40:22 message, and the 12:40 exchange (22 records) is not in its ancestry. The assistant said it didn't have that exchange in context. This matches TaffarelJr's comment ("no record of that turn in its own context"). It happened once here, on 1.145.0, where the reply itself was shown.

I investigated this with an AI coding agent (Claude Code), which read my local agenthost.log and Claude transcripts. Session IDs are shortened.

jay-lu-simplisafe avatar Nov 13 '26 18:11 jay-lu-simplisafe

Thanks for the logs. I can reproduce the crash in your log on Insiders 1.147.0 (944d79c), macOS, with a Claude session:

  1. Start a Claude session and send a message that runs a tool (sleep 20).
  2. Run Restart Local Agent Host.
  3. Send a message. It resumes the session and answers.
  4. Send another message. agenthost.log shows:
14:08:17.729 [info]  [Claude] session …: rebinding before turn request_… for changed client customizations
14:08:17.738 [info]  [Claude] session …: rebuild isResume=true agent=(none)
14:08:17.796 [error] [ClaudeSdkPipeline:…] _processMessages crashed: Error: Claude SDK stream ended without a result message

In my runs that turn still completed, and the session kept its context for the next four messages. So I got the rebuild and the crash, but not the second rebuild or the lost reply.

From the code (claudeSdkPipeline.ts): _rebindQuery shuts down the old query's stream before the new query is bound. The old consumer loop then sees its stream end while it still owns _query, so the swap guard in _processMessages doesn't apply. It logs the crash, fails the queued turns and sets _needsRebind, and the next send rebuilds again. That fits the "rebuild, crash, rebuild" sequence and the stuck turn in your logs.

https://github.com/user-attachments/assets/22196f94-849a-44b1-b428-c4fcf9483ddf

🤖 Authored with GitHub Copilot on behalf of @alexdima.

alexdima avatar Nov 27 '26 07:11 alexdima