fix(js/middleware/filesystem): return tool response on filesystem tool errors#5377
Open
pavelgj wants to merge 3 commits into
Open
fix(js/middleware/filesystem): return tool response on filesystem tool errors#5377pavelgj wants to merge 3 commits into
pavelgj wants to merge 3 commits into
Conversation
Return a proper tool response instead of injecting a user-role message when a filesystem tool call fails. Anthropic requires a tool response after every tool call — injecting a user message breaks its protocol. Updates tests to assert on tool-role messages with error output.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the filesystem middleware to return a toolResponse containing error details instead of injecting a user message when a tool fails. This change ensures compatibility with providers like Anthropic that require a proper tool response for every call. The test suite has been updated to reflect this change in message roles and structure, and some test markers have been refactored into constants. Review feedback highlights several locations in the updated tests where optional chaining should be applied to tool response checks to prevent potential TypeError exceptions when processing message parts.
…stem tests Add `?.` before `.includes()` calls on `toString()` results to prevent potential TypeError when `toString()` returns undefined. Also add optional chaining when accessing `toolResponse` after `find()`.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Return a proper tool response instead of injecting a user-role message when a filesystem tool call fails. Anthropic requires a tool response after every tool call — injecting a user message breaks its protocol. Updates tests to assert on tool-role messages with error output.