Skip to content

fix: UI message validation rejects persisted assistant responses with empty parts#17201

Merged
lgrammel merged 2 commits into
mainfrom
bug-11053-2
Jul 14, 2026
Merged

fix: UI message validation rejects persisted assistant responses with empty parts#17201
lgrammel merged 2 commits into
mainfrom
bug-11053-2

Conversation

@lgrammel

@lgrammel lgrammel commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Background

Persisted chats could become unloadable when an errored assistant response was saved with an empty parts array.

Summary

Allowed assistant UI messages to have empty parts while retaining non-empty parts validation for user and system messages.

Testing

Added regression coverage for validateUIMessages and safeValidateUIMessages using chats ending with an empty assistant response.

End-to-end Validation

  • pnpm --filter ai build followed by an inline pnpm tsx persisted-chat validation returned {"success":true,"messageCount":2}.

Related Issues

Fixes #11053

Co-authored-by: davidroeca 6155705+davidroeca@users.noreply.github.com

@lgrammel lgrammel changed the title reproduction: UIMessage validations are now a bit too strict fix: UI message validation rejects persisted assistant responses with empty parts Jul 14, 2026
@lgrammel
lgrammel marked this pull request as ready for review July 14, 2026 12:03
@lgrammel

Copy link
Copy Markdown
Collaborator Author

Bugfix review

Outcome: approved

Fixes issue

Status: fully-addresses

The schema now accepts empty parts only for assistant messages, allowing the persisted errored response described in #11053 to load through both validation APIs.

Concerns: none.

Side effects

Risk: low

The validation relaxation is narrowly role-scoped; existing tests still confirm empty user-message parts are rejected, and the same condition also preserves rejection for system messages.

Concerns: none.

Performance

Risk: low

The change adds one constant-time role and length check per message during validation, with no additional retained data or meaningful complexity increase.

Concerns: none.

Backwards compatibility

Risk: none

Stored messages are not mutated; previously valid data remains valid, while persisted assistant messages with empty parts become loadable.

Concerns: none.

Security

Risk: low

Only the assistant-parts minimum-length rule is relaxed; message roles, IDs, parts arrays, and all non-empty part structures continue to be schema-validated.

Concerns: none.

Testing

Status: appropriate

Regression tests cover the reported persisted-chat shape through validateUIMessages and safeValidateUIMessages while retaining coverage that empty user parts fail.

Concerns: none.

Verification

Inspected origin/main...HEAD and the original reproduction; ran the focused validation suite in Node and Edge configurations with all 55 tests passing in each, ran the ai package type-check and targeted formatting/lint checks successfully, and manually confirmed empty assistant messages validate while empty system messages fail and downstream model conversion safely omits an empty assistant message.

