Repository navigation
Description
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
RyanEwen commentedon Aug 13, 2026
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.
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:
Consistent with the
activeClientRemovedlifecycle race in the report, I also see client/session state desync in the same sessions: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:
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:
fileCheckpointingEnabled: falsedid not help and made it hang earlier.[Claude] Models refreshed (merged). Count: 4.Happy to gather more logs or run a specific build if that helps.
RyanEwen commentedon Aug 13, 2026
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:
not-needed)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/toolCallReadyevents: one from the stream mapper atcontent_block_stop, and one from the SDK permission flow (carriesconfirmationTitle).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.completeClientToolCallcallsPendingRequestRegistry.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 toregister():The stalled id is never registered, before or after. Confirmed across many runs:
matched=trueimplies the turn continues,matched=false(for a client tool result) implies it parks.AHP sequences for the two cases:
Ruled out by experiment
{success:false, error:{message}}with nocontent, andconvertToolCallResultreads onlycontent, so the model receives an empty result, see Surface a client tool's error when it returns no content #330709), but patching it did not affect the stall.respondOrBufferinstead ofrespond). Cannot help, because_earlyResultsis only collected byregister(), which is never called for the stalled id.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.
RyanEwen commentedon Aug 13, 2026
Correction to my previous comment, and a fix: #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.registeralongside each completion.So the sequence is:
content_block_stopready) and finishes it in milliseconds.ClaudeAgentSession.completeClientToolCallcallsrespond, which drops a result nothing is parked on.CopilotAgentSessionalready usesrespondOrBufferon 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 (#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.
mmontagnana commentedon Sep 23, 2026
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, onetool_use_id: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
AbortErroris the effect of the interrupt, not the cause. NotechatandcompletionChatare 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-dispatchforwarding line appears at all, even though that line is logged atinfo. 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).
guihss-atos commentedon Oct 14, 2026
Still reproduces on 1.141.0 stable (
2a59476c9bfcb90b3ddc372c36762471b7dfad1c); the ClaudecompleteClientToolCallis 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
mainstill has: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):The workbench had the correct result ~75 ms after the call was ready; the SDK never received it. Same pattern for
openBrowserPageandscreenshotPagein 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.CopilotAgentSessionand the Codex path already userespondOrBufferhere, andPendingRequestRegistry.register()already collects_earlyResults, so the minimal change from #330730 (respond->respondOrBufferincompleteClientToolCall) 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.
RyanEwen commentedon Oct 14, 2026
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.
mmontagnana commentedon Oct 14, 2026
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→respondOrBufferchange, as guihss-atos suggests.RyanEwen commentedon Oct 14, 2026
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.
agentHost: recover client tools after silent disconnects (#346681)
agentHost: recover client tools after silent disconnects (#346681)
agentHost: recover client tools after silent disconnects (#346681)
agentHost: recover client tools after silent disconnects (#346681)
GNeras commentedon Nov 27, 2026
Still reproduces on 1.148.0 (661626d), Ubuntu 25.10, local window, Claude agent host with the bundled SDK 0.3.304.
completeClientToolCallis unchanged (claudeAgentSession.ts:1448-1451, stillrespond).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 donein the terminal, and call theproblemstool." The CLI runs the terminal command first and only then calls theproblemshandler, 8 s after the workbench has finished it.Capture (Nov 26):
completeClientToolCall(toolu_01DrcR…)(problems): nothing parked under that id → droppedproblemsstarts waiting fortoolu_01DrcR…, 8.3 s after its result was dropped. It waits until the turn is stoppedWorkaround tested. I've been running the
respond→respondOrBufferchange 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:AgentSideEffectsforwards everyChatToolCallComplete, including the CLI's own tools (Bash, Read…), sorespondOrBufferalso 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 Marco Montagnana (@mmontagnana) suspected above. Details, capture and a fix in #350630.