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
{{ message }}
Repository navigation
fix(react-core): keep all tool calls when merging duplicate messages - #8408
Fixes the remaining half of #3644: when two copies of an assistant message share an id, the chat view dropped the tool calls held only by the earlier copy. The original cause was in @ag-ui/client: up to 0.0.51, TOOL_CALL_START attached a tool call to its parent only if the parent was the last message. A TOOL_CALL_RESULT between two tool calls for the same parent therefore created a second assistant message with the same id. Upstream fixed this in 0.0.52 (2026-04-08), and CopilotKit has used a fixed version since a5c1137465. I reproduced the reporter's event sequence against an old and a current client to confirm this.
deduplicateMessages in CopilotChatMessageView.tsx already merges duplicate assistant messages (it recovers wiped content and undefined toolCalls), but when both copies had tool calls it kept only the later copy's list. For the reporter's sequence — [tool_a, tool_b] on the first copy and [tool_c] on the second — only tool_c rendered. Duplicates can still reach the view from older clients, custom agents, or stored history.
When both copies carry tool calls, deduplicateMessages now keeps the calls from both. The existing rules are unchanged: undefined recovers the earlier list, and an explicit [] is kept.
A new mergeToolCalls helper combines the lists: for a tool call in both copies, a later copy with arguments wins, and a blank copy never replaces a populated one. dedupeToolCalls is unchanged, so within a single message the first populated copy still wins (TOOL_CALL_ARGS deltas go to the first copy).
Moved the deduplicateMessages doc comment back above its function; an earlier change had placed dedupeToolCalls between them.
Four new deduplicateMessages tests: the reporter's scenario (all three tool calls survive and the content is kept), a blank later copy does not replace a populated one, a later populated copy wins when both are populated, and within one message a complete copy is kept over a stale later copy.
This builds on #4059, which proposed combining the lists but merged shared ids with "later wins". As noted when #4058 was closed, the blank copy of a duplicated tool call usually arrives second, so this PR keeps the existing "prefer the populated copy" protection.
If the PR changes or adds functionality, I have updated the relevant documentation
If the PR contains a breaking change, the title has ! (for example feat(react-core)!: ...) and the description has a BREAKING CHANGE: line with migration steps. See VERSIONING.md
"Allow edits by maintainers" is checked (lets us help iterate on your PR directly — faster turnaround for everyone)
deduplicateMessages merged two copies of an assistant message by taking
the later copy's toolCalls, so tool calls held only by the earlier copy
were dropped from the chat. When both copies carry tool calls, keep the
calls from both. dedupeToolCalls now lets a populated copy replace an
earlier one, while a blank copy still never replaces a populated one,
so merged streaming updates keep their freshest arguments.
Also moves the deduplicateMessages doc comment back above its function.
FixesCopilotKit#3644
Co-Authored-By: Claude Opus 5.5 <[email protected]>
No actionable comments were generated in the recent review.
Walkthrough
Duplicate assistant messages now merge tool calls by ID when both messages contain calls. Populated arguments are preserved over blank copies. Tests cover duplicate IDs within a message and across duplicate messages.
Changes: Assistant Message Merge
Layer / File(s)
Summary
Merge and deduplicate tool calls packages/react-core/src/v2/components/chat/CopilotChatMessageView.tsx, packages/react-core/src/v2/components/chat/__tests__/CopilotChatMessageView.test.tsx
Duplicate assistant messages merge tool calls by ID when both contain calls. A later call replaces an earlier one only when it has arguments or the earlier call has none. Tests cover within-message duplicates and merges across assistant messages.
This change keeps tool calls from both copies of a duplicate assistant message, so none are lost in the chat view. The change is localized and has test coverage, and no merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: tool calls from duplicate messages are now kept instead of being discarded. The changeset modifies deduplicateMessages in CopilotChatMessageView.tsx to merge tool call…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check
Explanation
The title names the main change: tool calls from duplicate messages are now kept instead of being discarded. The changeset modifies deduplicateMessages in CopilotChatMessageView.tsx to merge tool calls by ID across duplicate assistant-message occurrences, and adds tests for this behavior. The title is specific, follows the conventional commit format, and reflects the primary fix.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
370-370: Major · Functional Correctness · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Keep first-match precedence within a single message.
For restored tool calls [tc-1, tc-1] with arguments '{"symptom":', TOOL_CALL_ARGS in @ag-ui/client 1.0.2 updates only the first entry. After delta '"headache"}', the first entry is complete, but the second remains partial. (raw.githubusercontent.com)
Line 370 selects that stale second entry because its arguments are nonempty. The single-message normalization path therefore discards completed arguments.
Keep first-populated selection within each message occurrence. Apply later-occurrence precedence only when merging distinct occurrences. Add a regression case where streaming advances the first duplicate.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
TOOL_CALL_ARGS deltas go to the first copy of a tool call id, so within
one message a later copy can hold stale partial arguments. Restore the
original dedupeToolCalls rule (first populated copy wins) and apply
later-copy precedence only when merging separate occurrences, through a
new mergeToolCalls helper.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
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.
What does this PR do?
Fixes the remaining half of #3644: when two copies of an assistant message share an id, the chat view dropped the tool calls held only by the earlier copy. The original cause was in
@ag-ui/client: up to 0.0.51,TOOL_CALL_STARTattached a tool call to its parent only if the parent was the last message. ATOOL_CALL_RESULTbetween two tool calls for the same parent therefore created a second assistant message with the same id. Upstream fixed this in 0.0.52 (2026-04-08), and CopilotKit has used a fixed version sincea5c1137465. I reproduced the reporter's event sequence against an old and a current client to confirm this.deduplicateMessagesinCopilotChatMessageView.tsxalready merges duplicate assistant messages (it recovers wiped content andundefinedtoolCalls), but when both copies had tool calls it kept only the later copy's list. For the reporter's sequence —[tool_a, tool_b]on the first copy and[tool_c]on the second — onlytool_crendered. Duplicates can still reach the view from older clients, custom agents, or stored history.deduplicateMessagesnow keeps the calls from both. The existing rules are unchanged:undefinedrecovers the earlier list, and an explicit[]is kept.deduplicateMessagesdoc comment back above its function; an earlier change had placeddedupeToolCallsbetween them.This builds on #4059, which proposed combining the lists but merged shared ids with "later wins". As noted when #4058 was closed, the blank copy of a duplicated tool call usually arrives second, so this PR keeps the existing "prefer the populated copy" protection.
Related PRs and Issues
CopilotChatToolCallsViewproduces React duplicate-key warning whenconnect()replays historic tool call events over pre-populated message state #3928Checklist
!(for examplefeat(react-core)!: ...) and the description has aBREAKING CHANGE:line with migration steps. See VERSIONING.md