@lgrammel
lgrammel merged commit ac01b79 into main Jul 14, 2026
57 checks passed
@lgrammel
lgrammel deleted the bug-11053-2 branch July 14, 2026 12:49
lgrammel added a commit that referenced this pull request Jul 14, 2026
…es with empty parts (#17217)

## Background

Persisted chats could become unloadable when an errored assistant
response was saved with an empty parts array.

## Summary

Allowed assistant UI messages to have empty parts while retaining
non-empty parts validation for user and system messages.

## Testing

Added regression coverage for validateUIMessages and
safeValidateUIMessages using chats ending with an empty assistant
response.

## End-to-end Validation

- `pnpm --filter ai build` followed by an inline `pnpm tsx`
persisted-chat validation returned `{"success":true,"messageCount":2}`.

## Related Issues

Fixes #11053

Backport of #17201

Co-authored-by: davidroeca <6155705+davidroeca@users.noreply.github.com>

Co-authored-by: davidroeca <6155705+davidroeca@users.noreply.github.com>
lgrammel added a commit that referenced this pull request Jul 14, 2026
…es with empty parts (#17219)

## Background

Persisted chats could become unloadable when an errored assistant
response was saved with an empty parts array.

## Summary

Allowed assistant UI messages to have empty parts while retaining
non-empty parts validation for user and system messages.

## Testing

Added regression coverage for validateUIMessages and
safeValidateUIMessages using chats ending with an empty assistant
response.

## End-to-end Validation

- `pnpm --filter ai build` followed by an inline `pnpm tsx`
persisted-chat validation returned `{"success":true,"messageCount":2}`.

## Related Issues

Fixes #11053

Backport of #17201

Co-authored-by: davidroeca <6155705+davidroeca@users.noreply.github.com>

Co-authored-by: davidroeca <6155705+davidroeca@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
ai 7.0.27 github npm
@ai-sdk/alibaba 2.0.12 github npm
@ai-sdk/amazon-bedrock 5.0.21 github npm
@ai-sdk/angular 3.0.27 github npm
@ai-sdk/anthropic 4.0.15 github npm
@ai-sdk/anthropic-aws 2.0.7 github npm
@ai-sdk/assemblyai 3.0.10 github npm
@ai-sdk/azure 4.0.14 github npm
@ai-sdk/baseten 2.0.10 github npm
@ai-sdk/black-forest-labs 2.0.10 github npm
@ai-sdk/bytedance 2.0.12 github npm
@ai-sdk/cartesia 3.0.3 github npm
@ai-sdk/cerebras 3.0.10 github npm
@ai-sdk/cohere 4.0.10 github npm
@ai-sdk/deepgram 3.0.10 github npm
@ai-sdk/deepinfra 3.0.10 github npm
@ai-sdk/deepseek 3.0.10 github npm
@ai-sdk/devtools 1.0.6 github npm
@ai-sdk/elevenlabs 3.0.11 github npm
@ai-sdk/fal 3.0.11 github npm
@ai-sdk/fireworks 3.0.11 github npm
@ai-sdk/gateway 4.0.20 github npm
@ai-sdk/gladia 3.0.10 github npm
@ai-sdk/google 4.0.15 github npm
@ai-sdk/google-vertex 5.0.19 github npm
@ai-sdk/groq 4.0.11 github npm
@ai-sdk/harness 1.0.32 github npm
@ai-sdk/harness-claude-code 1.0.33 github npm
@ai-sdk/harness-codex 1.0.34 github npm
@ai-sdk/harness-deepagents 1.0.31 github npm
@ai-sdk/harness-opencode 1.0.33 github npm
@ai-sdk/harness-pi 1.0.32 github npm
@ai-sdk/huggingface 2.0.10 github npm
@ai-sdk/hume 3.0.10 github npm
@ai-sdk/klingai 4.0.11 github npm
@ai-sdk/langchain 3.0.27 github npm
@ai-sdk/llamaindex 3.0.27 github npm
@ai-sdk/lmnt 3.0.10 github npm
@ai-sdk/luma 3.0.11 github npm
@ai-sdk/mcp 2.0.13 github npm
@ai-sdk/mistral 4.0.11 github npm
@ai-sdk/moonshotai 3.0.12 github npm
@ai-sdk/open-responses 2.0.10 github npm
@ai-sdk/openai 4.0.14 github npm
@ai-sdk/openai-compatible 3.0.10 github npm
@ai-sdk/otel 1.0.27 github npm
@ai-sdk/perplexity 4.0.11 github npm
@ai-sdk/policy-opa 1.0.27 github npm
@ai-sdk/prodia 2.0.11 github npm
@ai-sdk/provider-utils 5.0.10 github npm
@ai-sdk/quiverai 2.0.10 github npm
@ai-sdk/react 4.0.28 github npm
@ai-sdk/replicate 3.0.11 github npm
@ai-sdk/revai 3.0.10 github npm
@ai-sdk/rsc 3.0.27 github npm
@ai-sdk/sandbox-just-bash 1.0.32 github npm
@ai-sdk/sandbox-vercel 1.0.32 github npm
@ai-sdk/svelte 5.0.27 github npm
@ai-sdk/togetherai 3.0.11 github npm
@ai-sdk/tui 1.0.27 github npm
@ai-sdk/valibot 3.0.10 github npm
@ai-sdk/vercel 3.0.10 github npm
@ai-sdk/voyage 2.0.10 github npm
@ai-sdk/vue 4.0.27 github npm
@ai-sdk/workflow 1.0.27 github npm
@ai-sdk/workflow-harness 1.0.32 github npm
@ai-sdk/xai 4.0.13 github npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UIMessage validations are now a bit too strict

1 participant