Skip to content

fix(reskinnable-demo): collapse HITL approval buttons on the tool result - #6404

Merged
davidmckayv merged 2 commits into
mainfrom
fix/reskinnable-demo-hitl-resolved
Aug 5, 2026
Merged

davidmckayv merged 2 commits into
mainfrom
fix/reskinnable-demo-hitl-resolved

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

Ports the banking demo's #6401 fix, which was never carried over to reskinnable-demo. Found while bringing the demo up against a local Intelligence stack.

The bug

ApprovalButtons collapsed only on local responded state, which dies with the component. These cards do get remounted when the run syncs, which resurrects live Approve/Deny buttons on an action the user already took — a second click fires a duplicate write against an already-settled call.

Reproduced in the banking skin: clicking the "Approve the $15,000 AWS charge" pill and approving the policy exception left a second card carrying live Approve/Deny buttons (with empty args).

The fix

Adds a durable resolved prop, OR-ed with the local state so a click still collapses without waiting for the round trip. It is passed from the tool call itself:

resolved={status === "complete" || !!result}

Applied at the three HITL renders that don't already early-return on status === "complete" (openPolicyException, finalizePolicyException, approveTransaction).

The other three (offerWorkflowRecording, awaitDashboardDemonstration, saveLearnedWorkflow) render their own terminal card when complete, so they never reach the buttons — passing resolved there is both redundant and a type error, since status is narrowed to ToolCallStatus.Executing. That is why banking also has exactly three call sites.

Verification

  • Before: second card had live Approve/Deny. After: it reads "Response submitted."
  • pnpm lint → exit 0
  • pnpm build (the type-check gate) → exit 0

Note: the duplicate card still renders — that comes from a separate pre-existing Encountered two children with the same key warning also present in banking, and is out of scope here. This PR removes the duplicate-write hazard, which is what #6401 addressed.

🤖 Generated with Claude Code

Ports the banking demo's #6401 fix, which was never carried over to this app.

ApprovalButtons collapsed only on local `responded` state, which dies with the
component. These cards do get remounted when the run syncs, which resurrected
live Approve/Deny buttons on an action the user had already taken; clicking
them again fires a duplicate write against an already-settled call.

Adds a durable `resolved` prop, OR-ed with the local state so a click still
collapses without waiting for the round trip. It is passed from the tool call
itself at the three HITL renders that do not already early-return on status
"complete". The other three (offerWorkflowRecording,
awaitDashboardDemonstration, saveLearnedWorkflow) render their own terminal
card when complete, so they never reach the buttons and need nothing — which
is why banking also has exactly three call sites.

Verified against the banking skin in the browser: before, approving a policy
exception left a second card carrying live Approve/Deny; after, that card
reads "Response submitted." `pnpm lint` and `pnpm build` both exit 0.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@davidmckayv
davidmckayv merged commit 8b46745 into main Aug 5, 2026
5 of 10 checks passed
@davidmckayv
davidmckayv deleted the fix/reskinnable-demo-hitl-resolved branch August 5, 2026 19:05
davidmckayv added a commit that referenced this pull request Aug 5, 2026
…#6407)

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:

```
Encountered two children with the same key, call_QHa801k5PL32WtPKsPItO1pI
```

## Root cause

`@ag-ui/client`'s `TOOL_CALL_START` handler appends to the parent
assistant message's `toolCalls` with no check for an existing entry with
that id:

```js
message.toolCalls ??= [];
message.toolCalls.push({ id, type: "function", function: { name, arguments: "" } });
```

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 **empty `arguments`**, because a start event
carries none; the args arrive afterwards as `TOOL_CALL_ARGS` deltas
addressed to the first copy. That empty copy is what rendered as the
blank card, and `CopilotChatToolCallsView` uses the call id as its
render key, hence the warning.

Evidence gathered while diagnosing:

- Instrumented the message view: the offending assistant message ends up
with `toolCalls: ["call_X","call_X"]`, and the React warning fires on
the same id in the same tick.
- Queried a local Intelligence stack: the server emits **exactly one**
`TOOL_CALL_START` for that id (one `START`, one `END`, one `RESULT`). So
this is client-side state, not a stream defect.
- React StrictMode is **not** involved — the demo sets `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=5` with 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

- 5 regression tests added, **verified red before green** (neutered the
fix → 3 failed with "Expected 1, Received 2"; restored → pass).
- Full `@copilotkit/react-core` suite: **1480 passed / 123 files**.
- `test`, `publint`, `attw` green for react-core and its dependents.
- In-browser against a live Intelligence stack: before, approving left a
blank second card + 3 key warnings; after, **one card and zero
warnings**.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants