Repository navigation
Execute a client tool the SDK replays from the transcript - #330746
Ryan Ewen (RyanEwen) wants to merge 1 commit into
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: TylerLeonhardtMatched files:
|
There was a problem hiding this comment.
Pull request overview
Adds recovery for Claude SDK client-tool calls replayed without stream events.
Changes:
- Introduces a
client_tool_invokedsignal carrying replay details. - Synthesizes protocol state and client execution requests for replayed calls.
- Adds coverage across MCP handling, session signaling, and host side effects.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/vs/platform/agentHost/common/agent.ts |
Defines the new invocation signal. |
src/vs/platform/agentHost/node/agentSideEffects.ts |
Synthesizes replayed tool-call execution. |
src/vs/platform/agentHost/node/claude/claudeAgentSession.ts |
Parks invocations and emits signals. |
src/vs/platform/agentHost/node/claude/claudeSdkOptions.ts |
Plumbs the result callback. |
src/vs/platform/agentHost/node/claude/clientTools/claudeClientToolMcpServer.ts |
Forwards tool names and arguments. |
src/vs/platform/agentHost/test/node/agentSideEffects.test.ts |
Tests synthesized execution and deduplication. |
src/vs/platform/agentHost/test/node/claudeAgent.test.ts |
Tests session signaling and completion. |
src/vs/platform/agentHost/test/node/clientTools/claudeClientToolMcpServer.test.ts |
Tests MCP argument forwarding. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
cc Tyler for Claude specifics |
|
Pushed two fixes from review on #330933, both in code this PR introduces. A client tool invoked inside a subagent was announced without its parent, so the signal was handled on the parent chat rather than the subagent one. It now resolves the parent spawn as the permission path does and carries A call whose tool no connected client provides left the runtime parked forever, since the MCP handler is already awaiting when the signal fires. It is now completed as a failure in protocol state and to the provider, so the turn unwinds instead of hanging. AI disclosure: this comment and the related code were written with the assistance of AI. |
|
Two notes from reviewing this alongside #331300, since both decide which client owns a tool call and they no longer agree. Ownership is resolved three ways after these land. The stream stamp in Cosmetic: AI disclosure: this comment was written with the assistance of AI. |
a4a1898 to
2ce84ab
Compare
2ce84ab to
1fe9d0e
Compare
|
Closing in favour of #330933, which supersedes this. Both PRs move client tool execution off the stream-mapper ready and onto the runtime's invocation, and #330933 is the general form: four of the five tests here also exist there, including the replayed-call cases this PR was opened for.
The one test unique to this PR is Both are rebased onto current AI disclosure: this comment and the related code were written with the assistance of AI. |
Companion to #330730; together they close the remaining ways a client tool call wedges a Claude session in a remote window (#322990).
The failure
Cancel a turn while a client tool call is pending and the transcript keeps an assistant
tool_usewith notool_result. On the next message the SDK resumes and replays that call: it invokes the in-process MCP tool directly, without re-streaming the assistant message. The stream mapper — the sole trigger for client-tool execution — sees nothing, so no execution is ever requested. The SDK waits forever, emitting onlytool_progressheartbeats, and the UI sits at "Considering".Worse, the dangling
tool_useis durable: every subsequent resume replays it, so the session is permanently wedged. Observed live on 1.133.0:The fix
The MCP handler already receives everything needed — the tool name, the args, and the
tool_use_id. It now parks viaPendingRequestRegistry.registerAndFire, firing aclient_tool_invokedsignal. The host checks turn state:ChatToolCallStart/ChatToolCallReadypair the stream would have produced, which drives the existingToolClientExecutionrequest path, so the client executes it like any other call.registerAndFirecollects a result buffered before registration without firing, so this composes with #330730's eager-execution buffering rather than re-triggering execution.The synthesis is deliberately host-side (
agentSideEffects), where turn state lives — the reducer appends blindly onChatToolCallStart, so the session cannot safely emit unconditionally.Testing
an SDK client tool invocation fires client_tool_invoked and resolves on completion— session-level, through the real MCP handler wiring.client_tool_invoked synthesizes execution for a replayed call and leaves a streamed one alone— host-level: the replayed call gains aRunningtool call with the owning client's contributor and aToolClientExecutionrequest; a second signal for the same id does not duplicate state.handler forwards the tool name and args to awaitResult— factory-level.npm run typecheck-clientclean.AI disclosure: this description and the code it proposes were written with the assistance of AI.
Public patches and patcher scripts
Source patch and installed-bundle workaround mapping. The public collection includes the maintained patchers, rollback instructions, regression scripts, and historical snapshots. Build restrictions and exact installer coverage are documented there.