Fix skipped tool response contamination with success message #275960
+90
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Changes
The
pastTenseMessagefromprepareToolInvocationpersisted onChatToolInvocationeven after skip. The initial fix settoolResultMessage: ''in the skip result, but this didn't work because the conditionif (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
toolResultMessage: ''to tool resulttoolResultMessage: ''to tool resultchatToolInvocation.ts
if (result?.toolResultMessage)toif (result?.toolResultMessage !== undefined)to properly handle empty string valueslanguageModelToolsService.test.ts
Fixes contaminated language model context when tools are skipped.
Original prompt
💡 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.