Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): drop over-long session cursors and stop treating 408 as terminal
Alfredo Lopeza8e36982c3c5
diff --git a/desktop-app/src/__tests__/rpcProxyClient.test.ts b/desktop-app/src/__tests__/rpcProxyClient.test.tsindex 05796eebf..e4170c873 100644--- a/desktop-app/src/__tests__/rpcProxyClient.test.ts+++ b/desktop-app/src/__tests__/rpcProxyClient.test.ts@@ -215,6 +215,47 @@ describe('RpcProxyClient.listSessions', () => {})})+ // R3-L10: the `rpc:listSessions` IPC handler refuses a cursor longer than+ // 2048 characters, so a page cursor that long must never reach the renderer.+ it.each([+ [2048, true],+ [3000, false],+ ])('keeps a %s-character nextCursor only within the IPC cursor limit', async (length, kept) => {+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)+ const nextCursor = 'c'.repeat(length)+ vi.stubGlobal(+ 'fetch',+ vi.fn().mockResolvedValue({+ ok: true,+ json: async () => ({+ items: [+ {+ agent: 'agent-a',+ chatId: 'chat-a',+ turnCount: 1,+ lastActivityAt: '2026-01-01T00:00:00.000Z',+ },+ ],+ nextCursor,+ }),+ })+ )++ const result = await client.listSessions('token', 'host')++ // Witness: the page itself is still delivered in both cases.+ expect(result.items.map(item => item.chatId)).toEqual(['chat-a'])+ expect(result.nextCursor).toBe(kept ? nextCursor : undefined)+ if (kept) {+ expect(warn).not.toHaveBeenCalled()+ } else {+ expect(warn).toHaveBeenCalledTimes(1)+ const logged = warn.mock.calls[0].map(String).join(' ')+ expect(logged).toContain(String(length))+ expect(logged).not.toContain('ccc')+ }+ })+it('keeps valid catalog entries when one item is malformed and omits unknown states', async () => {vi.stubGlobal('fetch',diff --git a/desktop-app/src/rpcProxyClient.ts b/desktop-app/src/rpcProxyClient.tsindex 6d0ea772a..45c60dba0 100644--- a/desktop-app/src/rpcProxyClient.ts+++ b/desktop-app/src/rpcProxyClient.ts@@ -168,6 +168,12 @@ function parseToolSteps(value: unknown, label: string): MessageToolStep[] {})}+/**+ * Longest sessions cursor the `rpc:listSessions` IPC handler accepts+ * (`sanitizeSessionsListQuery` in `ipc.ts`; mcp-host enforces the same bound).+ */+const SESSIONS_CURSOR_MAX_LENGTH = 2048+// Exported for tests: renderer/parser tests derive their fixtures from the real// producer (pr-discipline T1) instead of hand-mocking the parsed shape.export function parseSessionsListResult(value: unknown): SessionsListResult {@@ -250,12 +256,24 @@ export function parseSessionsListResult(value: unknown): SessionsListResult {}})if (record.items.length > 0 && items.length === 0 && firstItemError) throw firstItemError+ const nextCursor =+ record.nextCursor != null+ ? wireString(record.nextCursor, 'sessions response.nextCursor')+ : undefined+ // R3-L10: the `rpc:listSessions` IPC handler refuses a longer cursor before+ // any request, so handing one to the renderer would only produce a status-less+ // error on "Load more". End the page chain here instead. The cursor is opaque+ // upstream state: log its length only, never its value.+ const cursorTooLong = nextCursor !== undefined && nextCursor.length > SESSIONS_CURSOR_MAX_LENGTH+ if (cursorTooLong) {+ console.warn(+ `[RpcProxyClient] Dropped a sessions nextCursor of ${nextCursor.length} characters (limit ${SESSIONS_CURSOR_MAX_LENGTH})`+ )+ }return {items,...(droppedItemCount > 0 ? { droppedItemCount } : {}),- ...(record.nextCursor != null- ? { nextCursor: wireString(record.nextCursor, 'sessions response.nextCursor') }- : {}),+ ...(nextCursor !== undefined && !cursorTooLong ? { nextCursor } : {}),}}diff --git a/desktop-app/ui/src/hooks/domain/__tests__/chatListTitleMerge.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/chatListTitleMerge.test.tsxindex d4e7ff41b..de8f0522f 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/chatListTitleMerge.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/chatListTitleMerge.test.tsx@@ -23,6 +23,7 @@ import {ipcHostWaking,ipcHttpError,ipcServerErrorMentioning403,+ wrapLikeElectronIpc,} from './__fixtures__/ipcErrors'import { type MockClerum, installMockClerum, uninstallMockClerum } from './__fixtures__/mockClerum'@@ -453,9 +454,45 @@ describe('revoked host catalog protection', () => {)})- // NEW-dui-2: 429 and 5xx keep the cursor, tell the user once per attempt and- // never retry on their own.+ // R3-L10: the main process validates the cursor before any request and throws+ // without an HTTP status (`ipc.ts` sanitizeSessionsListQuery). Re-sending the+ // same cursor repeats that refusal, so it ends the page chain like a 400.+ it('clears a load-more cursor the main process refuses without an HTTP status', async () => {+ const rejection = wrapLikeElectronIpc('rpc:listSessions', new Error('Invalid sessions cursor'))+ expect(httpErrorStatus(rejection)).toBeUndefined()+ clerum.rpc.listSessions.mockImplementation(+ async (_agentRef: string, _teamId: string | undefined, query?: { cursor?: string }) => {+ if (query?.cursor) throw rejection+ return serverSessions([{ agent: 'agent-x', chatId: 'remote-page-1' }], 'cursor-refused')+ }+ )+ const controller = renderController()++ await waitFor(() => expect(controller.result.current.chatListHasMoreRemoteSessions).toBe(true))+ await act(async () => {+ await controller.result.current.loadMoreChatSessions()+ })+ await act(async () => {+ await controller.result.current.loadMoreChatSessions()+ })++ // Witness: the refused cursor was sent exactly once.+ expect(+ clerum.rpc.listSessions.mock.calls.filter(+ call => (call[2] as { cursor?: string } | undefined)?.cursor === 'cursor-refused'+ )+ ).toHaveLength(1)+ expect(controller.result.current.chatListHasMoreRemoteSessions).toBe(false)+ expect(controller.spies.pushToast).not.toHaveBeenCalledWith(+ expect.stringContaining("Couldn't load more chats"),+ 'info'+ )+ })++ // NEW-dui-2: 408, 429 and 5xx keep the cursor, tell the user once per attempt+ // and never retry on their own. A 408 is retryable (RFC 9110 §15.5.9).it.each([+ [408, 'Request Timeout'],[429, 'Too Many Requests'],[503, 'Service Unavailable'],])('preserves the load-more cursor after a retryable %s', async (status, statusText) => {diff --git a/desktop-app/ui/src/hooks/domain/useChatListController.ts b/desktop-app/ui/src/hooks/domain/useChatListController.tsindex c29050904..154f4f3f9 100644--- a/desktop-app/ui/src/hooks/domain/useChatListController.ts+++ b/desktop-app/ui/src/hooks/domain/useChatListController.ts@@ -16,6 +16,7 @@ import {isConfirmedHostAccessRevoked,isHostAvailabilityError,isHttpServerError,+ isInvalidSessionsCursorError,isNetworkError,} from '../../lib/format'import { scheduleAfterFirstPaint } from '../scheduleAfterFirstPaint'@@ -153,18 +154,20 @@ const byLastActivityDesc = (a: { lastActivityAt: string }, b: { lastActivityAt:/*** A load-more failure the same cursor can never recover from: any client error- * other than an authorization status (handled as authority) or a rate limit- * (retryable). Re-sending the cursor after a 400/404/409/410 only repeats the- * rejection, so the page chain ends here.+ * other than an authorization status (handled as authority), a request timeout+ * or a rate limit (both retryable, RFC 9110), plus the main process's own+ * status-less cursor refusal. Re-sending the cursor after a 400/404/409/410+ * only repeats the rejection, so the page chain ends here.*/function isTerminalCatalogCursorError(error: unknown): boolean {const status = httpErrorStatus(error)+ if (status === undefined) return isInvalidSessionsCursorError(error)return (- status !== undefined &&status >= 400 &&status < 500 &&status !== 401 &&status !== 403 &&+ status !== 408 &&status !== 429)}diff --git a/desktop-app/ui/src/lib/format.ts b/desktop-app/ui/src/lib/format.tsindex cee2abde4..e2163e33b 100644--- a/desktop-app/ui/src/lib/format.ts+++ b/desktop-app/ui/src/lib/format.ts@@ -225,6 +225,18 @@ export function isAuthorizationError(err: unknown): boolean {return status === 401 || status === 403}+/**+ * The main process refused a sessions cursor before issuing any request+ * (`sanitizeSessionsListQuery` in `ipc.ts`). That refusal carries no HTTP+ * status, only its fixed message behind the IPC wrapper.+ */+export function isInvalidSessionsCursorError(err: unknown): boolean {+ return (+ httpErrorStatus(err) === undefined &&+ /(?:^|error: )invalid sessions cursor$/.test(errorText(err))+ )+}+export function isHttp403(err: unknown): boolean {return httpErrorStatus(err) === 403}