You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
addToolOutput() doesn't work properly when the chat contains a MESSAGES_SNAPSHOT-type message. If I delete it, I can add output without any problems.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
None
Terms & Code of Conduct
I agree to follow this project's Code of Conduct
I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
Hi, I've been digging into this and reproduced two related breakage modes. Want to confirm the intended fix direction before opening a PR.
Root cause
MESSAGES_SNAPSHOT (processor.tshandleMessagesSnapshotEvent) replaces this.messages with chunk.messages.map(aguiSnapshotMessageToUIMessage). The normalisation in messages.ts maps an AG-UI role: 'tool' snapshot message to a standaloneUIMessage whose only part is a tool-result — it is NOT anchored into the preceding assistant message. So after a snapshot, the assistant message that originally carried the streaming tool-call part is gone, and the tool-result lives in a detached assistant message with no tool-call part.
Repro A — addToolResult silently no-ops (the reported bug)
Stream a client-side tool call (TOOL_CALL_START/ARGS/END -> assistant msg with tool-call part tc-1), then receive a snapshot that re-describes the assistant turn with only content (no toolCalls) plus a separate role: 'tool' message for tc-1. After the snapshot, no message contains a tool-call part with id tc-1, so:
[StreamProcessor] Could not find message with tool call tc-1
and addToolResult('tc-1', ...) no-ops. Removing the snapshot from the stream (the reporter's "if I delete it") leaves the streamed assistant message intact, so addToolResult works — matches the report exactly.
Repro B — duplicate tool-result when both shapes are present
If the snapshot's assistant message does carry toolCalls AND a separate role: 'tool' message exists, addToolResult succeeds but produces two tool-result parts for the same toolCallId (one anchored in the assistant msg, one in the detached assistant msg). convertMessagesToModelMessages dedups the LLM-bound model messages, but the UI array carries the duplicate.
Proposed fix (two options, need your call)
A) Anchor role: 'tool' snapshot messages into the preceding assistant message during aguiSnapshotMessageToUIMessage / handleMessagesSnapshotEvent — mirror what modelMessagesToUIMessages already does for the streaming fan-out. This fixes B and keeps the tool-result attached, but in Repro A it still can't reconstruct the missing tool-call part (the tool wire message only carries toolCallId + content, not name/args), so addToolResult still can't find tc-1.
B) Preserve in-flight tool-call parts across the snapshot. In handleMessagesSnapshotEvent, after normalising the snapshot, re-attach any tool-call parts from the pre-snapshot messages whose id is referenced by a snapshot tool-result (or simply not yet complete and not represented in the snapshot). This fully fixes A but is a bigger change and changes snapshot semantics (snapshot is no longer a pure replacement while client tools are pending).
I can implement either. A is smaller and consistent with the existing fan-out dedup; B is the only thing that actually fixes the reported addToolResult no-op. Which direction do you want? (Or is there a third — e.g. declaring that servers must include toolCalls on snapshot assistant messages and documenting that?)
Activity
NovolineGast commentedon Jun 30, 2026
Hi, I've been digging into this and reproduced two related breakage modes. Want to confirm the intended fix direction before opening a PR.
Root cause
MESSAGES_SNAPSHOT(processor.tshandleMessagesSnapshotEvent) replacesthis.messageswithchunk.messages.map(aguiSnapshotMessageToUIMessage). The normalisation inmessages.tsmaps an AG-UIrole: 'tool'snapshot message to a standaloneUIMessagewhose only part is atool-result— it is NOT anchored into the preceding assistant message. So after a snapshot, the assistant message that originally carried the streamingtool-callpart is gone, and the tool-result lives in a detached assistant message with notool-callpart.Repro A —
addToolResultsilently no-ops (the reported bug)Stream a client-side tool call (
TOOL_CALL_START/ARGS/END-> assistant msg withtool-callparttc-1), then receive a snapshot that re-describes the assistant turn with onlycontent(notoolCalls) plus a separaterole: 'tool'message fortc-1. After the snapshot, no message contains atool-callpart with idtc-1, so:and
addToolResult('tc-1', ...)no-ops. Removing the snapshot from the stream (the reporter's "if I delete it") leaves the streamed assistant message intact, soaddToolResultworks — matches the report exactly.Repro B — duplicate tool-result when both shapes are present
If the snapshot's assistant message does carry
toolCallsAND a separaterole: 'tool'message exists,addToolResultsucceeds but produces twotool-resultparts for the sametoolCallId(one anchored in the assistant msg, one in the detached assistant msg).convertMessagesToModelMessagesdedups the LLM-bound model messages, but the UI array carries the duplicate.Proposed fix (two options, need your call)
A) Anchor
role: 'tool'snapshot messages into the preceding assistant message duringaguiSnapshotMessageToUIMessage/handleMessagesSnapshotEvent— mirror whatmodelMessagesToUIMessagesalready does for the streaming fan-out. This fixes B and keeps the tool-result attached, but in Repro A it still can't reconstruct the missingtool-callpart (thetoolwire message only carriestoolCallId+content, not name/args), soaddToolResultstill can't findtc-1.B) Preserve in-flight tool-call parts across the snapshot. In
handleMessagesSnapshotEvent, after normalising the snapshot, re-attach anytool-callparts from the pre-snapshot messages whoseidis referenced by a snapshottool-result(or simply not yet complete and not represented in the snapshot). This fully fixes A but is a bigger change and changes snapshot semantics (snapshot is no longer a pure replacement while client tools are pending).I can implement either. A is smaller and consistent with the existing fan-out dedup; B is the only thing that actually fixes the reported
addToolResultno-op. Which direction do you want? (Or is there a third — e.g. declaring that servers must includetoolCallson snapshot assistant messages and documenting that?)fix(ai): preserve tool-call metadata across MESSAGES_SNAPSHOT so addT…