Skip to content

fix(ai): strip execute from tools passed to repairToolCall callback#14985

Open
Mmartinrusso wants to merge 2 commits into
vercel:mainfrom
Mmartinrusso:fix/repair-tool-call-strip-execute
Open

fix(ai): strip execute from tools passed to repairToolCall callback#14985
Mmartinrusso wants to merge 2 commits into
vercel:mainfrom
Mmartinrusso:fix/repair-tool-call-strip-execute

Conversation

@Mmartinrusso
Copy link
Copy Markdown
Contributor

@Mmartinrusso Mmartinrusso commented May 5, 2026

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

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root)
  • I have reviewed this pull request (self-review)

@Mmartinrusso Mmartinrusso force-pushed the fix/repair-tool-call-strip-execute branch from 97554b8 to 70fc6da Compare May 5, 2026 13:35
Mmartinrusso and others added 2 commits May 5, 2026 11:25
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>
@Mmartinrusso Mmartinrusso force-pushed the fix/repair-tool-call-strip-execute branch from 70fc6da to 3935b2f Compare May 5, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant