Repository navigation
fix(react-core): collapse duplicate tool-call ids in the message view - #6407
Merged
Merged
Conversation
AG-UI's TOOL_CALL_START handler appends to the parent assistant message's `toolCalls` without checking whether an entry with that id is already present, so whenever a start event is applied twice — which the human-in-the-loop flow triggers when the run syncs after `respond()` — the message carries the same call twice. The second copy has EMPTY arguments, because a start event carries none; the args arrive afterwards as TOOL_CALL_ARGS deltas addressed to the first. Rendering both produced a phantom duplicate card in the transcript (in the banking skin: a second "Open policy exception" with no transaction id or code) plus a React "Encountered two children with the same key" warning, since the call id is the render key in CopilotChatToolCallsView. Verified against a local Intelligence stack that the server emits exactly ONE TOOL_CALL_START for the affected id, so this is client-side state, not a stream defect. React StrictMode is not involved (the demo disables it). Extends the existing deduplicateMessages() — which already collapses duplicate message ids from streaming re-delivery — to also collapse duplicate call ids within a message, preferring whichever copy actually carries arguments. Applied outside the merge branch too, because the duplicate also lands on a message that was never itself duplicated. Returns the original array when there is nothing to collapse, so memoized consumers do not re-render needlessly. Does not change the underlying agent state, which still holds the duplicate; that needs an idempotency guard in the AG-UI start handler. 5 regression tests, verified red before green. Full react-core suite: 1480 passed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
davidmckayv
requested review from
jpr5,
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
August 5, 2026 21:03
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-telegram
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
Contributor
|
Size Change: +1.86 kB (+0.15%) Total Size: 1.22 MB 📦 View Changed
ℹ️ View Unchanged
|
tylerslaton
reviewed
Aug 5, 2026
Contributor
There was a problem hiding this comment.
We do not use changesets. Please remove this.
davidmckayv
force-pushed
the
fix/dedupe-duplicate-tool-call-ids
branch
from
August 5, 2026 21:12
58e4263 to
eee580f
Compare
tylerslaton
approved these changes
Aug 5, 2026
davidmckayv
added a commit
that referenced
this pull request
Aug 5, 2026
…the wire (#6411) Linear: [CPK-7786](https://linear.app/copilotkit/issue/CPK-7786/hitl-continuation-reuses-the-originating-run-id-on-the-wire-breaking) Regression fix. **Nothing from #6296 is reverted** — its goal is kept and moved one layer up. ## What broke #6296 (@rodboev) preserved the logical run id across a HITL resolve by pinning the originating id on the follow-up's agent invocation, correctly fixing #3456 (external tracing saw one logical run split into two halves). Pinning it **on the wire**, though, made the transport treat the follow-up as a resumption of a run it had already finished: - it re-delivered that run's already-applied half, duplicating every tool call on the message — each duplicate carrying **empty arguments**, because a start event has none and the `TOOL_CALL_ARGS` deltas that follow are addressed to the first copy; and - the follow-up's own tool call never reached client state, so its card never rendered. In `reskinnable-demo`'s banking skin that killed teach mode: the agent called `awaitDashboardDemonstration`, the server emitted `TOOL_CALL_START` for it, and the live "Recording your workflow" card never appeared — no REC indicator, no step feed, no "I'm done", so a demonstration could not be finished or saved. ## Evidence - Intelligence event log shows **two `RUN_STARTED`/`RUN_FINISHED` cycles under one run id**, with `TOOL_CALL_START [awaitDashboardDemonstration]` in the second — the server does emit it. - Instrumented `useRenderToolCall`: **never invoked** for that tool, despite its renderer being registered. - Client message state after the click: `assistant tc:["recall_memory","recall_memory"]`, `assistant tc:["offerWorkflowRecording","offerWorkflowRecording"]` — prior cycle re-applied, new call absent. - Bisect: reverting #6296's four source files makes the card appear; restoring them breaks it again. No later commit touches those files. - Ruled out: React StrictMode (disabled in that app), model/prompt/tool-availability differences (byte-identical between the working and broken apps), and the view-layer dedupe from #6407. ## The fix `markNextRunAsContinuation` already accepted an `expectedRunId` that was never used. It now records it, and the state manager re-stamps the continuation's events onto that id. So: - **logical identity is preserved** — state/message association and external tracing still see one run, which is #6296's whole point; - **the wire identifies the invocation honestly** — the follow-up no longer claims to be a run that already finished, so nothing is re-delivered and the continuation's own tool call lands. ## Test changes — please review this part closely `core-follow-up`'s run-id test asserted the *mechanism* (both invocations carry the same wire id), which this deliberately changes. It now asserts the *goal*: the originating id is pinned on the first invocation, and the follow-up leaves the id to the transport. Its sibling assertion — the thread still knows exactly one run — was already there and passes untouched. A new `StateManager` test covers the re-stamp directly, verified **red before green** by dropping the `expectedRunId` lookup (it fails, along with one of #6296's own tests). @rodboev — flagging you directly since this touches your change from today. If the wire-level pinning was load-bearing for something I have not seen, say so and I will rework it. ## Verification - `@copilotkit/core` 58 files and `@copilotkit/react-core` 123 files pass. - In-browser against a live Intelligence stack: before, the recording card never rendered; after, it renders with its REC indicator and I'm done / Cancel controls. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
Follow-up to #6404. That PR stopped the duplicate write from a resurrected approval card; this one removes the duplicate card itself.
Symptom
Approving a HITL card in the banking skin left a second, blank copy of the same card in the transcript — "Open policy exception" with no transaction id and no code — plus a React warning:
Root cause
@ag-ui/client'sTOOL_CALL_STARThandler appends to the parent assistant message'stoolCallswith no check for an existing entry with that id:So when a start event is applied twice — which the HITL flow triggers when the run syncs after
respond()— the message carries the same call twice. The second copy has emptyarguments, because a start event carries none; the args arrive afterwards asTOOL_CALL_ARGSdeltas addressed to the first copy. That empty copy is what rendered as the blank card, andCopilotChatToolCallsViewuses the call id as its render key, hence the warning.Evidence gathered while diagnosing:
toolCalls: ["call_X","call_X"], and the React warning fires on the same id in the same tick.TOOL_CALL_STARTfor that id (oneSTART, oneEND, oneRESULT). So this is client-side state, not a stream defect.reactStrictMode: false.Fix
Extends the existing
deduplicateMessages()— which already collapses duplicate message ids arriving from streaming re-delivery — to also collapse duplicate call ids within a message, preferring whichever copy actually carries arguments.Applied outside the merge branch too, because the duplicate also lands on a message that was never itself duplicated (observed
rawMsgs=5 dedupMsgs=5with the duplicate still present). Returns the original array untouched when there is nothing to collapse, so memoized consumers don't re-render needlessly.Scope / known limitation
This fixes what renders. The underlying agent state still holds the duplicate entry, so a fully correct fix also wants an idempotency guard in the AG-UI start handler (upstream). Filed separately — flagging here so the remaining gap is explicit rather than implied-fixed.
The precise reason a single start event gets applied twice is also still open; the fix is deliberately robust to re-application whatever the trigger.
Verification
@copilotkit/react-coresuite: 1480 passed / 123 files.test,publint,attwgreen for react-core and its dependents.🤖 Generated with Claude Code