Skip to content

Do not present a failed tool call as a successful one - #330707

Merged
Connor Peet (connor4312) merged 3 commits into
microsoft:mainfrom
RyanEwen:fix/browser-tool-failure-reporting
Aug 17, 2026
Merged

Connor Peet (connor4312) merged 3 commits into
microsoft:mainfrom
RyanEwen:fix/browser-tool-failure-reporting

Conversation

@RyanEwen

@RyanEwen Ryan Ewen (RyanEwen) commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

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.didExecuteTool kept the optimistic label. It replaced pastTenseMessage only 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. invokeFunctionResultToToolResult reported an errored run as a success. An error from the evaluated Playwright code was recorded only in toolResultDetails.isError, never as toolResultError, so the tool call itself came back successful. Now sets toolResultError too.

The second one matters beyond the UI: the model is told the call succeeded.

Testing

  • Added 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.
  • ChatModel 135 passing, ChatResponseModel 8, ChatListRenderer 41, stateToProgress 130, ToolInvocation 104. No failures.
  • npm run typecheck-client clean.

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.

Copilot AI balanced review requested due to automatic review settings August 13, 2026 18:36
@vs-code-engineering

vs-code-engineering Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Kyle Cutler (@kycutler)

Matched files:

  • src/vs/workbench/contrib/browserView/electron-browser/tools/browserToolHelpers.ts
  • src/vs/workbench/contrib/browserView/test/electron-browser/tools/browserToolHelpers.test.ts

Joaquín Ruales (@jruales)

Matched files:

  • src/vs/workbench/contrib/browserView/electron-browser/tools/browserToolHelpers.ts
  • src/vs/workbench/contrib/browserView/test/electron-browser/tools/browserToolHelpers.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • error is optional, so presence—not truthiness—indicates that execution threw. The service can produce an empty string from new Error() or throw ''; 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 with error produces a truthy toolResultError and 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.
@RyanEwen
Ryan Ewen (RyanEwen) force-pushed the fix/browser-tool-failure-reporting branch from 21c89e5 to c517c08 Compare August 17, 2026 19:07
@RyanEwen

Ryan Ewen (RyanEwen) commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Agreed, and reworked that way — the ChatToolInvocation hunk is gone.

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 — pastTenseMessage: \${toolCall.displayName} failed`inprotocolServerHandler._completeDisconnectedClientToolCalls`. So "the producer names the failure" is already the convention on both sides, and my version changed the past-tense behavior of every tool that reports an error in order to fix browser ones.

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 invocationMessage and never a pastTenseMessage — no browser tool sets one — so on completion ChatToolInvocation falls back to the present-tense progress message and "Capturing browser screenshot" becomes the completed state. Naming the failure fixes that without touching shared code.

That also settles the suppressed Copilot comment about an empty error message: the check is on presence rather than truthiness now, so throw '' and new Error() still report a failure rather than silently passing as success. isError in toolResultDetails moved to the same test for consistency.

Coverage moved with the behavior. The ChatToolInvocation test is gone and there's a new browserToolHelpers.test.ts covering the conversion directly — a failure sets both fields, an empty error message still counts as a failure, a success sets neither, and errorResult names the failure. That was Copilot's other point, that nothing exercised the conversion itself.

One thing I left deliberately generic: the label is a single localized "Browser action failed" rather than per-tool text, because invokeFunctionResultToToolResult and errorResult never see the tool's own name. Threading a label through each tool would give "Failed to capture screenshot" and so on — happy to do that if you'd prefer it, but it touches every browser tool and this seemed like the smaller change to review.

Rebased on current main; the diff is now just the helper and its test. 14615 node unit tests pass, typecheck clean.

AI disclosure: this comment and the related code were written with the assistance of AI.

@connor4312
Connor Peet (connor4312) merged commit 624addc into microsoft:main Aug 17, 2026
27 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.135.0 milestone Aug 17, 2026
@RyanEwen

Ryan Ewen (RyanEwen) commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

errorResult(''). Correct, and it was inconsistent with the conversion right above it, which already fell back (result.error || failedMessage). errorResult now does the same, so a thrown empty string or a bare new Error() still reports a failure instead of being serialised as a successful call. Test added for exactly that input.

The pastTenseMessage point — you are right and my description was wrong. I claimed these tools declare only an invocationMessage. They do not: screenshotBrowserTool prepares "Captured browser screenshot", readBrowserTool "Read {0}", and so on. The real mechanism is the one you describe — didExecuteTool keeps that prepared, success-shaped label unless the result carries a message of its own, so a failed call completes wearing the label of a successful one. Supplying toolResultMessage on failure overrides it, which is why the fix works, but my explanation of why it was broken was not accurate. The comment above failedMessage now says the right thing.

Worth noting that also makes the original ChatToolInvocation approach in this PR's first revision more clearly wrong than I understood at the time: clearing pastTenseMessage would have dropped a legitimately prepared label rather than replacing a fallback.

AI disclosure: this comment was written with the assistance of AI.

@dmitrivMS

Copy link
Copy Markdown
Collaborator

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.

errorResult(''). Correct, and it was inconsistent with the conversion right above it, which already fell back (result.error || failedMessage). errorResult now does the same, so a thrown empty string or a bare new Error() still reports a failure instead of being serialised as a successful call. Test added for exactly that input.

The pastTenseMessage point — you are right and my description was wrong. I claimed these tools declare only an invocationMessage. They do not: screenshotBrowserTool prepares "Captured browser screenshot", readBrowserTool "Read {0}", and so on. The real mechanism is the one you describe — didExecuteTool keeps that prepared, success-shaped label unless the result carries a message of its own, so a failed call completes wearing the label of a successful one. Supplying toolResultMessage on failure overrides it, which is why the fix works, but my explanation of why it was broken was not accurate. The comment above failedMessage now says the right thing.

Worth noting that also makes the original ChatToolInvocation approach in this PR's first revision more clearly wrong than I understood at the time: clearing pastTenseMessage would have dropped a legitimately prepared label rather than replacing a fallback.

Please tell your AI the PR is merged :-)

@RyanEwen

Ryan Ewen (RyanEwen) commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor Author

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.
errorResult(''). Correct, and it was inconsistent with the conversion right above it, which already fell back (result.error || failedMessage). errorResult now does the same, so a thrown empty string or a bare new Error() still reports a failure instead of being serialised as a successful call. Test added for exactly that input.
The pastTenseMessage point — you are right and my description was wrong. I claimed these tools declare only an invocationMessage. They do not: screenshotBrowserTool prepares "Captured browser screenshot", readBrowserTool "Read {0}", and so on. The real mechanism is the one you describe — didExecuteTool keeps that prepared, success-shaped label unless the result carries a message of its own, so a failed call completes wearing the label of a successful one. Supplying toolResultMessage on failure overrides it, which is why the fix works, but my explanation of why it was broken was not accurate. The comment above failedMessage now says the right thing.
Worth noting that also makes the original ChatToolInvocation approach in this PR's first revision more clearly wrong than I understood at the time: clearing pastTenseMessage would have dropped a legitimately prepared label rather than replacing a fallback.

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants