Skip to content

fix(react-core): invalidate messages memo for activity object content - #6325

Merged
BenTaylorDev merged 4 commits into
CopilotKit:mainfrom
seanxuu:fix/react-core-activity-contentkey-memo
Aug 10, 2026
Merged

BenTaylorDev merged 4 commits into
CopilotKit:mainfrom
seanxuu:fix/react-core-activity-contentkey-memo

Conversation

@seanxuu

@seanxuu seanxuu commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • CopilotChat fingerprints messages for useMemo with contentKey = 0 for any non-string / non-array content.
  • ACTIVITY_SNAPSHOT updates often keep the same messageId and only replace object content (progress / generative UI). That left activity renderers stuck on the first frame until some other list change forced a refresh.
  • Include JSON.stringify(m.content) for object content in the fingerprint. Multimodal attachments remain on the array-length branch, so this does not reintroduce base64 serialization for user uploads.
  • Add a regression test that replaces the same activity messageId and asserts the UI updates.

Test plan

  • nx run @copilotkit/react-core:test (or the package's activity e2e suite)
  • Manual: stream repeated ACTIVITY_SNAPSHOT with the same messageId + replace: true and confirm custom activity renderers update each frame

Made with Cursor

ACTIVITY_SNAPSHOT replace updates keep the same message id while mutating
object content. The messages memo fingerprint used contentKey=0 for any
non-string/non-array content, so generative-UI and progress activity
renderers stayed on the first frame until some other message list change
forced a refresh.

Serialize object content in the fingerprint (multimodal attachments remain
on the array length branch) and add a regression test for same-id replaces.
@pkg-pr-new

pkg-pr-new Bot commented Aug 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@copilotkit/a2ui-renderer

pnpm add https://pkg.pr.new/@copilotkit/a2ui-renderer@6325

@copilotkit/agentcore-runner

pnpm add https://pkg.pr.new/@copilotkit/agentcore-runner@6325

@copilotkit/angular

pnpm add https://pkg.pr.new/@copilotkit/angular@6325

@copilotkit/channels

pnpm add https://pkg.pr.new/@copilotkit/channels@6325

@copilotkit/channels-core

pnpm add https://pkg.pr.new/@copilotkit/channels-core@6325

@copilotkit/channels-discord

pnpm add https://pkg.pr.new/@copilotkit/channels-discord@6325

@copilotkit/channels-intelligence

pnpm add https://pkg.pr.new/@copilotkit/channels-intelligence@6325

@copilotkit/channels-slack

pnpm add https://pkg.pr.new/@copilotkit/channels-slack@6325

@copilotkit/channels-teams

pnpm add https://pkg.pr.new/@copilotkit/channels-teams@6325

@copilotkit/channels-telegram

pnpm add https://pkg.pr.new/@copilotkit/channels-telegram@6325

@copilotkit/channels-ui

pnpm add https://pkg.pr.new/@copilotkit/channels-ui@6325

@copilotkit/channels-whatsapp

pnpm add https://pkg.pr.new/@copilotkit/channels-whatsapp@6325

@copilotkit/core

pnpm add https://pkg.pr.new/@copilotkit/core@6325

@copilotkit/react-core

pnpm add https://pkg.pr.new/@copilotkit/react-core@6325

@copilotkit/react-native

pnpm add https://pkg.pr.new/@copilotkit/react-native@6325

@copilotkit/react-textarea

pnpm add https://pkg.pr.new/@copilotkit/react-textarea@6325

@copilotkit/react-ui

pnpm add https://pkg.pr.new/@copilotkit/react-ui@6325

@copilotkit/runtime

pnpm add https://pkg.pr.new/@copilotkit/runtime@6325

@copilotkit/runtime-client-gql

pnpm add https://pkg.pr.new/@copilotkit/runtime-client-gql@6325

@copilotkit/sdk-js

pnpm add https://pkg.pr.new/@copilotkit/sdk-js@6325

@copilotkit/shared

pnpm add https://pkg.pr.new/@copilotkit/shared@6325

@copilotkit/sqlite-runner

pnpm add https://pkg.pr.new/@copilotkit/sqlite-runner@6325

@copilotkit/voice

pnpm add https://pkg.pr.new/@copilotkit/voice@6325

@copilotkit/vue

pnpm add https://pkg.pr.new/@copilotkit/vue@6325

@copilotkit/web-components

pnpm add https://pkg.pr.new/@copilotkit/web-components@6325

@copilotkit/web-inspector

pnpm add https://pkg.pr.new/@copilotkit/web-inspector@6325

commit: 35502a5

@BenTaylorDev BenTaylorDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against current main. The 0 fallback at CopilotChat.tsx:985-990 is real, and worth noting it was only ever reachable for activity messages — in @ag-ui/[email protected] that's the one role whose content is a Record<string, any>; every other role is a string or an array. So this targets exactly the affected case, and the claim that multimodal attachments stay on the array-length branch holds.

I confirmed the regression test earns its keep: reverting only CopilotChat.tsx to main and keeping the test fails with expected 'Working on your request' to be 'Understanding your request' — the frozen first frame from the issue. With the fix, green.

Two things I checked before worrying about them out loud:

  • JSON.stringify throwing on a cycle in render. Not reachable — activity content is zod-parsed from wire JSON, so it's acyclic.
  • Serialization cost per render. Measured: 0.0006 ms at 500 B, 0.005 ms at 4.7 KB, 0.039 ms at 47 KB. Negligible against a memo that otherwise freezes the UI.

contentKey appears at this one site only, so nothing else needs the same treatment. tsc --noEmit clean, and CI is green across the matrix.

I bless the code with a glad heart.

@BenTaylorDev
BenTaylorDev merged commit 7a474da into CopilotKit:main Aug 10, 2026
37 checks passed
mxmzb added a commit that referenced this pull request Aug 13, 2026
`messagesFingerprint`'s content key collapsed every object to 0, so an
in-place content replacement that kept the same message id was invisible to
every memo derived from it. Its comment claimed to mirror react-core's
`messagesMemoKey`, which stopped being true when react-core #6325
(de0a659) taught that key to serialize object content.

Serialize object content here too, keeping the length-not-value treatment for
string and array content so large text and base64 attachment payloads are
still never re-serialized per render. Serialization is guarded: the
fingerprint runs on every render and `JSON.stringify` throws on a circular
structure, which this component is already required to tolerate (see the
existing "does not throw on tool content that cannot be JSON-serialised"
assertion) — react-core stringifies unguarded, so the guard is a deliberate
and documented divergence.

Not a live stale-render bug via the activity path: same-id object content
comes from an ACTIVITY_SNAPSHOT replace, and `role: "activity"` never reaches
`listItems`, which builds rows for `user` and `assistant` only. Object content
DOES reach a renderer through the `role: "tool"` correlation, though, which is
what the added test drives: an object tool result replaced in place used to
leave the renderer showing the first object's serialization.

The comment no longer claims to mirror a moving target — it records what the
key captures, why the object branch exists, and that the two implementations
are independent.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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