fix(ai): strip execute from tools passed to repairToolCall callback#14985
Open
Mmartinrusso wants to merge 2 commits into
Open
fix(ai): strip execute from tools passed to repairToolCall callback#14985Mmartinrusso wants to merge 2 commits into
Mmartinrusso wants to merge 2 commits into
Conversation
97554b8 to
70fc6da
Compare
When experimental_repairToolCall is used with the re-ask strategy, the callback receives the full tools object including execute functions. If the callback passes those tools to an inner generateText call, the tool executes inside the repair step and then again in the outer generateText — causing double execution. Strip execute (set to undefined) from each tool before passing them to the repairToolCall callback. isExecutableTool checks `typeof tool.execute === 'function'`, so setting it to undefined is enough to prevent execution in any inner generateText call while keeping the tool schemas visible to the model. Fixes vercel#5801 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
70fc6da to
3935b2f
Compare
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.
Background
The `repairToolCall` callback receives the full tool map including `execute` functions. When the callback forwards tool definitions to a model (e.g. to re-generate a malformed call), `JSON.stringify` silently drops non-serializable function values — leaving the model with incomplete tool schemas.
Summary
Strip the `execute` property from each tool before passing the map to `repairToolCall`. The callback gets clean, serializable tool definitions. The `execute` function is irrelevant to repair logic and should never be exposed to the model.
Manual Verification
Verified via unit test: the `repairToolCall` callback receives tool definitions without `execute`.
Checklist