Skip to content

The agent that grows with you

fix(desktop): fetch the origin page only when the landed page has no user turn

Brooklyn Nicholsonde16f9b06266
diff --git a/apps/desktop/src/app/chat/transcript-backfill.test.ts b/apps/desktop/src/app/chat/transcript-backfill.test.ts
index ab1fef09cf8..547bea622a4 100644
--- a/apps/desktop/src/app/chat/transcript-backfill.test.ts
+++ b/apps/desktop/src/app/chat/transcript-backfill.test.ts
@@ -590,7 +590,7 @@ describe('backfillOlderTranscriptPage', () => {
truncatedTail()
// The last older page: full paging history ends at the first assistant row.
vi.mocked(getOlderSessionMessages).mockResolvedValue({
- messages: [row(10, 'first-assistant')],
+ messages: [{ ...row(10, 'first-assistant'), role: 'assistant' as const }],
pagination: { limit: 120, offset: 120, order: 'latest', returned: 1 },
session_id: 'stored-1'
} as never)
@@ -604,7 +604,7 @@ describe('backfillOlderTranscriptPage', () => {
display_kind: 'hidden',
timestamp: 1
},
- row(10, 'first-assistant')
+ { ...row(10, 'first-assistant'), role: 'assistant' as const }
],
pagination: { limit: 20, offset: 0, order: 'oldest', returned: 2 },
session_id: 'stored-1'
diff --git a/apps/desktop/src/app/chat/transcript-backfill.ts b/apps/desktop/src/app/chat/transcript-backfill.ts
index fa1835a9a6d..52e523007f0 100644
--- a/apps/desktop/src/app/chat/transcript-backfill.ts
+++ b/apps/desktop/src/app/chat/transcript-backfill.ts
@@ -532,16 +532,19 @@ export function backfillOlderTranscriptPage(request: BackfillRequest): Promise<b
// below prepends whatever prefix the store is missing, and the recorded
// state marks the session fully loaded so the REST action retires.
recordTranscriptBackfillPage(storedSessionId, page, profile)
- request.applyOlderPage(toChatMessages(unhideOpeningUserRows(page.messages)))
+ const olderRows = unhideOpeningUserRows(page.messages)
+ request.applyOlderPage(toChatMessages(olderRows))
// #96875: paging can reach the top while the opening USER turn is still
// missing — the durable row is compaction-projected to display_kind=hidden
// (dropped at hydration) or sits before the last reachable `latest` page.
- // Once the tail bookkeeping reports the session fully loaded, fetch the
- // oldest display rows once and prepend any opening user turn the store is
- // still missing. Best-effort: a failure keeps the older page that already
- // landed.
- if (!transcriptTailState(storedSessionId, profile)?.possiblyTruncated) {
+ // Once the tail bookkeeping reports the session fully loaded and the page
+ // that landed carries no user turn, fetch the oldest display rows once and
+ // prepend the opening user turn. Best-effort: a failure keeps the older
+ // page that already landed.
+ const openingTurnLoaded = olderRows.some(message => message.role === 'user' && message.display_kind !== 'hidden')
+
+ if (!openingTurnLoaded && !transcriptTailState(storedSessionId, profile)?.possiblyTruncated) {
try {
const origin = await getSessionMessages(storedSessionId, tail.profile, {
includeCompacted: true,