Repository navigation
Do not present a failed tool call as a successful one - #330707
Connor Peet (connor4312) merged 3 commits into
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Kyle Cutler (@kycutler)Matched files:
Joaquín Ruales (@jruales)Matched files:
|
There was a problem hiding this comment.
Pull request overview
Prevents failed browser tool calls from being presented as successful.
Changes:
- Clears optimistic completion messages when tools fail.
- Propagates Playwright execution errors as tool failures.
- Adds regression coverage for completion messages.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
chatModel.test.ts |
Tests failed and successful message handling. |
chatToolInvocation.ts |
Removes optimistic labels after failures. |
browserToolHelpers.ts |
Propagates execution errors to tool results. |
Suppressed comments (2)
src/vs/workbench/contrib/browserView/electron-browser/tools/browserToolHelpers.ts:186
erroris optional, so presence—not truthiness—indicates that execution threw. The service can produce an empty string fromnew Error()orthrow ''; this spread is then omitted and the tool is still reported as successful. Preserve the failure signal with a truthy fallback for an empty error message.
...(result.error ? { toolResultError: result.error } : {}),
src/vs/workbench/contrib/browserView/electron-browser/tools/browserToolHelpers.ts:186
- This second regression fix is not exercised by the added test: that test covers only
ChatToolInvocation, while no browser-view test verifies this conversion. Add a focused test showing that a result witherrorproduces a truthytoolResultErrorand that a successful result does not, so the model-facing success state cannot regress independently.
...(result.error ? { toolResultError: result.error } : {}),
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Two ways a failed browser tool still read as success. `ChatToolInvocation.didExecuteTool` only replaced the past-tense message when the result carried one of its own, so a tool that failed kept the message prepared before it ran. A screenshot that failed with "No browser page found" still rendered as "Captured browser screenshot". Drop the prepared message on failure and let the error stand on its own. `invokeFunctionResultToToolResult` recorded an evaluated-code error only in `toolResultDetails.isError`, so the tool call itself was still reported as successful. Set `toolResultError` as well.
Review feedback: the codebase sets a past-tense message for a failed tool call rather than clearing it — the codex mapper does it per result, and the agent host does it for client tool calls that outlive their client. Doing it in ChatToolInvocation changed the past-tense behavior of every tool that reports an error in order to fix browser ones. The browser helpers now supply the failure label alongside the error, so the shared model is untouched. These tools declare only an invocationMessage and no pastTenseMessage, which is why a failed call reused the present-tense one and read as a success. The error check is on presence rather than truthiness, so an empty message from `throw ''` or `new Error()` still reports a failure. Coverage moves to browserToolHelpers, which nothing exercised before.
21c89e5 to
c517c08
Compare
|
Agreed, and reworked that way — the It isn't only codex, either: the agent host does the same thing for client tool calls that outlive their client, a few lines from where it builds the "you may try calling the tool again" text — The browser helpers now supply the label with the error: ...(result.error !== undefined ? { toolResultError: result.error || failedMessage, toolResultMessage: failedMessage } : {}),Reworking it also made the root cause clearer than my original description. These tools declare only an That also settles the suppressed Copilot comment about an empty error message: the check is on presence rather than truthiness now, so Coverage moved with the behavior. The One thing I left deliberately generic: the label is a single localized "Browser action failed" rather than per-tool text, because Rebased on current AI disclosure: this comment and the related code were written with the assistance of AI. |
|
Both right, and the second one corrects something I asserted wrongly in the description. Fixed in this PR rather than a follow-up — it is a hole I introduced, and the PR has not merged yet.
The Worth noting that also makes the original AI disclosure: this comment was written with the assistance of AI. |
Please tell your AI the PR is merged :-) |
His name is Claude and he's a swell fellow :) AI disclosure: this comment was written with the assistance of AI. |
Observed with the integrated browser tools: a screenshot that failed with
No browser page found with ID ...rendered in chat as "Captured browser screenshot". The agent host had the correct state the whole time (success: false,pastTenseMessage: "screenshotPage failed"); only the presented message was wrong.Two independent causes, both small:
1.
ChatToolInvocation.didExecuteToolkept the optimistic label. It replacedpastTenseMessageonly when the result supplied one of its own, so a failing tool fell through and kept the message prepared before it ran, which states what the tool would have done. Now dropped on failure so the error stands on its own.2.
invokeFunctionResultToToolResultreported an errored run as a success. An error from the evaluated Playwright code was recorded only intoolResultDetails.isError, never astoolResultError, so the tool call itself came back successful. Now setstoolResultErrortoo.The second one matters beyond the UI: the model is told the call succeeded.
Testing
a failed tool drops the past-tense message prepared before it ran; a successful one keeps it, which pins both directions so this cannot be over-corrected into dropping the message on success.ChatModel135 passing,ChatResponseModel8,ChatListRenderer41,stateToProgress130,ToolInvocation104. No failures.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.