ai-sdk: answering an approval on a message that later turns follow does nothing
answering a tool approval on an assistant message that is no longer the last one is a silent no-op in useAISDKRuntime. respondViaAISDK calls chatHelpers.addToolApprovalResponse, and [email protected] only rewrites the last message (addToolApprovalResponse in ai/dist/index.js maps the parts of messages[messages.length - 1]), so an approval-requested part on an earlier message stays requested. that message keeps its requires-action status, the kit keeps rendering Allow and Deny on it, and every click resolves without recording anything. addToolOutput has the same last message limit, so a human tool result added on an earlier message resolves and is dropped the same way.
a normal send does not reach this state. cancelPendingToolCallsOnSend defaults to true and useChatRuntime doesn't expose it, so onNew runs completePendingToolCalls before sendMessage and turns every open tool part into an output-error. the state comes from a message that lands after the pause without that sweep: a staged append({ startRun: false }), a voice transcript, a loaded history, host code calling chat.sendMessage directly, or cancelPendingToolCallsOnSend: false.
#8415 settled this state on the local runtime (#8348): a later turn ends the pause, open approvals record resolution: "cancelled", the message settles as incomplete/cancelled, a late answer throws, and a late tool result is stored without resuming. the ai-sdk runtime should match:
- an undecided approval whose message is not the last entry in
chat.messagesprojects asresolution: "cancelled", whatever role follows it, and its message settles as cancelled. the check runs on the useChat list, not on thread messages, since the default join strategy merges a following assistant message into the same thread message. - an approval a host handler already answered keeps its answer; one it has not answered is cancelled like any other.
- the part guards in core already throw once
resolutionis set, so the late answer is refused instead of resolving. - a late tool result is written into its message without triggering
sendAutomaticallyWhen, instead of being dropped.
repro: useAISDKRuntime with a tool that needs approval (useChatRuntime takes the same path), let the run pause on it, stage a message with thread.append({ role: "user", content: [{ type: "text", text: "later" }], startRun: false }), then click Allow on the earlier card: the click resolves, the part stays approval-requested, and nothing is sent. a normal send with cancelPendingToolCallsOnSend: false gives the same result, and the same staged message after a human tool call leaves the part input-available when addResult answers it.
Source: assistant-ui/assistant-ui