fix(mastra): keep replay conversion alive on malformed tool-call arguments - #2576
Open
jstar0 wants to merge 1 commit into
Open
fix(mastra): keep replay conversion alive on malformed tool-call arguments#2576jstar0 wants to merge 1 commit into
jstar0 wants to merge 1 commit into
Conversation
…ments Replay history can carry concatenated or invalid tool-call argument strings. A bare JSON.parse threw and made every later run on that thread fail before reaching the model. Recover the first JSON value when arguments are concatenated, skip a tool-call that still cannot be parsed, and leave the rest of the history runnable. Fixes ag-ui-protocol#2568 Signed-off-by: King Star <mcxin.y@gmail.com>
jstar0
force-pushed
the
fix/2568-mastra-replay-tool-args
branch
from
August 30, 2026 07:21
a53f776 to
984d7ee
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2568
Summary
convertAGUIMessagesToMastraparsed replayed tool-callargumentswith a bareJSON.parse. After concurrent runs leave concatenated JSON in in-memory history ({"mine":true}{"mine":true}), every lateragent/runon that thread throws before reaching the model, so the thread stays unrunnable until process restart.On parse failure the converter now recovers the first complete JSON object or array when the rest is trailing concatenation, and skips a tool-call that still cannot be parsed. The rest of the history continues through conversion. Valid JSON is unchanged.
This is the robustness half of #2568. It does not claim to fix the unisolated concurrency path that writes concatenated arguments into process memory.
Verification
integrations/mastra/typescript/src/__tests__/message-conversion.test.tscover concatenated objects (including a}inside a string), skipping irreparable arguments while keeping a sibling tool-call, and empty arguments becoming{}.pnpm --filter @ag-ui/mastra test— 23 files / 340 tests passed (workspace@ag-ui/core,@ag-ui/client,@ag-ui/proto, and@ag-ui/a2ui-toolkitdist builds first, as usual).pnpm --filter @ag-ui/mastra typecheck— clean.