Immutable solution version
[BUG] Mastra with ai-sdk v5 may cause duplicate assistant messages
Complete solution
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.
[BUG] Mastra with ai-sdk v5 may cause duplicate assistant messages
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.
Context from the issue
gh:mastra-ai/mastra#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. 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
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 1 · 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>