Skip to content

The agent that grows with you

fix(desktop): a live row short of the stored reply keeps the committed bubble

Tekniumd8ddf3fb142f
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/committed-reply.test.ts b/apps/desktop/src/app/session/hooks/use-session-actions/committed-reply.test.ts
index 4f407727d4f..80fb613d320 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/committed-reply.test.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/committed-reply.test.ts
@@ -49,11 +49,22 @@ describe('a re-attach page that commits the reply before its completion', () =>
expect(overlaid.map(message => message.id)).toEqual(['18-user', 'assistant-stream-1-3'])
})
+ // A live row still short of the stored reply may never get its tail (a
+ // completion lost to a reconnect): only the committed bubble holds it all.
+ it('keeps the committed bubble while the live row is still short of it', () => {
+ const baseline = [steer, live('A6 ')]
+ const current = [steer, live('A6 steered')]
+
+ const overlaid = overlayConcurrentMessageChanges(committedPage('change course'), baseline, current)
+
+ expect(assistants(overlaid).map(([id]) => id)).toEqual(['19-assistant', 'assistant-stream-1-3'])
+ })
+
// A page whose newest prompt is not the live row's own is an earlier turn:
// a new reply that happens to open with the same words is not that answer.
it('leaves a page reply that follows another prompt alone', () => {
const baseline = [steer, live('A6 ')]
- const current = [steer, live('A6 steered')]
+ const current = [steer, live('A6 steered answer')]
const overlaid = overlayConcurrentMessageChanges(committedPage('an earlier prompt'), baseline, current)
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/committed-reply.ts b/apps/desktop/src/app/session/hooks/use-session-actions/committed-reply.ts
index b71b4f27af2..8a0466969c3 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/committed-reply.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/committed-reply.ts
@@ -58,8 +58,11 @@ const promptText = (message: ChatMessage | undefined) =>
* the turn: its late deltas and the completion still find it by id, while a
* dropped live row would be re-seeded by the next delta. So it takes the
* committed bubble's place. `committedNew` admits only page bubbles that are
- * new since the baseline and not themselves live, and the bubble must follow
- * the live row's own prompt and end in a reply covering the live text.
+ * new since the baseline and not themselves live; the bubble must follow the
+ * live row's own prompt, end in a reply, and say exactly what the live row
+ * says. A live row still short of the stored text keeps both: its tail may
+ * never arrive (a completion lost to a reconnect), and only the committed
+ * bubble holds the whole reply.
*/
export function pageReplyCommittingLiveRow(
page: ChatMessage[],
@@ -78,13 +81,14 @@ export function pageReplyCommittingLiveRow(
return -1
}
- const snapshot = spokenText(live)
+ const said = spokenText(live).trim()
return page.findIndex(
(message, index) =>
index > pagePrompt &&
message.role === 'assistant' &&
committedNew(message) &&
- committedReplyCovers(message, snapshot)
+ Boolean(replyAfterLastTool(message).trim()) &&
+ spokenText(message).trim() === said
)
}