fix(ai): fix providerExecuted tool approvals being passed to language model twice#14289
Merged
felixarntz merged 2 commits intomainfrom Apr 10, 2026
Merged
Conversation
lgrammel
approved these changes
Apr 10, 2026
ghost
pushed a commit
that referenced
this pull request
Apr 10, 2026
|
|
|
🚀 Published in:
|
felixarntz
added a commit
that referenced
this pull request
Apr 10, 2026
4 tasks
felixarntz
added a commit
that referenced
this pull request
Apr 10, 2026
… to language model twice (#14319) This is an automated backport of #14289 to the release-v6.0 branch. FYI @felixarntz ~~This backport has conflicts that need to be resolved manually.~~ Conflicts resolved. ### `git cherry-pick` output ``` Auto-merging packages/ai/src/generate-text/generate-text.test.ts Auto-merging packages/ai/src/generate-text/generate-text.ts CONFLICT (content): Merge conflict in packages/ai/src/generate-text/generate-text.ts Auto-merging packages/ai/src/generate-text/stream-text.test.ts Auto-merging packages/ai/src/generate-text/stream-text.ts CONFLICT (content): Merge conflict in packages/ai/src/generate-text/stream-text.ts error: could not apply f372547... fix(ai): fix `providerExecuted` tool approvals being passed to language model twice (#14289) hint: After resolving the conflicts, mark them with hint: "git add/rm <pathspec>", then run hint: "git cherry-pick --continue". hint: You can instead skip this commit with "git cherry-pick --skip". hint: To abort and get back to the state before "git cherry-pick", hint: run "git cherry-pick --abort". hint: Disable this message with "git config set advice.mergeConflict false" ``` --------- Co-authored-by: Felix Arntz <felix.arntz@vercel.com>
felixarntz
added a commit
that referenced
this pull request
Apr 10, 2026
… no longer ignore `providerExecuted` tool approvals (#14323) ## Summary `lastAssistantMessageIsCompleteWithApprovalResponses()` so far ignores `providerExecuted` tools. There's no good reason for that, and we already had to work around it in one of the Next.js E2E examples. This PR removes the condition so that `providerExecuted` tools are also considered. ## Manual Verification run the modified example, where the custom workaround helper was replaced with the function from `ai` ## Checklist - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues includes a follow-up cleanup of an unused variable from #14289 (which for some reason wasn't flagged by CI in that PR)
5 tasks
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
When a UI message history contains an approved
providerExecutedtool invocation and the server does the standard pattern:the provider receives the same
tool-approval-responsetwice for the sameapprovalIdin one tool message. This can cause downstream providers to reject the prompt as invalid (one approval request must produce exactly one response).Summary
collectToolApprovalsfinds approval responses by reading the last tool message ofinitialMessages. Those responses are already present ininitialMessagesbecauseconvertToModelMessagesplaced them there. BothgenerateTextandstreamTextthen redundantly pushed the same responses intoresponseMessages/initialResponseMessages. When the step computedstepInputMessages = [...initialMessages, ...responseMessages], the approval appeared twice, andconvertToLanguageModelPromptsurfaced both copies inside a single merged tool message.providerExecutedToolApprovalspush ingenerateTextstreamTextManual Verification
In
examples/ai-e2e-next, navigate to/chat/test-openai-responses-mcp-approvaland send"Shorten the link https://ai-sdk.dev/". After approving the MCP tool call, the conversation should complete successfully.To compare before/after, add a
console.logof the prompt passed to the model in the mock or in the route handler. IngenerateText/streamText, you can logstepInputMessages(the variable at the top of thedoloop /streamStepbody) immediately before the language model call and confirm the tool message contains exactly onetool-approval-responseentry after the fix.Checklist
pnpm changesetin the project root)