Agent Host client tool hangs after active client removal; browser click invoked with empty args
Summary
A browser clickElement tool call can get stuck in Preparing after the Agent Host removes the active client. The click never reaches Playwright; the workbench invokes the browser tool with {} parameters and crashes during tool preparation.
Observed
In an Agents/Copilot CLI session using built-in browser tools:
openBrowserPagesucceeds.clickElementon the initialStartbutton succeeds.screenshotPagesucceeds.- The next
clickElementon the board'sRunbutton stays stuck atPreparing.
The session event stream ends with:
tool.execution_start clickElement
permission.requested clickElement
# no permission.completed
# no tool.execution_complete
Key log evidence
The model requested valid arguments:
{
"element": "Run button on Research Agent",
"pageId": "<page-id>",
"ref": "e200"
}
But the workbench invoked the underlying browser tool with empty parameters:
[AgentHost] Invoking client tool: clickElement
[LanguageModelToolsService#invokeTool] Invoking tool click_element with parameters {}
[error] Cannot read properties of undefined (reading 'toString')
at createBrowserPageLink(...)
at ClickBrowserTool.prepareToolInvocation(...)
The AHP sequence for the same tool call was:
chat/toolCallStart clickElement
chat/toolCallReady confirmed="not-needed" # no toolInput
chat/toolCallComplete success=false error="Client <client-id> disconnected before completing clickElement"
chat/toolCallReady confirmation UI with real toolInput
About 6 seconds earlier, the same session received:
session/activeClientRemoved clientId=<client-id>
Suspected cause
This looks like an Agent Host/client-tool lifecycle race:
- The active client is removed from session state while the UI/client connection is still participating in the turn.
- A later client-contributed browser tool call is treated as orphaned/disconnected.
- The synthetic
toolCallReadywithouttoolInputis consumed by the workbench client-tool handler. - The handler falls back to
{}and invokesclick_elementbefore the latertoolCallReadycontaining the realtoolInputarrives. ClickBrowserTool.prepareToolInvocationassumespageIdis present, callscreateBrowserPageLink(undefined), throws, and the original Copilot tool execution remains stuck waiting for completion/permission state.
Relevant code paths:
src/vs/platform/agentHost/node/protocolServerHandler.ts- disconnected client tool call handling emits synthetic ready/complete events
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts- missing
toolInputfalls back to{}once status is notStreaming
- missing
src/vs/workbench/contrib/browserView/electron-browser/tools/clickBrowserTool.tsprepareToolInvocationassumespageIdis defined
Expected
A disconnected/orphaned client-tool call should fail cleanly and unblock the model/UI, or be retried with a replacement active client. It should not invoke the local browser tool with {} parameters or leave the tool call stuck in Preparing.
Possible fixes
- Do not invoke client tools from
toolCallReadyevents that lacktoolInputwhen the tool has required arguments or_meta.toolArgumentsexists. - Ensure disconnected-client synthetic
toolCallReady/toolCallCompleteordering cannot race with later confirmation UI events for the same tool call. - Harden browser tool
prepareToolInvocationagainst missingpageIdso malformed protocol state becomes a clean tool error. - Investigate why
session/activeClientRemovedfired while the client was still successfully confirming/completing tool calls in the same session.
Seeing this too, and I think I can add one useful data point: for me it only happens in remote windows. The same repo, same client, same request works in a local window and hangs in both WSL Remote and Dev Containers.
| Window | Result |
|---|---|
| Local Windows folder | works |
| WSL Remote | hangs |
| Dev Container (compose) | hangs |
Environment: VS Code 1.133.0 stable and Insiders (both affected), Windows arm64 client, WSL2 Ubuntu, Docker Desktop. Copilot Chat with the Claude harness. The Anthropic Claude Code extension is not installed, so this reproduces with no third-party chat extension involved.
Symptom matches the report: the first browser tool call succeeds, then the turn never completes. In my case there is no error at all, the agent host log simply stops:
[AgentSideEffects] Forwarding client tool completion: source=server-envelope, session=claude:/<id>
[AgentSideEffects] Forwarding client tool completion: source=client-dispatch, session=claude:/<id>
(nothing further - no error, no timeout)
Consistent with the activeClientRemoved lifecycle race in the report, I also see client/session state desync in the same sessions:
[AgentHostStateManager] Action for unknown session: claude:/<id>, type=session/metaChanged
[AgentSideEffects] sendMessage failed for session=ahp-chat://default/<b64>: code=undefined, message=Canceled: Canceled, type=Canceled
Two sessions get created seconds apart and the older one is then unknown to the agent host.
Possibly related, and remote-specific: every session in a remote window logs a pair of file-watcher failures on the workspace URI, which never occur locally:
CodeExpectedError: ENOPRO: No file system provider found for resource
'vscode-remote://dev-container%2B<hex>/workspace/<repo>'
at Ms.withProvider (.../agentHostMain.js)
at async Ms.doWatch (.../agentHostMain.js)
The same URI also fails for <workspace>/.claude. In the same remote windows, chat session history never lists, which may be the same root cause and looks like #328736.
Ruled out by experiment, in case it saves anyone time:
- MCP servers: rebuilt with zero MCP servers registered (verified in the MCP Servers view) and it still hangs.
- File checkpointing: setting
fileCheckpointingEnabled: falsedid not help and made it hang earlier. - Auth/models: healthy throughout,
[Claude] Models refreshed (merged). Count: 4. - Agent SDK download: cache warm, no download during the failing turns.
Happy to gather more logs or run a specific build if that helps.
Root cause found, with a reliable reproduction rule and instrumented evidence. Correcting the "suspected cause" in the original report: the active-client removal is incidental, not the trigger.
Reproduction rule
With a client-contributed tool (the built-in browser tools), in a dev container (remote) window:
| Permission path | Result |
|---|---|
| Approved inline in the chat | works, turn continues |
| Approved in the confirm dialog | stalls |
Auto-approved (auto mode / not-needed) |
stalls |
The confirm dialog involves the same human delay as the inline prompt and still stalls, so this is not a timing race. What matters is which side owns the call.
Mechanism
A client tool call produces two chat/toolCallReady events: one from the stream mapper at content_block_stop, and one from the SDK permission flow (carries confirmationTitle).
When permission is requested inline, the SDK has genuinely invoked the tool, so its in-process MCP handler is registered and waiting. The result is delivered and the turn continues.
When no permission is requested, only the stream-mapper ready exists. The workbench executes the tool anyway and reports chat/toolCallComplete, but the SDK never invoked it, so nothing is waiting for the result. ClaudeAgentSession.completeClientToolCall calls PendingRequestRegistry.respond, which drops a result with no registered entry, and the turn waits forever for a call the model's runtime never made.
Evidence
Probe on completeClientToolCall, logging whether the id matched a registered handler, alongside every id passed to register():
STALLED id=toolu_01EQdcdF... matched=false
registered=["toolu_01UUfx...","toolu_0161bL...","toolu_011Pmh..."]
(the id is absent, and never appears in any later line)
WORKED id=toolu_015SZeT... matched=true
registered=[...,"toolu_015SZeTNzfwyZtXqcYGe8NTd"]
The stalled id is never registered, before or after. Confirmed across many runs: matched=true implies the turn continues, matched=false (for a client tool result) implies it parks.
AHP sequences for the two cases:
WORKED toolCallReady confirmationTitle=yes -> inputNeededSet -> confirmed=user-action -> complete (matched)
STALLED toolCallReady confirmationTitle=no -> confirmed=not-needed -> complete (dropped)
Ruled out by experiment
- Empty tool-result content. Real and worth fixing separately (the workbench sends
{success:false, error:{message}}with nocontent, andconvertToolCallResultreads onlycontent, so the model receives an empty result, see microsoft/vscode#330709), but patching it did not affect the stall. - Buffering the result (
respondOrBufferinstead ofrespond). Cannot help, because_earlyResultsis only collected byregister(), which is never called for the stalled id. - Active client removal. Appears in only one of the stalled runs.
- Duplicate client tool invocation (microsoft/vscode#330683). Fixed separately and verified; the stall reproduces with exactly one invocation.
Why remote-specific
On a local window the same client tools work. The stall needs the workbench to execute off the stream-mapper ready without an SDK invocation, which is far more likely when the client tool round trip crosses the websocket transport used by a remote window.
Suggested direction
A client-contributed tool should not execute until the agent host has a pending invocation for that tool call. The stream-mapper ready is enough to render the call, but not to run it.
Correction to my previous comment, and a fix: microsoft/vscode#330730.
I claimed the SDK "has no record of the call at all" and that the workbench executes a tool the SDK never invokes. That was wrong. The SDK does invoke the tool and register its handler, just after the workbench has already finished the tool and reported the result.
The instrumentation that showed this: logging every id passed to PendingRequestRegistry.register alongside each completion.
stalled id=toolu_01EQdcdF... matched=false registered=[...]
(the id is absent when the result arrives, and present seconds later)
So the sequence is:
- The workbench starts the client tool from the streamed tool call (
content_block_stopready) and finishes it in milliseconds. ClaudeAgentSession.completeClientToolCallcallsrespond, which drops a result nothing is parked on.- The SDK invokes the tool and registers its handler moments later.
- That handler waits forever for a result that was already discarded.
CopilotAgentSession already uses respondOrBuffer on the same path, so it survives the same ordering. The fix brings Claude in line.
This also explains the permission split reported above without needing a separate mechanism: auto-approval leaves nothing to delay the workbench so it always loses the race, while approving inline in the chat usually gives the SDK enough time to register first.
Two things in my earlier comments that remain correct: the active client removal is incidental, and the empty tool-result content is a real but separate defect (microsoft/vscode#330709).
Verified live on 1.133.0 with the change patched into a running agent host: auto mode recovered from a failed browser tool, reported the cause, and completed the turn.
Reproduces in a local macOS window (not remote-only), with an instrumented timeline.
Environment: VS Code 1.139.0 stable, macOS 26.6 arm64, local folder window — no Remote, no WSL, no Dev Container. Claude harness in an agent session. Single VS Code window, brand-new chat, so no "on another client" prompt was involved. We have been seeing this since ~1.135.
This contradicts the "local window works" row of the table above.
Agent Host log at trace, one tool call, one tool_use_id:
22:10:12.412 content_block_start tool_use name=mcp__client__openBrowserPage id=toolu_01YbTX…
22:10:12.776 chat/toolCallReady
22:10:12.796 chat/toolCallConfirmed approved=true (+20 ms, auto-approved, no human)
22:10:13.226 chat/toolCallComplete result={"success":true,…"Page ID: 8667a8f7…",
"Page Title: MEF-Analysis","URL: http://localhost:5175/"}
22:10:13.226 [AgentSideEffects] Forwarding client tool completion:
source=client-dispatch, toolCallId=toolu_01YbTX…, success=true
── 29 s of nothing ──
22:10:42.632 SDK message type=user: tool_result
"MCP error -32001: AbortError: interrupt" tool_use_id=toolu_01YbTX…
The successful result existed 814 ms after the tool call started and was forwarded; the SDK still had nothing 29 s later, and the only completion the call ever produced from the SDK's point of view came from me hitting stop. The AbortError is the effect of the interrupt, not the cause. Note chat and completionChat are identical, so no cross-client attribution is involved here — this is purely the drop described in #330730.
One observation I cannot fully account for: in earlier attempts in the same session under "Ask Before Edits", no client-dispatch forwarding line appears at all, even though that line is logged at info. Auto-approved calls forward a result nobody is parked on; dialog-approved calls appear not to forward one at all. That may be two distinct drop points.
Also worth noting for the permission-path table: VS Code never prompts for read-only client tools such as readPage, even in "Ask Before Edits" mode. So the only row that works — "approved inline in the chat" — is not reachable by the user for those tools. There is no user-side workaround.
Happy to re-test on macOS once #330730 is rebased (it is currently in merge conflict).
Still reproduces on 1.141.0 stable (2a59476c9bfcb90b3ddc372c36762471b7dfad1c); the Claude completeClientToolCall is byte-identical in the pending 1.141.1 build. Windows client + WSL2 remote window, Claude harness, auto-approved client tools (openBrowserPage, readPage, screenshotPage).
#330730 was closed unmerged on 2026-10-03, and main still has:
// src/vs/platform/agentHost/node/claude/claudeAgentSession.ts
completeClientToolCall(toolCallId: string, result: ToolCallResult): boolean {
const converted = convertToolCallResult(result, toolCallId);
return this._pendingClientToolCalls.respond(toolCallId, converted);
}
so as far as I can tell no fix for this is currently in flight.
Timeline for one stalled readPage (UTC, AHP log + agenthost.log):
09:04:07.18 chat/toolCallStart readPage (contributor kind=client)
09:04:07.54 chat/toolCallReady confirmed=not-needed
chat/toolCallConfirmed approved=true (permissionDecisionSource=host_policy)
09:04:07.618 chat/toolCallComplete success=true, full page snapshot (client dispatchAction)
09:04:07.619 [AgentSideEffects] Forwarding client tool completion: source=client-dispatch, success=true
-- nothing for ~87 s --
09:05:34.229 completion forwarded again with success=false, only because I sent a new message (steering)
The workbench had the correct result ~75 ms after the call was ready; the SDK never received it. Same pattern for openBrowserPage and screenshotPage in the same session, and the occasional call that wins the race works, which matches the register-after-complete analysis above. Ruled out on this machine: WSL networking (NAT, localhost forwarding fine both ways), browser tab visibility/overlays, page sharing.
CopilotAgentSession and the Codex path already use respondOrBuffer here, and PendingRequestRegistry.register() already collects _earlyResults, so the minimal change from #330730 (respond -> respondOrBuffer in completeClientToolCall) looks sufficient for this stall. Is a reduced version of that PR acceptable, or is a different fix planned?
Investigated and written with the help of an AI coding agent.
@guihss-atos I closed all my PRs as I had tens of them, and no one was acknowledging the issues let alone the fixes. I've since left vscode entirely as their chat tools are just too broken for me to use outside of their own sub.
I agree with Ryan: the Agents window is very pleasant to use, regarding the overall user experience. BUT, it's also very buggy, at least using the Claude harness. I live with 4-5 culprits every day (#322990, #332073, #337653, #335378, #333799), and it seems that it's not a priority for MS team to fix them.
Even a simple task like an update of the agent-sdk seems to be very tough: the SDK embedded in VS Code is 18 builds behind Anthropic's, as of today.
I strongly DON'T recommend my colleagues to use the Agents window: the Claude extension is far more stable than this.
+1 to the one-line respond → respondOrBuffer change, as @guihss-atos suggests.
15. I agree with Ryan: the Agents window is very pleasant to use, regarding the overall user experience. BUT, it's also very buggy, at least using the Claude harness. I live with 4-5 culprits every day, and it seems that it's not a priority for MS team to fix them. Even a simple task like an update of the agent-sdk seems to be very tough: the SDK embedded in VS Code is 18 builds behind Anthoropic's, as of today. I strongly DON'T recommend my colleagues to use the Agents window: the Claude extension is far more stable than this.
Adding to this is that the chat tools are somehow even more broken in the editor view than in the agents view. I am not sure why they behave so differently between those modes, either. There's definitely preferential treatment towards Codex over Claude as well, but it's still very broken with Codex. WSL adds a whole other layer to the issues as they seem to have forgotten to account for their remote plugins and how paths are different when working on remotes.
I've switched to Paseo and am much happier.
Still reproduces on 1.148.0 (661626d0e72f97806550790a98fb87116c9db825), Ubuntu 25.10, local window, Claude agent host with the bundled SDK 0.3.304. completeClientToolCall is unchanged (claudeAgentSession.ts:1448-1451, still respond).
Disclosure: I investigated this with an AI coding agent (Claude Code), attached to the agent host's inspector with breakpoints on
completeClientToolCalland on the client tool MCP handler. No VS Code files were modified.
Deterministic repro. The race depends on whether the CLI reaches the tool's handler before the workbench finishes it, which is why it looks intermittent. A slower tool in the same message makes it lose every time. In Bypass mode, send in one message: "In parallel, in a single message: run sleep 8 && echo done in the terminal, and call the problems tool." The CLI runs the terminal command first and only then calls the problems handler, 8 s after the workbench has finished it.
Capture (Nov 26):
| Time | Event |
|---|---|
| 15:02:38.708 | completeClientToolCall(toolu_01DrcR…) (problems): nothing parked under that id → dropped |
| 15:02:46.644 | The terminal command completes |
| 15:02:47.027 | The client tool MCP handler for problems starts waiting for toolu_01DrcR…, 8.3 s after its result was dropped. It waits until the turn is stopped |
Workaround tested. I've been running the respond → respondOrBuffer change since yesterday, applied at runtime through the inspector. The repro completes every time, and in a day and a half it delivered an early result 6 times, in the repro and in normal work. One thing I had to handle: AgentSideEffects forwards every ChatToolCallComplete, including the CLI's own tools (Bash, Read…), so respondOrBuffer also buffers results nobody will ever ask for. In my workaround they expire after 30 minutes; buffering only ids of client tool calls would avoid it.
In any permission mode other than Bypass this fix isn't enough. The workbench also confirms the client tool before the CLI asks for permission, and that answer is dropped the same way (respondToPermissionRequest → respond), so the turn hangs at the permission gate before it ever reaches the handler. That may be the second drop point @mmontagnana suspected above. Details, capture and a fix in #350630.