Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 6, 2025

Description

Skipped tool invocations were leaking success messages into the language model context. When a user skipped a tool approval (e.g., fetch request), the Chat Debug view showed both the preparation success message and the skip message:

Here is some relevant context from the web page https://google.com/:
The user chose to skip the tool call, they want to proceed without running it

Changes

The pastTenseMessage from prepareToolInvocation persisted on ChatToolInvocation even after skip. The initial fix set toolResultMessage: '' in the skip result, but this didn't work because the condition if (result?.toolResultMessage) treated empty strings as falsy in JavaScript/TypeScript.

Fixed by changing the condition to use strict undefined checking instead of truthiness checking.

languageModelToolsService.ts

  • Pre-execution skip: Added toolResultMessage: '' to tool result
  • Post-execution skip: Added toolResultMessage: '' to tool result

chatToolInvocation.ts

  • Changed condition from if (result?.toolResultMessage) to if (result?.toolResultMessage !== undefined) to properly handle empty string values

languageModelToolsService.test.ts

  • Added test coverage for both skip scenarios

Fixes contaminated language model context when tools are skipped.

Original prompt

This section details on the original issue you should resolve

<issue_title>Chat: Skipped fetch tool response still has some success text</issue_title>
<issue_description>1. Ask the Agent to fetch https://google.com
2. Skip the tool approval step
3. Open the Chat Debug view

🐛 The response has the following contents:

Here is some relevant context from the web page https://google.com/:
The user chose to skip the tool call, they want to proceed without running it

That first sentence is bogus, it should not appear in the subsequent prompts.

Image

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

When a tool call is skipped (either pre-execution or post-execution), the pastTenseMessage from prepareToolInvocation was still being included in the response sent to the language model. This caused confusing messages like "Here is some relevant context from the web page..." to appear alongside the skip message.

The fix sets toolResultMessage to an empty string when a tool is skipped, which overrides the pastTenseMessage property on the ChatToolInvocation object. This ensures only the skip message is sent to the language model.

Changes:
- Set toolResultMessage to empty string when tool is skipped (pre-execution)
- Set toolResultMessage to empty string when tool results are skipped (post-execution)
- Added tests to verify the fix

Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bogus text in skipped fetch tool response Fix skipped tool response contamination with success message Nov 6, 2025
Copilot AI requested a review from dmitrivMS November 6, 2025 23:49
Copilot finished work on behalf of dmitrivMS November 6, 2025 23:49
@dmitrivMS
Copy link
Contributor

@copilot This does not fix the problem, try again.

The previous fix didn't work because JavaScript/TypeScript treats empty strings as falsy. The condition `if (result?.toolResultMessage)` would be false when toolResultMessage is '', so the pastTenseMessage never got overridden.

Changed the condition to `if (result?.toolResultMessage !== undefined)` to properly handle empty strings and ensure the pastTenseMessage is cleared when tools are skipped.

Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 7, 2025

@copilot This does not fix the problem, try again.

Fixed in 97c47e4. The previous approach didn't work because empty string '' is falsy in JavaScript/TypeScript. Changed the condition from if (result?.toolResultMessage) to if (result?.toolResultMessage !== undefined) to properly handle empty strings.

Copilot finished work on behalf of dmitrivMS November 7, 2025 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat: Skipped fetch tool response still has some success text

2 participants