Repository navigation
Proposal: execute a client tool on the runtime's invocation - #330933
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
Moves Claude client-tool execution from streamed readiness to runtime invocation signals, preventing duplicate, premature, and argument-less execution.
Changes:
- Adds invocation-driven execution capability and routing.
- Forwards authoritative tool arguments from Claude’s MCP handler.
- Adds tests for signaling, replay, and execution ordering.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
common/agent.ts |
Defines the invocation signal and provider capability. |
node/agentSideEffects.ts |
Gates and synthesizes client-tool execution. |
node/claude/claudeAgent.ts |
Enables invocation-driven execution for Claude. |
node/claude/claudeAgentSession.ts |
Emits invocation signals and awaits results. |
node/claude/claudeSdkOptions.ts |
Wires the invocation callback into MCP setup. |
node/claude/clientTools/claudeClientToolMcpServer.ts |
Forwards tool names and arguments. |
test/node/agentSideEffects.test.ts |
Tests replay and invocation ordering. |
test/node/claudeAgent.test.ts |
Tests Claude invocation signaling. |
test/node/clientTools/claudeClientToolMcpServer.test.ts |
Tests MCP argument forwarding. |
test/node/mockAgent.ts |
Adds configurable invocation capability. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
fc7452f to
deda8ce
Compare
|
Two of the three hold and are fixed in #330746, since that is where the lines live; this PR is rebased on it. Subagent routing. Correct, and it would have been a hang rather than a cosmetic issue: with the gate on, the real subagent call never receives an execution request. The signal now resolves the parent spawn the same way the permission path does, via Unownable call wedging the turn. Also correct. The MCP handler is already parked when the signal fires, so returning after the log left the runtime awaiting forever. The call is now completed as a failure both in protocol state and to the provider, so the turn unwinds with an attributable error instead of hanging.
5299 agent host tests pass, with the same 3 failures present on Still very much a proposal, and still easy to decline: the latency question in #330899 is the part I cannot answer from outside. AI disclosure: this comment was written with the assistance of AI. |
|
A field note from running an approximation of this against a live dev container for a day, in case it is useful evidence for the design. I patched a local build to gate client-tool execution on the runtime invocation, as this PR does, but took a shortcut: my version resynced using a turn id stashed on the session when a message was sent, rather than carrying the turn id with the invocation. That shortcut broke, and the failure is worth knowing about. Client tool calls issued inside a steering turn were stranded permanently — readied, never executed, and the turn never completed. Three cases in one session, all of them in steering-promoted turns, none in ordinary turns. The reason is that a promoted steering turn is not created through the ordinary send path, so the stashed id still pointed at the preempted turn; the resync then asked for a request under the wrong turn, matched nothing, and no execution was ever requested. Nothing was logged, because the resync path had no logging. This PR does not have that problem: Fixing my version to record each call's own turn id at the point it streams resolved it, confirmed on live traffic: the diagnostic showed the two ids genuinely differing ( AI disclosure: this comment was written with the assistance of AI. |
ddbcb43 to
70593f3
Compare
70593f3 to
f8ce489
Compare
|
Housekeeping on the review threads above, since the branch was squashed after they were written. #330746 was closed rather than merged and its changes are folded into this PR's single commit, so
One correction to my earlier comment: the AI disclosure: this comment and the related code were written with the assistance of AI. |
|
Superseded by #334146, which I am closing this in favour of. The proposal was right about the shape of the problem and its signal, and #334146 keeps that: the same It could not be rebased. Its base #330746 was closed, and the publish point it patches has since moved out of Three things changed in the reimplementation, each for a reason worth recording. Admission is stamped into the tool call's protocol meta rather than living only in a process-local set, so it survives a client reconnect. The ownerless failure is dispatched as a server action and left to the existing envelope listener, because the explicit forward this proposal added would deliver it twice on current main. And the input is always repaired from the runtime's arguments rather than only when the streamed input looks empty, since the runtime's are authoritative. AI disclosure: this comment and the related investigation were written with the assistance of AI. |
Proposal, and easy to decline. #330899 asks whether the stream-mapper ready is meant to be actionable. This is what the alternative looks like, offered so the option is concrete rather than hypothetical. If the current ordering is deliberate, closing this costs nothing and the three symptom PRs still stand on their own.
Stacked on #330746, which introduces the
client_tool_invokedsignal this builds on.The seam
A client tool is executed when its streamed tool call reaches
Running(agentSideEffects.ts:566-575), in parallel with the runtime invoking the same tool through its in-process MCP server. The MCP handler discards its arguments and parks, so the streamed ready is the active trigger and the invocation is a passive await.Three defects follow from that one trigger:
{}toolInputThe change
A provider may declare
drivesClientToolExecution, meaning its runtime reports every client tool invocation. For those providers the host admits a call to execution only once the invocation arrives, rather than on the streamed ready. Claude opts in, since its in-process MCP server sees every call the SDK makes. Providers with no such signal are untouched, so Copilot and Codex keep executing onRunning.Because the invocation carries the runtime's own arguments, a streamed call that arrived without input is repaired from them before it runs.
All three defects then become structurally impossible for Claude rather than individually patched: one trigger instead of two, real arguments instead of
{}, andregisterAndFireordering registration before execution.What this costs
Execution starts at the SDK round trip rather than when the arguments finish streaming. If that latency is the reason the ready is actionable today, this is the wrong trade and I would rather know than guess. That is the question in #330899.
Verification
New test: with a provider that announces invocations, a streamed ready produces no execution request and the invocation does. 5298 agent host tests pass; the 3 failures are present on
mainunchanged.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.