Repository navigation
Stop repeating the model's canvas as the user's next turn - #276
Open
jerelvelarde wants to merge 1 commit into
Open
jerelvelarde wants to merge 1 commit into
jerelvelarde wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
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
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.
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.
submitPromptcallsStateSync.syncActiveDraftToHistory()before every prompt, and that skips a canvas only when itmatches
lastSynchronizedLayout.commitLayoutFromLlmcleared that field after applying themodel'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
commitLayoutFromLlmnow records the model's canvas as the last synchronized layout, sanitized likeevery 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
the history's trailing snapshot is replaced with an identical copy. That's correct, just redundant.
Verification
state-sync.spec.ts, "does not record the model canvas again before the next prompt".It makes the same calls
ChatCoordinatormakes (sync, prompt, model reply, commit, sync) and checksthe history is unchanged. On main it fails with the extra user turn; here it passes.
files. The full e2e suite passes: 91 of 91 with
CI=1, no retries.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.