Skip to content

The agent that grows with you

fix(desktop): retire "Show earlier" when the complete index lists no prompt before the window

teknium1cdc503420937
diff --git a/apps/desktop/src/app/chat/history-window.test.tsx b/apps/desktop/src/app/chat/history-window.test.tsx
index 7ef349d23e3..71b6a8080ec 100644
--- a/apps/desktop/src/app/chat/history-window.test.tsx
+++ b/apps/desktop/src/app/chat/history-window.test.tsx
@@ -182,6 +182,7 @@ describe('paging earlier from an open history window', () => {
.mockResolvedValueOnce(page(4000))
.mockResolvedValueOnce(index([3880, 4000]))
.mockResolvedValueOnce({ ...page(3880), pagination: { ...page(3880).pagination, has_older: false } })
+
const mounted = mount()
const live = mounted.view.$messages.get()
@@ -231,17 +232,25 @@ describe('paging earlier from an open history window', () => {
expect(beforePrepend).not.toHaveBeenCalled()
})
- it('still retires the entry point when the open window starts at the session top', async () => {
- const api = vi.spyOn(window.hermesDesktop, 'api').mockResolvedValue({
- ...page(1),
- pagination: { ...page(1).pagination, has_older: false }
- })
- const mounted = mount()
+ it('retires the entry point when the complete index lists no prompt before the window', async () => {
+ const api = vi
+ .spyOn(window.hermesDesktop, 'api')
+ // The backend counts rows before this page, but none of them is a prompt mark.
+ .mockResolvedValueOnce(page(4000))
+ .mockResolvedValueOnce(index([4000]))
- await act(async () => { await mounted.window.revealRow(1, new AbortController().signal) })
+ const mounted = mount('stored-unlisted')
+
+ await act(async () => { await mounted.window.revealRow(4000, new AbortController().signal) })
+ expect(mounted.window.olderAvailable).toBe(true)
+
+ let grew = true
+ await act(async () => { grew = (await mounted.window.expandWindow()) === true })
+ expect(grew).toBe(false)
+ // No page can ever arrive: stop offering one instead of failing forever.
expect(mounted.window.olderAvailable).toBe(false)
+ expect(mounted.window.currentMessages?.[0]?.rowId).toBe(4000)
expect(await mounted.window.expandWindow()).toBe(false)
- // Nothing older to walk to: the lookup never even reaches the backend.
- expect(api).toHaveBeenCalledTimes(1)
+ expect(api).toHaveBeenCalledTimes(2)
})
})
diff --git a/apps/desktop/src/app/chat/history-window.ts b/apps/desktop/src/app/chat/history-window.ts
index 1007a4a3767..41aeb7ac3cf 100644
--- a/apps/desktop/src/app/chat/history-window.ts
+++ b/apps/desktop/src/app/chat/history-window.ts
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { capabilityScoped, hermesApi, type ProfileScope } from '@/api/client'
-import { previousPromptRowId } from '@/components/assistant-ui/thread/timeline-index'
+import { cachedTimelineIndex, previousPromptRowId, timelineIndexKey } from '@/components/assistant-ui/thread/timeline-index'
import { type ChatMessage, toChatMessages } from '@/lib/chat-messages'
import type { SessionMessagesResponse } from '@/types/hermes'
@@ -162,6 +162,20 @@ export function useHistoryWindow({ scopeKey, storedId, scope, isCurrent }: Histo
const rowId = await previousPromptRowId(captured.storedId, captured.scope, anchor)
if (rowId === null || controller.signal.aborted) {
+ // A complete index that lists no prompt before this window means the
+ // backend's older rows can never be paged to: retire the offer so the
+ // button and the top-edge auto-page stop promising a page that never
+ // arrives. An incomplete index still leaves the page untouched for a retry.
+ if (
+ rowId === null &&
+ anchor !== undefined &&
+ !controller.signal.aborted &&
+ latest.current.page === current &&
+ cachedTimelineIndex(timelineIndexKey(captured.storedId, captured.scope))?.complete
+ ) {
+ setSelection({ lifetime: captured.lifetime, page: { ...current, olderAvailable: false } })
+ }
+
return false
}
diff --git a/apps/desktop/src/components/assistant-ui/thread/timeline-index.test.ts b/apps/desktop/src/components/assistant-ui/thread/timeline-index.test.ts
index 7529ce4e03b..ca7706feb33 100644
--- a/apps/desktop/src/components/assistant-ui/thread/timeline-index.test.ts
+++ b/apps/desktop/src/components/assistant-ui/thread/timeline-index.test.ts
@@ -66,7 +66,7 @@ describe('timeline metadata index', () => {
expect((await fetchTimelineIndex('session', 'default')).complete).toBe(true)
})
- it('names the mark before an anchor, paging the index once while it cannot cover it', async () => {
+ it('names the mark before an anchor, paging a partial index only as far as one lookup may', async () => {
api
.mockResolvedValueOnce({
entries: [{ row_id: 10, preview: 'Prompt 10' }, { row_id: 20, preview: 'Prompt 20' }],
@@ -76,6 +76,7 @@ describe('timeline metadata index', () => {
entries: [{ row_id: 30, preview: 'Prompt 30' }, { row_id: 40, preview: 'Prompt 40' }],
pagination: { next_cursor: null, has_more: false }
})
+ .mockResolvedValue(page(1, true))
const { previousPromptRowId } = await import('./timeline-index')
// The anchor sits past the first page; the lookup advances the shared index.
@@ -88,15 +89,9 @@ describe('timeline metadata index', () => {
expect(await previousPromptRowId('session', 'default', 10)).toBeNull()
expect(await previousPromptRowId('session', 'default', undefined)).toBeNull()
expect(api).toHaveBeenCalledTimes(2)
- })
-
- it('bounds how far one lookup pages a partially loaded index', async () => {
- api.mockResolvedValue(page(1, true))
- const { previousPromptRowId } = await import('./timeline-index')
-
- // The anchor is never covered and the index never completes: the lookup
+ // A session whose index never completes nor covers the anchor: the lookup
// stops at its per-lookup ceiling instead of walking the whole session.
- expect(await previousPromptRowId('session', 'default', 99_999)).toBe(1)
- expect(api).toHaveBeenCalledTimes(3)
+ expect(await previousPromptRowId('endless', 'default', 99_999)).toBe(1)
+ expect(api).toHaveBeenCalledTimes(5)
})
})