fix: prevent invalid tool from leaking into model error messages#23264
fix: prevent invalid tool from leaking into model error messages#23264nitishagar wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PRs Found:
These PRs all touch on tool call repair and error handling, though they may address different aspects. PR #23067 seems most directly related as it also deals with tool call argument repair. You may want to verify if these are solving overlapping issues or if they're complementary fixes. |
Issue for this PR
Closes #21900
Type of change
What does this PR do?
When a model emits an invalid tool call, the AI SDK's
NoSuchToolErrorincludes the raw "Available tools: invalid, bash, read, ..." list. This gets passed throughexperimental_repairToolCall→ theinvalidtool → back into the model's context. The model sees "invalid" listed as a tool and may try calling it, entering a loop that the doom loop detector can't catch because each call has different input.Three fixes:
llm.ts: ExtractrepairToolCalland build a clean error message that never leaks internal tool names or the "Available tools" list. Uses duck-typing on the error object to distinguish "tool not found" from "bad arguments."processor.ts: Extend doom loop detection to circuit-break consecutiveinvalidtool calls regardless of input variation. The existing detector only catches identical calls (same name + same input).invalid.ts: Strip any residual "Available tools: ..." text from the output as defense-in-depth.How did you verify your code works?
bun run typecheckpassesbun test test/session/llm.test.ts test/session/processor-effect.test.ts)repairToolCallcovering: case-insensitive repair, unknown tool clean error, invalid arguments error, exact match fallbackScreenshots / recordings
N/A - no UI changes
Checklist