Skip to content

The agent that grows with you

fix(desktop): stop anchoring a backfilled fold on its first part row alone

kshitijk4poorf9829a4887e6
diff --git a/apps/desktop/src/app/chat/transcript-backfill.test.ts b/apps/desktop/src/app/chat/transcript-backfill.test.ts
index 21a5ce67285..2693b68b06b 100644
--- a/apps/desktop/src/app/chat/transcript-backfill.test.ts
+++ b/apps/desktop/src/app/chat/transcript-backfill.test.ts
@@ -175,20 +175,29 @@ describe('mergeOlderTranscriptPage', () => {
const toolCall = { type: 'tool-call', toolCallId: 't1', toolName: 'read_file', args: {} } as unknown as ChatMessage['parts'][number]
it.each([
- { name: 'drops a fold whose every row is already held live', liveParts: [narration, answer], foldParts: [narration, answer], kept: false },
- { name: 'keeps a fold carrying a tool call and unheld narration', liveParts: [answer], foldParts: [toolCall, narration, answer], kept: true }
- ])('$name (#123801)', ({ liveParts, foldParts, kept }) => {
- const live: ChatMessage = { id: 'assistant-stream-1', role: 'assistant', parts: [...liveParts], rowId: 52203 }
- const existing: ChatMessage[] = [chat('prompt', 52200), live]
+ {
+ name: 'drops a fold whose every row is already held live',
+ live: { parts: [narration, answer], rowId: 52203 },
+ foldParts: [narration, answer],
+ expected: ['prompt', 'assistant-stream-1']
+ },
+ {
+ name: 'keeps a fold carrying a tool call and unheld narration',
+ live: { parts: [answer], rowId: 52203 },
+ foldParts: [toolCall, narration, answer],
+ expected: ['prompt', '1770000000000-4-assistant', 'assistant-stream-1']
+ },
+ {
+ name: 'keeps a fold whose first row is held only as a part of another bubble',
+ live: { parts: [narration], rowId: 52202 },
+ foldParts: [narration, answer],
+ expected: ['prompt', '1770000000000-4-assistant', 'assistant-stream-1']
+ }
+ ])('$name (#123801)', ({ live, foldParts, expected }) => {
+ const existing: ChatMessage[] = [chat('prompt', 52200), { id: 'assistant-stream-1', role: 'assistant', ...live, parts: [...live.parts] }]
const fold: ChatMessage = { id: '1770000000000-4-assistant', role: 'assistant', parts: [...foldParts], rowId: 52201 }
- const merged = mergeOlderTranscriptPage(existing, [chat('prompt-refetch', 52200), fold])
-
- if (kept) {
- expect(merged.flatMap(message => message.parts)).toEqual(expect.arrayContaining([toolCall, narration]))
- } else {
- expect(merged).toBe(existing)
- }
+ expect(mergeOlderTranscriptPage(existing, [chat('prompt-refetch', 52200), fold]).map(message => message.id)).toEqual(expected)
})
})
diff --git a/apps/desktop/src/app/chat/transcript-backfill.ts b/apps/desktop/src/app/chat/transcript-backfill.ts
index 16768ea8653..bf613bd8fc4 100644
--- a/apps/desktop/src/app/chat/transcript-backfill.ts
+++ b/apps/desktop/src/app/chat/transcript-backfill.ts
@@ -149,10 +149,6 @@ export function mergeOlderTranscriptPage(existing: ChatMessage[], olderPage: Cha
const anchor =
(message.rowId !== undefined ? existingRowIndices.get(message.rowId) : undefined) ??
existingIdIndices.get(message.id) ??
- // Either side of the match may be a folded part row: a fetched single
- // row already held inside a live fold, or a fetched fold carrying a
- // row the store already holds.
- (message.rowId !== undefined ? existingPartRowIndices.get(message.rowId) : undefined) ??
partRowAnchor(message)
if (anchor === undefined) {