Solution skill
[BUG] Mastra with ai-sdk v5 may cause duplicate assistant messages
Complete solution
Shows how to fix [BUG] Mastra with ai-sdk v5 may cause duplicate assistant messages. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
If you hit this, upgrade to the latest beta and retest. Duplicate assistant messages with ai-sdk v5 could not be reproduced in the latest beta, so the issue was closed there.
Steps
- If you hit this, upgrade to the latest beta and retest.
- Duplicate assistant messages with ai-sdk v5 could not be reproduced in the latest beta, so the issue was closed there.
When to use
You are seeing this: https://github.com/mastra-ai/mastra/issues/9370: Issue mastra-ai/mastra#9370 (closed, 32 comments): ### Describe the Bug When using useChat from @ai-sdk/react to call Mastra's API, assistant messages may have duplicate parts. Use this skill when you run into "[BUG] Mastra with ai-sdk v5 may cause duplicate assistant messages".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Sources
- https://github.com/mastra-ai/mastra/issues/9370:
- https://github.com/mastra-ai/mastra/tree/main/examples/ai-sdk-v5
Evidence
Issue gh:mastra-ai/mastra#9370: the reporter asked: Issue mastra-ai/mastra#9370 (closed, 32 comments): ### Describe the Bug When using useChat from @ai-sdk/react to call Mastra's API, assistant messages may have duplicate parts. In the messages list, some assistant messages contain previous parts. It occurred in my project and can also be reproduced 100% in the Official AI SDK v5 example when sending user messages quickly. It reproduces less frequently at normal chat speed. After some debugging, I found that it might be caused in the call stack addOne() -> addPartsToLatestMessage() -> pushNewMessagePart() in [message-list The verified answer was: Duplicate assistant messages with ai-sdk v5 could not be reproduced in the latest beta, so the issue was closed there. If you hit this, upgrade to the latest beta and retest. Evidence thread: https://github.com/mastra-ai/mastra/issues/9370
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_9mILo-MG4O23DdnXIgllbQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">[BUG] Mastra with ai-sdk v5 may cause duplicate assistant messages <span>— Vectle</span></a>