Skip to content

Report a browser tool failure with an empty message as a failure - #334311

Merged
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
microsoft:mainfrom
RyanEwen:fix/browser-tool-empty-error
Sep 3, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 1 commit into
microsoft:mainfrom
RyanEwen:fix/browser-tool-empty-error

Conversation

@RyanEwen

@RyanEwen Ryan Ewen (RyanEwen) commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #330707. That PR merged with two review points from Dmitriy Vasyura (@dmitrivMS) unaddressed. I replied at the time saying both were fixed in it, on the mistaken belief that it had not merged yet. It had, and neither change landed. Nothing has touched errorResult since.

An empty error message reports success to the model

errorResult set toolResultError to the raw message, unlike the conversion sixteen lines above it, which already falls back:

...(result.error !== undefined ? { toolResultError: result.error || failedMessage, toolResultMessage: failedMessage } : {}),

So errorResult('') left toolResultError falsy, and that is the sole error signal downstream:

// agentHostSessionHandler.ts
const isError = !!result.toolResultError;
...
success: !isError,

The call was serialized as a success with error: undefined, while toolResultMessage still set the completed row to "Browser action failed". The user saw a failure, the model was told it succeeded.

Three call sites can produce an empty message, all of the form e instanceof Error ? e.message : String(e), which is '' for both new Error() and throw '': playwrightInvoke in browserToolHelpers.ts (used by the click, type, hover, drag, navigate and screenshot tools), the deferred-result wait in runPlaywrightCodeTool.ts, and handleDialogBrowserTool.ts. The fourth site prefixes its message and was never affected.

The fix falls back to the same label the conversion uses, for the content part as well as the error, so the model is given a reason rather than an empty string.

The comment on failedMessage was wrong

It asserted these tools "declare only an invocationMessage". They do not: the screenshot tool prepares "Captured browser screenshot", and didExecuteTool keeps a prepared past-tense label unless the result carries a toolResultMessage. That is the mechanism Dmitriy Vasyura (@dmitrivMS) described, and the comment still stated the version I had wrong. Rewritten to say what the constant is actually for.

Tests

errorResult with an empty message still reports a failure covers both the error signal and the content part. It mirrors the existing empty-message test for invokeFunctionResultToToolResult, which had no errorResult counterpart. Without the source change it fails on the first assertion; with it the file is 6 passing. No new type errors, 349 before and after.

AI disclosure: this comment and the related code 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.

`errorResult('')` left `toolResultError` falsy, so `toolResultToProtocol`
serialized the call as `success: true` while the completed row still read
"Browser action failed". Both `new Error()` and `throw ''` reach it as an
empty string, from `playwrightInvoke` and two other call sites.

Fall back to the failure label for the error and the content part, as the
conversion above already does for `result.error`.

Also corrects the comment on `failedMessage`. These tools do not all declare
only an `invocationMessage`; the screenshot tool prepares a past-tense one,
and that prepared label is what survives when a result carries no
`toolResultMessage`.
Copilot AI balanced review requested due to automatic review settings September 3, 2026 16:39
@vs-code-engineering

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.

🟢 Approval recommended

The focused fix correctly preserves failure signaling and includes appropriate regression coverage.

Pull request overview

Ensures empty browser-tool errors are reported as failures to both the model and UI.

Changes:

  • Falls back to “Browser action failed” for empty errors.
  • Adds regression coverage and corrects the failure-label comment.
File summaries
File Description
browserToolHelpers.ts Adds non-empty error fallback and updates documentation.
browserToolHelpers.test.ts Tests empty-message failure handling.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 3c83500 into microsoft:main Sep 3, 2026
30 checks passed
@RyanEwen
Ryan Ewen (RyanEwen) deleted the fix/browser-tool-empty-error branch September 3, 2026 17:44
@vs-code-engineering vs-code-engineering Bot added this to the 1.137.0 milestone Sep 3, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 18, 2026
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.

5 participants