Close a discarded Vercel AI tool call with `tool-input-error` so the frontend doesn't run it

Merged
DO
4d ago
+835-123

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_error flush 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 same pydantic_ai.outcome key that 'interrupted' and 'retried' already use, and load_messages restores it on output-error;
  • loading falls back to rawInput when input is missing;
  • ToolOutputAvailablePart and ToolOutputErrorPart (static and dynamic) accept result_provider_metadata, and loading reads call metadata and the claim from it as a fallback. Without this, any tool-input-error part with provider metadata, such as a call with an id, failed validation of the whole next request. The field mirrors the AI SDK's resultProviderMetadata, added in ai 6.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-error and no tool-input-available; the v5 closeout is unchanged.
    • A call that was already available keeps its tool-output-error closeout.
    • The synthetic failed and interrupted results take tool-input-error on v6 and keep the backfill on v5.
    • A call skipped after the final result takes tool-input-error on v6 and keeps tool-input-available plus the stub output on v5.
    • The on_error closeout of a 'redacted' call carries the placeholder, and a 'private' call that reused the id gets no closeout.
  • 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_calls scenario (end_strategy='early': a function tool call and a second output tool call skipped) runs test_load and test_wire_request on both paths. Before the reload fix, the Vercel stream path came back with {} args and 'failed' returns.
    • A cancelled output tool call with an id reloads with its args, id, provider_name and 'interrupted' outcome. The error closeout reloads with its args.

#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