Skip to content

The agent that grows with you

fix(desktop): count the answer row in a page-boundary fold

kshitijk4poor6668ac14a0a5
diff --git a/apps/desktop/src/lib/chat-messages.test.ts b/apps/desktop/src/lib/chat-messages.test.ts
index defba040555..65aae4043c3 100644
--- a/apps/desktop/src/lib/chat-messages.test.ts
+++ b/apps/desktop/src/lib/chat-messages.test.ts
@@ -1560,4 +1560,25 @@ describe('toChatMessages backend-row accounting', () => {
expect(plain).toHaveLength(1)
expect(plain[0]).not.toHaveProperty('serverRowSpan')
})
+
+ it('counts the current answer row when a page starts on a tool-only turn', () => {
+ // A page boundary can start mid-turn: the first row is the tool-only
+ // assistant, the second its result, and the answer arrives third with no
+ // active bubble to append to. The bubble it creates stands for all three
+ // backend rows — counting only the two pending ones would make the release
+ // rewind short and skip history the reader then cannot reach.
+ const messages = toChatMessages([
+ {
+ role: 'assistant',
+ content: '',
+ timestamp: 1,
+ tool_calls: [{ id: 'tc', function: { name: 'terminal', arguments: '{}' } }]
+ },
+ { role: 'tool', tool_call_id: 'tc', content: 'ok', timestamp: 2 },
+ { role: 'assistant', content: 'Answer.', timestamp: 3 }
+ ])
+
+ expect(messages).toHaveLength(1)
+ expect(messages[0].serverRowSpan).toBe(3)
+ })
})
diff --git a/apps/desktop/src/lib/chat-messages/hydration.ts b/apps/desktop/src/lib/chat-messages/hydration.ts
index a1380148e28..1790a1b9770 100644
--- a/apps/desktop/src/lib/chat-messages/hydration.ts
+++ b/apps/desktop/src/lib/chat-messages/hydration.ts
@@ -465,7 +465,7 @@ export function toChatMessages(messages: SessionMessage[]): ChatMessage[] {
...(message.display_kind === 'process_complete' ? { asyncResultKind: 'process' as const } : {}),
timestamp: earliestTimestamp(message.timestamp, ...parts.map(part => part.timestamp)),
...(rowId !== undefined ? { rowId } : {}),
- ...(pendingAbsorbedRows > 1 ? { serverRowSpan: pendingAbsorbedRows } : {}),
+ ...(pendingAbsorbedRows > 0 ? { serverRowSpan: pendingAbsorbedRows + 1 } : {}),
...(reactions.length ? { reactions } : {}),
...(extractedAttachmentRefs ? { attachmentRefs: extractedAttachmentRefs } : {})
})