fix: prevent strict Chat Completions backends from rejecting malformed persisted tool arguments (#19283)
## Background
Persisted output-error UI tool parts can contain malformed raw input,
causing strict OpenAI-compatible Chat Completions backends to reject
every continuation before the model receives the paired tool error.
## Root Cause
`convertToModelMessages` can represent malformed `rawInput` as a string,
and the OpenAI Chat Completions serializer JSON-stringified that
non-object value directly, producing arguments that decoded to a string.
The original reproduction previously returned HTTP 400 and now succeeds
with object-valued arguments.
## Summary
The serializer now emits `{}` for non-object or array tool inputs while
preserving valid objects.
Regression coverage stays with the packages that own each side of the
boundary:
- The `ai` conversion test verifies that malformed persisted `rawInput`
and its paired tool error are preserved in model messages.
- The `@ai-sdk/openai` serializer test verifies that malformed input
becomes object-valued arguments while the paired tool error remains in
the Chat Completions request.
The PR also includes a patch changeset for `@ai-sdk/openai`.
## Testing
- AI UI-message conversion tests pass in Node and Edge environments with
67 tests each.
- Focused OpenAI Node and Edge tests pass with 34 tests each.
- The full workspace type check passes.
- Formatting and lint checks pass.
## End-to-end Validation
- `pnpm -C examples/ai-functions exec tsx
src/reproduction/issue-19274-openai-malformed-tool-replay.ts` via
immutable replay — exited zero without the configured bug signal.
- `pnpm -C packages/openai build && pnpm -C examples/ai-functions exec
tsx src/reproduction/malformed-tool-replay-live-validation.ts` — live
qwen-plus accepted the replay and returned corrected object-valued tool
arguments.
## Related Issues
Fixes #19274
Closes #19278
---------
Co-authored-by: ai-sdk-factory <308175966+ai-sdk-factory@users.noreply.github.com>
Co-authored-by: gr2m <39992+gr2m@users.noreply.github.com>
Co-authored-by: ai-sdk-factory[bot] <305873210+ai-sdk-factory[bot]@users.noreply.github.com> A
ai-sdk-factory[bot] committed
25234039f132be79bb946130b5a7baf269d67d34
Parent: a0d2e8c
Committed by GitHub <noreply@github.com>
on 8/26/2026, 5:56:49 PM