You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(ai): v5: preserve providerMetadata on invalid tool calls and tool results (#10733)
## Background
Provider metadata (such as Google Gemini's `thoughtSignature`) was being
lost in two scenarios:
1. **Tool result propagation**: When tool results were converted to
model messages, the `callProviderMetadata` from tool UI parts was not
being propagated to tool-result parts. This was fixed in main branch (PR
#10361, merged November 19, 2025) but not backported to v5.0.
2. **Invalid tool call handling**: When a tool call failed input
validation (e.g., Zod schema mismatch), the error handler was creating
an invalid tool call object without preserving the `providerMetadata`
field from the original tool call.
This is particularly problematic for providers like Google Gemini that
use provider metadata to track `thoughtSignature` through reasoning and
tool execution cycles.
## Summary
<!-- What did you change? -->
This PR includes two related fixes for provider metadata preservation on
the `release-v5.0` branch:
### Fix 1: Tool Result Metadata Propagation (Backport from main)
Backported changes ensure that `callProviderMetadata` from tool UI parts
is correctly propagated to tool-result parts as `providerOptions` in two
locations:
1. **Provider-executed tool results** (within assistant message content)
-
[convert-to-model-messages.ts:223-225](packages/ai/src/ui/convert-to-model-messages.ts#L223-L225)
2. **Client-executed tool results** (in separate tool messages) -
[convert-to-model-messages.ts:281-283](packages/ai/src/ui/convert-to-model-messages.ts#L281-L283)
### Fix 2: Invalid Tool Call Metadata Preservation (New)
Added `providerMetadata` preservation in the error handler of
`parse-tool-call.ts` (line 88). When tool input validation fails, the
invalid tool call object now includes the `providerMetadata` from the
original `LanguageModelV2ToolCall`, matching the behavior of the success
path.
**File**:
[packages/ai/src/generate-text/parse-tool-call.ts:88](packages/ai/src/generate-text/parse-tool-call.ts#L88)
Both fixes ensure consistency in how provider metadata flows through the
entire tool execution lifecycle (tool-call → tool-result) and error
paths.
## Manual Verification
Added comprehensive test coverage:
- Client-executed tool result with provider metadata
- Provider-executed tool result with provider metadata
- Error state tool result with provider metadata
- Dynamic tool result with provider metadata
- Updated existing test snapshot to reflect the fix
In addition, I manually ran:
[google-vertex-code-execution.](examples/ai-core/src/stream-text/google-vertex-code-execution.ts)
[google-vertex-fullstream](examples/ai-core/src/stream-text/google-vertex-fullstream.ts)
[google-vertex-grounding](examples/ai-core/src/stream-text/google-vertex-grounding.ts)
with both the `gemini-3-pro-preview` and `gemini-2.5-pro` models and
confirmed they function correctly.
Finally, I manually ran the provided reproduction script in #10560, and
verified that it works correctly.
## Related Issues
Fixes#10560Fixes#10721
**Related PR:**
- #10361 - Original fix in main branch
**Potentially Related PRs:**
- #10462 - `fix(google): add thought signature to gemini 3 pro image
parts`
- #10508 - Potentially related to provider metadata handling
0 commit comments