fix: sanitize null providerExecuted in tool-call parts to prevent ModelMessage validation error#3100
Conversation
…conversion DB JSONB storage can persist providerExecuted as JSON null for tool-call parts. The AI SDK's standardizePrompt validates messages using z.boolean().optional(), which accepts undefined but rejects null (Zod v4 strict behavior), causing the 'Invalid prompt: The messages must be a ModelMessage[]' error on resume. ensureToolCallResults now converts providerExecuted: null to undefined for all tool-call parts before convertToModelMessages runs, preventing the Zod failure. Fixes onlook-dev#2888
|
Someone is attempting to deploy a commit to the Onlook Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
Closes #2888
When a conversation with tool calls is loaded from the database and the AI stream resumes, the app throws:
Root Cause
Tool-call parts are stored as JSONB in the database. JSONB permits JSON
nullas a valid value for any field — soproviderExecutedcan be stored asnullwhen it wasn't explicitly set (e.g. from older records or a race during streaming).In
convertToModelMessages(AI SDK v5,src/ui/convert-to-model-messages.ts, line ~5915), the function passesproviderExecuteddirectly from the UIMessage part into the ModelMessage content:standardizePromptthen validates this againstmodelMessageSchemausing Zod v4'sz.boolean().optional(). In Zod v4,.optional()allowsundefinedbut rejectsnull— causing the crash.Fix
ensureToolCallResults(inpackages/ai/src/stream/index.ts) already processes all tool-call parts on every assistant message beforeconvertToModelMessagesruns. The fix adds a null-to-undefined sanitization step there:This converts
null → undefinedforproviderExecutedon every tool-call part before the AI SDK validates it, fixing the crash without affecting any other behavior.Test plan
streamTextis called without the "Invalid prompt" errorSummary by CodeRabbit