Skip to content

fix(ai): reject messages after tool approval responses#17551

Open
jstar0 wants to merge 1 commit into
vercel:mainfrom
jstar0:fix/tool-approval-message-sequence
Open

fix(ai): reject messages after tool approval responses#17551
jstar0 wants to merge 1 commit into
vercel:mainfrom
jstar0:fix/tool-approval-message-sequence

Conversation

@jstar0

@jstar0 jstar0 commented Jul 21, 2026

Copy link
Copy Markdown

fix(ai): reject messages after tool approval responses

Background

streamText currently treats any approval response in message history as
resolving its tool call during prompt validation, while local approval execution
only consumes responses from the final tool message. A later user, system, or
assistant message can therefore leave a dangling tool call that reaches the
provider without executing the approved tool or producing a denial result.

The earlier approach in #17036 searches backward and executes approvals after
trailing context. This change instead follows the later maintainer guidance in
#17033 that such messages break the required
assistant -> tool -> assistant -> user sequence and should be rejected.

Summary

Align prompt validation with the approval boundary consumed by the current
streamText or generateText invocation. Invalid histories are rejected before
an approved side effect or provider request can be silently skipped.

Changes

  • Limit approval-based missing-result exemption to responses in the final tool
    message, matching the boundary consumed by the current invocation.
  • Reject unresolved approved or denied histories before tool execution or model
    invocation by using the existing MissingToolResultsError.
  • Preserve completed histories that already contain a tool result.
  • Add direct streamText and prompt-validation regression coverage plus a patch
    changeset for ai.

Contributor Credit

End-to-End Verification

An approved response followed by a user message now reports
MissingToolResultsError before either the tool or model is called. The same
boundary rejects denied and other unresolved trailing histories. A final
approval response still follows the normal execution path, and a completed tool
result can still be followed by assistant and user messages.

Verification

cd packages/ai && pnpm test
cd packages/ai && pnpm type-check
cd packages/ai && pnpm build
pnpm check

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)

Related Issues

Fixes #17033

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.

streamText silently skips local tool approvals when a later context message follows the approval response

1 participant