Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): stabilize activity backfill ordering
Josué7efc20d6e79b
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useActivityController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useActivityController.test.tsxindex 8f281c874..e35201294 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/useActivityController.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/useActivityController.test.tsx@@ -300,4 +300,48 @@ describe('useActivityController', () => {}))})++ it('prioritizes valid recent activity dates when choosing chats to backfill', async () => {+ const loadMessages = vi.fn(async () => [])+ Object.defineProperty(window, 'clerum', {+ configurable: true,+ value: {+ chat: {+ getIndex: vi.fn(async () => ({ chats: [] })),+ loadMessages,+ backfillCounters: vi.fn().mockResolvedValue(undefined),+ },+ },+ })+ const invalidChats = Array.from({ length: 20 }, (_, index) => ({+ id: `invalid-${index}`,+ title: 'Invalid date',+ createdAt: 'not-a-date',+ updatedAt: 'not-a-date',+ messageCount: 1,+ }))++ renderHook(() =>+ useActivityController({+ selectedAgent: 'agent-a',+ isAuthenticated: true,+ loadMenuData: true,+ chatList: [+ ...invalidChats,+ {+ id: 'valid-recent',+ title: 'Recent',+ createdAt: '2026-07-22T00:00:00.000Z',+ updatedAt: '2026-07-22T00:00:00.000Z',+ messageCount: 1,+ },+ ],+ progressByAgentMessage: EMPTY_PROGRESS,+ agentNames: AGENT_A,+ })+ )++ await waitFor(() => expect(loadMessages).toHaveBeenCalledTimes(20))+ expect(loadMessages).toHaveBeenCalledWith('agent-a', 'valid-recent', 1000, undefined)+ })})diff --git a/desktop-app/ui/src/hooks/domain/useActivityController.ts b/desktop-app/ui/src/hooks/domain/useActivityController.tsindex 8c023b423..96a04ac4a 100644--- a/desktop-app/ui/src/hooks/domain/useActivityController.ts+++ b/desktop-app/ui/src/hooks/domain/useActivityController.ts@@ -15,6 +15,11 @@ interface UseActivityControllerParams {const ACTIVITY_SUMMARY_CHAT_SCAN_LIMIT = 20const ACTIVITY_SUMMARY_MESSAGE_SCAN_LIMIT = 1000+function sortableActivityTimestamp(value: string): number {+ const timestamp = Date.parse(value)+ return Number.isFinite(timestamp) ? timestamp : 0+}+function activityCounterKey(agentRef: string, chatId: string): string {return `${agentRef}\u0000${chatId}`}@@ -102,7 +107,10 @@ export function useActivityController({(chat.errorCount === undefined || chat.toolCallCount === undefined))})- .sort((left, right) => Date.parse(right.updatedAt) - Date.parse(left.updatedAt))+ .sort(+ (left, right) =>+ sortableActivityTimestamp(right.updatedAt) - sortableActivityTimestamp(left.updatedAt)+ ).slice(0, ACTIVITY_SUMMARY_CHAT_SCAN_LIMIT).map(chat => chat.id))