Repository navigation
Do not run a client tool twice when a tool call is readied twice - #330683
Ryan Ewen (RyanEwen) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Prevents duplicate client-tool execution when concurrent ready actions arrive.
Changes:
- Tracks in-flight client-tool calls synchronously.
- Suppresses execution while the call remains active.
- Clears tracking after execution settles.
Suppressed comments (2)
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts:2333
- This call-wide guard also suppresses legitimate superseding attempts while
resolveToolInputis still pending. The existingsupersedes a hung referenced input read when the request changestest updates the same call from a never-resolving input URI to a second URI; the first attempt adds this key, so the update now returns here and the second input is never read or invoked. Track the active request/attempt and coalesce only duplicate ready variants (for example, equivalent execution payloads ignoring approval metadata) instead of blocking every request sharing the call key.
if (startedClientToolCalls.has(key) || inFlightClientToolCalls.has(key)) {
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts:2356
- Add a regression test for the pre-
markInvocationStartedrace: keep referenced input resolution pending, deliver the two ready variants with different approval metadata, and assert exactly one invocation while preserving a genuine retry after settlement. The existing tests do not exercise this timing window.
inFlightClientToolCalls.add(key);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
@microsoft-github-policy-service agree |
|
Related: these three share a root cause. Noting it so they can be triaged together rather than as three unrelated patches. The workbench executes a client tool off the stream-mapper
If client tools executed only on the SDK-driven invocation, with the stream-mapper ready used for rendering only, all three would be structurally impossible: one authoritative trigger, never without real input, and registration ordered before execution. I have not proposed that as a PR because I do not know whether the stream-mapper ready is deliberately actionable. Starting the tool as soon as its arguments finish streaming, instead of waiting for the SDK round trip, is a plausible latency win, and the permission flow may already depend on the current ordering. That is a call for whoever owns the design. Each of the three fixes a reproducible bug on its own and carries a test that fails without it, so they are safe to land in the meantime. If the structural fix is preferred, #330683 and #330684 can reasonably be closed in its favour; #330730 is worth keeping either way, since buffering a result that arrives before its handler is the same defensive behaviour AI disclosure: this comment was written with the assistance of AI. |
26c3827 to
165fc03
Compare
|
Two findings in the review body were collapsed as suppressed comments, so they never opened threads. Addressing both here. On the guard suppressing legitimate superseding attempts ( The cited scenario is exactly what that first test does: it parks the first attempt on a never-resolving For the record on test hygiene: three earlier runs of mine reported 53 passing against a stale On the missing regression test for the pre- AI disclosure: this comment and the related code were written with the assistance of AI. |
|
Following up on the second suppressed finding, the one asking for a regression test in the pre- Two guards on the execution path judged sameness differently:
Between them the call was stranded. Three-way control, each run with the rest of the suite green:
No confirmation timer fires either, so the call sits unresolved for the life of the session rather than failing visibly. The fix judges staleness by the same signature the coalescing check uses, so an approval-only change no longer invalidates the attempt it declined to replace. The new test pins all three rows above. AI disclosure: this comment and the related code were written with the assistance of AI. |
|
Correcting the attribution in my previous comment, since it could be read as describing a pre-existing upstream defect. It is not. The That makes the original review comment right about this PR specifically: the new call-wide guard did interfere with an attempt it should not have. It was wrong only about which scenario broke. The named test, Both are now covered. AI disclosure: this comment and the related code were written with the assistance of AI. |
9d0bb55 to
731cca6
Compare
|
Superseded by #330933. Running twice is one symptom of there being no single admission point for a client tool: a display signal derived from the stream is used as the dispatch signal. Deduplicating at this layer suppresses the second of two events that should never have been two. #330933 addresses that directly, so this guard becomes redundant. See #333174. AI disclosure: this comment and the related code were written with the assistance of AI. |
Problem
A client tool call can receive two
ChatToolCallReadyactions: one from the permission flow (carrying confirmation options,preApprovedunset) and one from the agent's stream mapper oncontent_block_stop(confirmed: not-needed, pre-approved)._executeClientToolis driven once per ready, so the tool runs twice.The existing
startedClientToolCallsguard cannot prevent this. It is armed frommarkInvocationStarted, which_executeClientToolonly calls after awaitingresolveToolInput, so both readies pass the started check before either arms it. The two requests also differ (only inpreApproved), so theequals(observedRequest, request)check treats the second as a new request rather than a duplicate.Symptom
The turn hangs indefinitely. The tool visibly succeeds and
chat/toolCallCompleteis reported, but only one of the two invocations is tracked, so the turn is never closed and nothing is logged.User-visible variants of the same double dispatch: a browser page opening before the approval prompt is answered, and answering it then opening a second one.
Evidence
Captured by logging a stack at
LanguageModelToolsService#invokeToolin a dev container window:Same call id, same call site, same millisecond, differing only in approval state.
Fix
Arm a separate in-flight set synchronously when execution starts, and clear it when the execution settles. A second ready for a call that is already running is ignored, while genuine retries still work because the set is cleared on completion.
Verification
With the change applied, each tool call is invoked exactly once and turns complete:
Reproduced originally in a compose dev container on Windows (VS Code 1.133.0). Local windows were unaffected.
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.