Skip to content

fix(js/middleware/filesystem): return tool response on filesystem tool errors#5377

Open
pavelgj wants to merge 3 commits into
mainfrom
pj/filesystem-middleware-fix-tool-error-handler
Open

fix(js/middleware/filesystem): return tool response on filesystem tool errors#5377
pavelgj wants to merge 3 commits into
mainfrom
pj/filesystem-middleware-fix-tool-error-handler

Conversation

@pavelgj
Copy link
Copy Markdown
Member

@pavelgj pavelgj commented May 21, 2026

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.

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.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread js/plugins/middleware/tests/filesystem_test.ts
Comment thread js/plugins/middleware/tests/filesystem_test.ts
Comment thread js/plugins/middleware/tests/filesystem_test.ts
Comment thread js/plugins/middleware/tests/filesystem_test.ts
Comment thread js/plugins/middleware/tests/filesystem_test.ts Outdated
@pavelgj pavelgj changed the title fix(middleware): return tool response on filesystem tool errors fix(js/middleware/filesystem): return tool response on filesystem tool errors May 21, 2026
pavelgj added 2 commits May 21, 2026 14:18
…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()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant