fix: UI message validation rejects persisted assistant responses with empty parts#17201
Conversation
Bugfix reviewOutcome: approved Fixes issueStatus: 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 effectsRisk: 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. PerformanceRisk: 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 compatibilityRisk: none Stored messages are not mutated; previously valid data remains valid, while persisted assistant messages with empty parts become loadable. Concerns: none. SecurityRisk: 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. TestingStatus: appropriate Regression tests cover the reported persisted-chat shape through validateUIMessages and safeValidateUIMessages while retaining coverage that empty user parts fail. Concerns: none. VerificationInspected 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. |
…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>
…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>
|
🚀 Published in:
|
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 buildfollowed by an inlinepnpm tsxpersisted-chat validation returned{"success":true,"messageCount":2}.Related Issues
Fixes #11053
Co-authored-by: davidroeca 6155705+davidroeca@users.noreply.github.com