Skip to content

fix(ai): preserve tool approval signature when transitioning to appro…#16558

Open
luluwux wants to merge 1 commit into
vercel:mainfrom
luluwux:fix/tool-approval-signature
Open

fix(ai): preserve tool approval signature when transitioning to appro…#16558
luluwux wants to merge 1 commit into
vercel:mainfrom
luluwux:fix/tool-approval-signature

Conversation

@luluwux

@luluwux luluwux commented Jul 1, 2026

Copy link
Copy Markdown

Background

When experimental_toolApprovalSecret is configured, resuming after a tool approval fails with AI_InvalidToolApprovalSignatureError: missing signature.

This happens because the client-side state manager drops approval.signature when transitioning from the approval-requested state to the approval-responded state in two places:

  1. In AbstractChat.addToolApprovalResponse (manual approval) — rebuilt approval as { id, approved, reason } without carrying forward signature.
  2. In processUIMessageStream under the tool-approval-response case (streamed/automatic) — rebuilt toolInvocation.approval carrying isAutomatic but omitting signature.

Consequently, convertToModelMessages later read part.approval.signature as undefined, causing the server-side verification check to throw.

Summary

  • packages/ai/src/ui/chat.ts:
    • Updated addToolApprovalResponse to preserve part.approval.signature when mapping and updating message parts.
  • packages/ai/src/ui/process-ui-message-stream.ts:
    • Updated the tool-approval-response case to carry forward the previous approval.signature into the updated toolInvocation.approval object.
  • packages/ai/src/ui/chat.test.ts:
    • Added approved with signature unit test to verify signature preservation for manual approvals.
  • packages/ai/src/ui/process-ui-message-stream.test.ts:
    • Added automatic tool approval signature preservation unit test to verify signature preservation for streamed/automatic approvals.

Manual Verification

  • Verified the state transitions and signature preservation via the newly added automated unit tests. All tests run successfully:
    ✓ src/ui/chat.test.ts (30 tests) 662ms
    ✓ src/ui/process-ui-message-stream.test.ts (115 tests) 1.59s
    
    

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features)
  • I have reviewed this pull request (self-review)

Note

Please make sure to sign your commits as required by the repository guidelines before merging.

Related Issues

Fixes #16543

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.

experimental_toolApprovalSecret: approval signature dropped on approval-responded → "missing signature" (7.0.8/7.0.9)

1 participant