Close a discarded Vercel AI tool call with `tool-input-error` so the frontend doesn't run it
- Part of #13260
On AI SDK v6+, a tool call the run discarded now renders as output-error. That covers calls skipped after the final result, calls cut off by a run error, and a pending output tool call cut off by a cancellation. Before, such a call was first announced with tool-input-available. That left it in input-available, or put it in output-error or output-available with the synthetic or stub result. AI SDK v5 is unchanged.
The change applies to a streamed tool call that never got tool-input-available and is then closed without having run:
- the
on_errorflush of a call that was still streaming its args when the run errored; - the synthetic failed or interrupted result for a pending call, for example an output tool whose validation raised before its call event;
- the "Tool not executed" stub for a call skipped because a final result was already processed (
end_strategy='early'), or the "Output tool not used" stub for a second output tool call.
Until now the Vercel AI adapter announced such a call with a backfilled tool-input-available before closing it. In AI SDK v6+, tool-input-available without providerExecuted awaits the frontend's onToolCall, so a call the run discarded could run in the browser. On v6+ the adapter now sends tool-input-error instead, with the call's input and the synthetic or stub message as errorText. That's the same chunk it already sends for a call whose args failed validation. tool-input-error puts the part in output-error and never calls onToolCall.
A call that already got tool-input-available keeps its current closeout. A denied call is unchanged, and so is everything on v5, which has no tool-input-error. A function tool call that's still streaming when the run is cancelled still gets no closeout, since the stream just ends with abort. The docs now say so.
The closeout survives a reload exactly. The AI SDK keeps a tool-input-error part's input only as rawInput, and the chunk's providerMetadata as the part's resultProviderMetadata. So:
- the chunk carries a
'success'(the "not executed" stubs) or'interrupted'outcome claim on the samepydantic_ai.outcomekey that'interrupted'and'retried'already use, andload_messagesrestores it onoutput-error; - loading falls back to
rawInputwheninputis missing; ToolOutputAvailablePartandToolOutputErrorPart(static and dynamic) acceptresult_provider_metadata, and loading reads call metadata and the claim from it as a fallback. Without this, anytool-input-errorpart with provider metadata, such as a call with anid, failed validation of the whole next request. The field mirrors the AI SDK'sresultProviderMetadata, added inai6.0.120.
This also fixes a bug on main: after a tool call's args failed validation, the AI SDK sent its tool-input-error part back with resultProviderMetadata, and the next request failed validation.
Tests:
tests/test_vercel_ai.py:- The v6 error closeout emits
tool-input-errorand notool-input-available; the v5 closeout is unchanged. - A call that was already available keeps its
tool-output-errorcloseout. - The synthetic failed and interrupted results take
tool-input-erroron v6 and keep the backfill on v5. - A call skipped after the final result takes
tool-input-erroron v6 and keepstool-input-availableplus the stub output on v5. - The
on_errorcloseout of a'redacted'call carries the placeholder, and a'private'call that reused the id gets no closeout.
- The v6 error closeout emits
tests/ui_roundtrip:- The driver now records the ids the real AI SDK client hands to
onToolCall. Two new tests check that neither the call cut off by an error nor the call skipped after the final result reaches it, while the output tool call does. On main the discarded calls reach it. - A new
skipped_tool_callsscenario (end_strategy='early': a function tool call and a second output tool call skipped) runstest_loadandtest_wire_requeston both paths. Before the reload fix, the Vercel stream path came back with{}args and'failed'returns. - A cancelled output tool call with an
idreloads with its args,id,provider_nameand'interrupted'outcome. The error closeout reloads with its args.
- The driver now records the ids the real AI SDK client hands to
#13260 is mainly about the tool calls of a replaced streamed response, which this doesn't change, so it stays open.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
š¤ Generated with Claude Code