Skip to content

Stop repeating the model's canvas as the user's next turn - #276

Open
jerelvelarde wants to merge 1 commit into
a2ui-project:mainfrom
jerelvelarde:jerel/copilotkit-snapshot-once
Open

jerelvelarde wants to merge 1 commit into
a2ui-project:mainfrom
jerelvelarde:jerel/copilotkit-snapshot-once

Conversation

@jerelvelarde

Copy link
Copy Markdown
Contributor

The same two prompts on main and on this branch

Watch or download the video

The problem

Since #215, every follow-up prompt carries the canvas the model just produced twice: once as the
model's turn, and again as a user turn in front of the new prompt. submitPrompt calls
StateSync.syncActiveDraftToHistory() before every prompt, and that skips a canvas only when it
matches lastSynchronizedLayout. commitLayoutFromLlm cleared that field after applying the
model's canvas, so the next sync appended the model's own canvas as a user turn. The client merges
consecutive user turns, so the request holds model: [canvas], user: [canvas, prompt].

Both chat panels show the repeat. The plain panel shows a "Canvas Revision Snapshot" bubble between
the reply and the next prompt, and the CopilotKit panel shows a second "N components in this canvas"
card. #216 hid the card in the CopilotKit panel only. This fixes the cause, and #216 drops that
workaround.

The approach

commitLayoutFromLlm now records the model's canvas as the last synchronized layout, sanitized like
every value it's compared with, so the next sync sees nothing new. A canvas the user changes after
the reply still differs from it and is still recorded, including a canvas restored to an earlier
draft. The existing test for that case passes unchanged.

What is not covered

  • If the user edits the canvas after a reply and then edits it back to exactly the model's canvas,
    the history's trailing snapshot is replaced with an identical copy. That's correct, just redundant.

Verification

  • New test in state-sync.spec.ts, "does not record the model canvas again before the next prompt".
    It makes the same calls ChatCoordinator makes (sync, prompt, model reply, commit, sync) and checks
    the history is unchanged. On main it fails with the extra user turn; here it passes.
  • The full shell suite passes: 1,794 tests, with coverage. ESLint and Prettier pass on the changed
    files. The full e2e suite passes: 91 of 91 with CI=1, no retries.
  • The recording runs the same two prompts against main, then this branch, with the e2e Gemini
    fixture. Its captions count the canvas cards in the chat, and the copies of the first reply's
    canvas in the second request the fixture captured: twice on main, once here.

Since a2ui-project#215, ChatCoordinator.submitPrompt calls
StateSync.syncActiveDraftToHistory so each request includes the latest
canvas. But commitLayoutFromLlm cleared lastSynchronizedLayout when it
applied a reply, so the next prompt always appended a user turn holding
the canvas the model had just returned. The model received its own
canvas twice in every follow-up request, and both chat panels showed
it twice: the plain panel as a "Canvas Revision Snapshot" after the
Gemini AI reply, the CopilotKit panel as a second "N components in
this canvas" card.

commitLayoutFromLlm now records the model's canvas as the last
synchronized layout, sanitized like every layout syncLayoutToHistory
compares. A canvas the user changes after the reply, including one
restored to the previous draft, differs from it and is still recorded.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request ensures that an unchanged canvas is not recorded again in the chat history before the next prompt. In StateSync, commitLayoutFromLlm now sets lastSynchronizedLayout to the sanitized layout value instead of null, marking it as already recorded. A unit test has been added to verify this behavior. There are no review comments, and the changes look correct.

This branch has not been deployed

No deployments
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.

1 participant