Skip to content

fix(mastra): keep replay conversion alive on malformed tool-call arguments - #2576

Open
jstar0 wants to merge 1 commit into
ag-ui-protocol:mainfrom
jstar0:fix/2568-mastra-replay-tool-args
Open

fix(mastra): keep replay conversion alive on malformed tool-call arguments#2576
jstar0 wants to merge 1 commit into
ag-ui-protocol:mainfrom
jstar0:fix/2568-mastra-replay-tool-args

Conversation

@jstar0

@jstar0 jstar0 commented Aug 30, 2026

Copy link
Copy Markdown

Fixes #2568

Summary

convertAGUIMessagesToMastra parsed replayed tool-call arguments with a bare JSON.parse. After concurrent runs leave concatenated JSON in in-memory history ({"mine":true}{"mine":true}), every later agent/run on 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

  • New regressions in integrations/mastra/typescript/src/__tests__/message-conversion.test.ts cover 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-toolkit dist builds first, as usual).
  • pnpm --filter @ag-ui/mastra typecheck — clean.

@jstar0
jstar0 requested a review from a team as a code owner August 30, 2026 07:19
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant