Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop): preserve cursor during rate limits

Alfredo Lopez0a2ce67b481f
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/chatListTitleMerge.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/chatListTitleMerge.test.tsx
index 86f93a2a5..7f132dd38 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/chatListTitleMerge.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/chatListTitleMerge.test.tsx
@@ -362,7 +362,7 @@ describe('revoked host catalog protection', () => {
it('clears a rejected load-more cursor after a client-side cursor error', async () => {
clerum.rpc.listSessions.mockImplementation(
async (_agentRef: string, _teamId: string | undefined, query?: { cursor?: string }) => {
- if (query?.cursor) throw new Error('400 Bad Request: invalid cursor')
+ if (query?.cursor) throw new Error('400 Bad Request: Invalid sessions cursor')
return {
...serverSessions([{ agent: 'agent-x', chatId: 'remote-page-1' }]),
nextCursor: 'cursor-invalid',
@@ -383,6 +383,35 @@ describe('revoked host catalog protection', () => {
)
).toHaveLength(1)
})
+
+ it('preserves the load-more cursor during a transient rate limit', async () => {
+ clerum.rpc.listSessions.mockImplementation(
+ async (_agentRef: string, _teamId: string | undefined, query?: { cursor?: string }) => {
+ if (query?.cursor) throw new Error('429 Too Many Requests')
+ return {
+ ...serverSessions([{ agent: 'agent-x', chatId: 'remote-page-1' }]),
+ nextCursor: 'cursor-rate-limited',
+ }
+ }
+ )
+ const controller = renderController()
+
+ await waitFor(() => expect(controller.result.current.chatListHasMoreRemoteSessions).toBe(true))
+ await act(async () => {
+ await controller.result.current.loadMoreChatSessions()
+ })
+ expect(controller.result.current.chatListHasMoreRemoteSessions).toBe(true)
+
+ await act(async () => {
+ await controller.result.current.loadMoreChatSessions()
+ })
+
+ expect(
+ clerum.rpc.listSessions.mock.calls.filter(
+ call => (call[2] as { cursor?: string } | undefined)?.cursor === 'cursor-rate-limited'
+ )
+ ).toHaveLength(2)
+ })
})
describe('host authority verification', () => {
diff --git a/desktop-app/ui/src/hooks/domain/useChatListController.ts b/desktop-app/ui/src/hooks/domain/useChatListController.ts
index 81e270121..7c87b7d66 100644
--- a/desktop-app/ui/src/hooks/domain/useChatListController.ts
+++ b/desktop-app/ui/src/hooks/domain/useChatListController.ts
@@ -149,8 +149,14 @@ const byLastActivityDesc = (a: { lastActivityAt: string }, b: { lastActivityAt:
sortableTimestamp(b.lastActivityAt) - sortableTimestamp(a.lastActivityAt)
function isRecoverableCatalogCursorError(error: unknown): boolean {
- const message = error instanceof Error ? error.message : String(error)
- return /\b4\d\d\b/.test(message) || message.toLowerCase().includes('invalid')
+ const message = (error instanceof Error ? error.message : String(error)).toLowerCase()
+ const status = httpErrorStatus(error)
+ const invalidCursor = /invalid (?:sessions )?cursor/.test(message)
+ if (status === 429) return false
+ if (status !== undefined) {
+ return status === 400 && invalidCursor
+ }
+ return invalidCursor
}
function isCatalogOutageError(error: unknown): boolean {