The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): page a deep Archived load in 500-row pages
Teknium8d0f814d2d28
diff --git a/apps/desktop/src/store/sidebar-archive.test.ts b/apps/desktop/src/store/sidebar-archive.test.tsindex f15fc2ab193..e55244cbd85 100644--- a/apps/desktop/src/store/sidebar-archive.test.ts+++ b/apps/desktop/src/store/sidebar-archive.test.ts@@ -17,7 +17,7 @@ vi.mock('@/api/sessions', () => ({listAllProfileSessions}))-const PAGE_SIZE = 200+const PAGE_SIZE = 500const row = (id: string, overrides: Partial<SessionInfo> = {}): SessionInfo =>({@@ -203,23 +203,23 @@ describe('listEveryArchivedSession', () => {})it('paginates until the backend total is loaded', async () => {- const firstPage = Array.from({ length: 200 }, (_, i) => row(`a${i}`))+ const firstPage = Array.from({ length: PAGE_SIZE }, (_, i) => row(`a${i}`))listAllProfileSessions- .mockResolvedValueOnce({ sessions: firstPage, total: 201, limit: 200, offset: 0 })- .mockResolvedValueOnce({ sessions: [row('c')], total: 201, limit: 200, offset: 200 })+ .mockResolvedValueOnce({ sessions: firstPage, total: PAGE_SIZE + 1, limit: PAGE_SIZE, offset: 0 })+ .mockResolvedValueOnce({ sessions: [row('c')], total: PAGE_SIZE + 1, limit: PAGE_SIZE, offset: PAGE_SIZE })await expect(listEveryArchivedSession()).resolves.toEqual([...firstPage, row('c')])- expect(listAllProfileSessions).toHaveBeenNthCalledWith(1, 200, 0, 'only', 'recent', 'all', {}, 0)- expect(listAllProfileSessions).toHaveBeenNthCalledWith(2, 200, 0, 'only', 'recent', 'all', {}, 200)+ expect(listAllProfileSessions).toHaveBeenNthCalledWith(1, PAGE_SIZE, 0, 'only', 'recent', 'all', {}, 0)+ expect(listAllProfileSessions).toHaveBeenNthCalledWith(2, PAGE_SIZE, 0, 'only', 'recent', 'all', {}, PAGE_SIZE)})it('stops on an empty page when profiles changed during pagination', async () => {- const firstPage = Array.from({ length: 200 }, (_, i) => row(`a${i}`))+ const firstPage = Array.from({ length: PAGE_SIZE }, (_, i) => row(`a${i}`))listAllProfileSessions- .mockResolvedValueOnce({ sessions: firstPage, total: 400, limit: 200, offset: 0 })- .mockResolvedValueOnce({ sessions: [], total: 400, limit: 200, offset: 200 })+ .mockResolvedValueOnce({ sessions: firstPage, total: 2 * PAGE_SIZE, limit: PAGE_SIZE, offset: 0 })+ .mockResolvedValueOnce({ sessions: [], total: 2 * PAGE_SIZE, limit: PAGE_SIZE, offset: PAGE_SIZE })await expect(listEveryArchivedSession()).resolves.toEqual(firstPage)expect(listAllProfileSessions).toHaveBeenCalledTimes(2)@@ -232,24 +232,29 @@ describe('listEveryArchivedSession', () => {listAllProfileSessions.mockResolvedValueOnce({sessions: [...page(0, PAGE_SIZE), pinnedRow('pin-x')],- total: 401,+ total: 2 * PAGE_SIZE + 1,limit: PAGE_SIZE,offset: 0}).mockResolvedValueOnce({sessions: [...page(PAGE_SIZE, PAGE_SIZE), pinnedRow('pin-x')],- total: 401,+ total: 2 * PAGE_SIZE + 1,limit: PAGE_SIZE,offset: PAGE_SIZE})- .mockResolvedValueOnce({ sessions: [row('a-400')], total: 401, limit: PAGE_SIZE, offset: 2 * PAGE_SIZE })+ .mockResolvedValueOnce({+ sessions: [row(`a-${2 * PAGE_SIZE}`)],+ total: 2 * PAGE_SIZE + 1,+ limit: PAGE_SIZE,+ offset: 2 * PAGE_SIZE+ })const sessions = await listEveryArchivedSession()- // All 401 archived rows plus the pin — none skipped, pin listed once.- expect(sessions).toHaveLength(402)+ // Every archived row plus the pin — none skipped, pin listed once.+ expect(sessions).toHaveLength(2 * PAGE_SIZE + 2)expect(sessions.filter(s => s.id === 'pin-x')).toHaveLength(1)- expect(sessions.filter(s => s.archived).map(s => s.id)).toContain('a-400')+ expect(sessions.filter(s => s.archived).map(s => s.id)).toContain(`a-${2 * PAGE_SIZE}`)expect(listAllProfileSessions).toHaveBeenNthCalledWith(2, PAGE_SIZE, 0, 'only', 'recent', 'all', {}, PAGE_SIZE)expect(listAllProfileSessions).toHaveBeenNthCalledWith(3, PAGE_SIZE, 0, 'only', 'recent', 'all', {}, 2 * PAGE_SIZE)})@@ -259,7 +264,7 @@ describe('listEveryArchivedSession', () => {// and total counts only archived rows. pages 1-5 are full 200-row windows// each carrying 100 extra pin rows, so the row count crosses 1000 on page// 5 — the loop must still stop on the cursor, not on the inflated count.- const total = 1000+ const total = 5 * PAGE_SIZElet calls = 0listAllProfileSessions.mockImplementation(async (...args: unknown[]) => {const offset = args[6] as number@@ -277,11 +282,29 @@ describe('listEveryArchivedSession', () => {const sessions = await listEveryArchivedSession()- // 5 pages: offset 0,200,400,600,800 — the 6th request is never issued- // because offset 1000 has reached total.+ // 5 pages — the 6th request is never issued because the cursor has+ // reached total.expect(calls).toBe(5)expect(sessions.filter(s => s.archived)).toHaveLength(total)// The 100 distinct pins ride along once each, not once per page.expect(sessions.filter(s => !s.archived)).toHaveLength(100)})++ it('reads a deep archive in backend-sized pages so the merge path re-reads its prefix fewer times', async () => {+ // Review on #140972: the Electron merge path answers each page by reading+ // the whole prefix through offset + limit, so the page size sets how many+ // times that prefix is re-read. 650 archived rows: two requests, not four.+ const total = 650+ listAllProfileSessions.mockImplementation(async (...args: unknown[]) => {+ const [limit, , , , , , offset] = args as [number, number, string, string, string, object, number]++ return { sessions: page(offset, Math.max(0, Math.min(limit, total - offset))), total, limit, offset }+ })++ const sessions = await listEveryArchivedSession()++ expect(sessions).toHaveLength(total)+ expect(listAllProfileSessions).toHaveBeenCalledTimes(2)+ expect(listAllProfileSessions).toHaveBeenNthCalledWith(1, 500, 0, 'only', 'recent', 'all', {}, 0)+ })})diff --git a/apps/desktop/src/store/sidebar-archive.ts b/apps/desktop/src/store/sidebar-archive.tsindex 8457442f5e5..ec9d34f0454 100644--- a/apps/desktop/src/store/sidebar-archive.ts+++ b/apps/desktop/src/store/sidebar-archive.ts@@ -8,7 +8,11 @@ import type { SessionInfo } from '@/types/hermes'import { $sidebarShowArchived } from './layout'import { $sessions } from './session'-const ARCHIVED_FETCH_PAGE_SIZE = 200+// The backend's `/api/profiles/sessions` page cap (`le=500`). The Electron+// merge path (remote profiles, registry gateways) answers every page by+// re-reading the prefix through offset + limit, so fewer, larger pages keep a+// deep archive from re-reading that prefix once per 200 rows.+const ARCHIVED_FETCH_PAGE_SIZE = 500/*** Pages through `archived=only` until every archived row is loaded.