#21858·ai

Chat.addToolOutput overwrites a tool part that is waiting for approval, and the approval can then never be answered

Author: z4o4zCreated Sep 30, 2026Updated Sep 30, 2026
Labelstask-identify-issue-type-donetask-bug-reproduction-successfactory-activefactory-automatictask-identify-harness-labels-done

Summary

addToolOutput updates any tool part whose toolCallId matches, whatever state the part is in. If the part is in approval-requested, it becomes output-error (or output-available) but keeps approval: { id } with no approved value.

addToolApprovalResponse only updates parts in approval-requested, so this approval can no longer be answered, and lastAssistantMessageIsCompleteWithApprovalResponses never resubmits. The part also breaks UIToolInvocation, which allows an approval on an output part only with approved: true.

We hit this through a UI library that wrote a client-side error onto a server tool waiting for approval. That library bug is fixed, but any stray addToolOutput call can still cause it.

Reproduction

Offline, with AbstractChat and a transport that returns a fixed stream.

typescript
// The transport streams: start, start-step,
// tool-input-start { toolCallId: 'call_1', toolName: 'update_note' },
// tool-input-available { input: { id: 'n1' } },
// tool-approval-request { approvalId: 'ap1' }, finish-step, finish
const chat = new Chat({
  transport,
  sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses,
});

await chat.sendMessage({ text: 'rename note n1' });
// { state: 'approval-requested', approval: { id: 'ap1' } }

await chat.addToolOutput({
  tool: 'update_note',
  toolCallId: 'call_1',
  state: 'output-error',
  errorText: 'client-side error',
});
// { state: 'output-error', approval: { id: 'ap1' }, errorText: 'client-side error' }

await chat.addToolApprovalResponse({ id: 'ap1', approved: true });
// The part is unchanged and no request is sent.

Expected

addToolOutput does not change a part that is still waiting for approval, or it rejects the call. The approval stays answerable.

Actual

The part leaves approval-requested and the approval can never be answered.

Versions

ai 7.0.29 and 7.0.124 (current main). The addToolOutput code is the same in both.

Root cause

packages/ai/src/ui/chat.ts, addToolOutput (lines 611 to 658). updatePart (lines 622 to 627) matches on toolCallId only and returns { ...part, state, output, errorText } as typeof part. It keeps approval and never checks the current state. addToolApprovalResponse (lines 551 to 553) does check for state === 'approval-requested'.

Suggested fix

In addToolOutput, skip or reject a part in approval-requested. A stricter version would also skip a part that already has output. If an approval-gated part must accept output, drop an approval that has no approved value, so the part matches UIToolInvocation.