-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: handle unknown/invalid native tool calls to prevent extension freeze #9834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…eeze When a model called a tool that doesn't exist, the switch statement in presentAssistantMessage had no default case to handle it. For native protocol, this meant no tool_result was sent back to the API, causing the extension to freeze waiting indefinitely. Added: - Default case in tool switch statement that: - Pushes an error tool_result back to the API - Increments consecutiveMistakeCount - Records the tool error - Shows error message to user - Comprehensive test suite for unknown tool handling
Contributor
Review Complete ✅Re-reviewed commit 0292351 and found no new issues. The changes successfully internationalize the unknown tool error message as requested in the previous review. Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
When using native tool protocol, if a model attempts to call a tool that doesn't exist (like 'edit_file'), the extension would freeze in a loop instead of returning an error to the model. Root causes: 1. During streaming, partial blocks of unknown tools would reach the default case in the switch statement, showing an error on every streaming chunk 2. validateToolUse was being called for partial blocks, causing repeated validation errors Changes: - Add isValidToolName() function to validateToolUse.ts to explicitly check for unknown tools - Only run tool validation for complete (non-partial) blocks in presentAssistantMessage - Skip partial blocks in the default case to prevent error loops during streaming - Fetch state early in tool_use case so mode/customModes are available throughout This ensures that when an invalid tool is called, the extension waits for the complete tool call before showing a single error and sending a tool_result back to the model.
mrubens
reviewed
Dec 4, 2025
mrubens
approved these changes
Dec 4, 2025
mrubens
approved these changes
Dec 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
lgtm
This PR has been approved by a maintainer
PR - Needs Review
size:L
This PR changes 100-499 lines, ignoring generated files.
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.
Summary
When using native tool protocol, if a model attempts to call a tool that doesn't exist, the extension would freeze in a loop instead of returning an error to the model.
Root Causes
defaultcase in the switch statement, showing an error on every streaming chunk, creating an infinite loopvalidateToolUsewas being called for partial blocks, causing repeated validation errors during streamingChanges
src/core/tools/validateToolUse.tsisValidToolName()function to explicitly check if a tool name is valid (either a known static tool or a dynamic MCP tool)src/core/assistant-message/presentAssistantMessage.tsvalidateToolUseinif (!block.partial)- validation only runs for complete tool blocks, preventing repeated errors during streamingif (block.partial) breakin thedefaultcase to skip partial blocks of unknown toolsTesting
validateToolUse.spec.tsHow to Test