Skip to content

Commit 6a452a8

Browse files
committed
fix(ui): use content-level comparison for tail duplicate detection
The previous isTailDuplicate used messageDisplaySignature which only compared text content, causing false positives when two messages had the same text but different content structure (e.g., text-only vs text+canvas). Switch to JSON.stringify comparison of content arrays so messages with different block types or counts are not incorrectly deduplicated. This fixes the upstream test 'keeps repeated assistant final text within the same turn' which expects both a text-only and a text+canvas message to be preserved even when they share the same display text. Signed-off-by: Sebastien Tardif <[email protected]>
1 parent a037c11 commit 6a452a8

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

ui/src/ui/controllers/chat.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,12 +1228,17 @@ function isTailDuplicate(messages: unknown[], candidate: unknown): boolean {
12281228
if (messages.length === 0) {
12291229
return false;
12301230
}
1231-
const candidateSig = messageDisplaySignature(candidate);
1232-
if (!candidateSig) {
1231+
const tail = messages[messages.length - 1];
1232+
if (!tail || !candidate || typeof tail !== "object" || typeof candidate !== "object") {
1233+
return false;
1234+
}
1235+
const tailContent = (tail as { content?: unknown }).content;
1236+
const candidateContent = (candidate as { content?: unknown }).content;
1237+
try {
1238+
return JSON.stringify(tailContent) === JSON.stringify(candidateContent);
1239+
} catch {
12331240
return false;
12341241
}
1235-
const tailSig = messageDisplaySignature(messages[messages.length - 1]);
1236-
return tailSig === candidateSig;
12371242
}
12381243

12391244
export function handleChatEvent(state: ChatState, payload?: ChatEventPayload) {

0 commit comments

Comments
 (0)