Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: close remaining desktop reconciliation review gaps
Josuéc21875d47b6f
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.jsonindex 180fa9f38..ecff9fed5 100644--- a/desktop-app/package-lock.json+++ b/desktop-app/package-lock.json@@ -1,12 +1,12 @@{"name": "evenfire",- "version": "0.1.332",+ "version": "0.1.333","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "evenfire",- "version": "0.1.332",+ "version": "0.1.333","license": "MPL-2.0","dependencies": {"@tanstack/react-query": "5.100.10",diff --git a/desktop-app/package.json b/desktop-app/package.jsonindex 60bbb28e1..6bcdd01aa 100644--- a/desktop-app/package.json+++ b/desktop-app/package.json@@ -1,7 +1,7 @@{"name": "evenfire","productName": "Evenfire",- "version": "0.1.332",+ "version": "0.1.333","private": true,"license": "MPL-2.0","description": "Evenfire desktop client for secure agent and workflow access",diff --git a/desktop-app/src/__tests__/chatMessageMerge.test.ts b/desktop-app/src/__tests__/chatMessageMerge.test.tsindex 658831275..422ee48a2 100644--- a/desktop-app/src/__tests__/chatMessageMerge.test.ts+++ b/desktop-app/src/__tests__/chatMessageMerge.test.ts@@ -67,9 +67,94 @@ describe('mergeAuthoritativeServerMessages', () => {timestamp: 100,serverTurnNumber: 3,},- ]+ ],+ { activeTaskIds: new Set(['task-1']) })expect(merged.map(message => message.id)).toEqual(['turn-3-user', 'pending'])})++ it('replaces completed task-backed echoes inside their authoritative turn', () => {+ const merged = mergeAuthoritativeServerMessages(+ [+ {+ id: 'optimistic-user',+ role: 'user',+ content: 'hello',+ timestamp: 1,+ task_id: 'completed-task',+ },+ {+ id: 'optimistic-assistant',+ role: 'assistant',+ content: 'done',+ timestamp: 2,+ task_id: 'completed-task',+ },+ ],+ [+ {+ id: 'turn-4-user',+ role: 'user',+ content: 'hello',+ timestamp: 100,+ serverTurnNumber: 4,+ },+ {+ id: 'turn-4-assistant',+ role: 'assistant',+ content: 'done',+ timestamp: 101,+ serverTurnNumber: 4,+ },+ ]+ )++ expect(merged.map(message => message.id)).toEqual(['turn-4-user', 'turn-4-assistant'])+ expect(merged.every(message => message.task_id === 'completed-task')).toBe(true)+ })++ it('preserves turnless system messages inside an authoritative range', () => {+ const system: ChatMessage = {+ id: 'system-note',+ role: 'system',+ content: 'local diagnostic',+ timestamp: 2,+ }+ const merged = mergeAuthoritativeServerMessages(+ [+ {+ id: 'turn-1-assistant',+ role: 'assistant',+ content: 'first',+ timestamp: 1,+ serverTurnNumber: 1,+ },+ system,+ {+ id: 'turn-3-user',+ role: 'user',+ content: 'third',+ timestamp: 3,+ serverTurnNumber: 3,+ },+ ],+ [+ {+ id: 'turn-2-user',+ role: 'user',+ content: 'second',+ timestamp: 20,+ serverTurnNumber: 2,+ },+ ]+ )++ expect(merged.map(message => message.id)).toEqual([+ 'turn-1-assistant',+ 'system-note',+ 'turn-2-user',+ 'turn-3-user',+ ])+ })})diff --git a/desktop-app/src/__tests__/chatStore.test.ts b/desktop-app/src/__tests__/chatStore.test.tsindex 917d372f5..c34d5800e 100644--- a/desktop-app/src/__tests__/chatStore.test.ts+++ b/desktop-app/src/__tests__/chatStore.test.ts@@ -713,7 +713,7 @@ describe('messages', () => {).toEqual(['m1', 'm2', 'm3'])})- it('keeps unseen and local-only messages when reconciling a bounded server window', async () => {+ it('keeps unseen numbered history while replacing completed local-only echoes', async () => {await store.createChat('agent-1', 'reconcile-upsert')await store.saveMessages('agent-1', 'reconcile-upsert', [{@@ -758,7 +758,7 @@ describe('messages', () => {expect((await store.loadMessages('agent-1', 'reconcile-upsert')).map(message => message.id)- ).toEqual(['turn-1-user', 'local-only', 'turn-2-user', 'turn-2-assistant'])+ ).toEqual(['turn-1-user', 'turn-2-user', 'turn-2-assistant'])})it('repairs a missing page from surviving pages and the compatibility snapshot', async () => {@@ -779,6 +779,11 @@ describe('messages', () => {})))await fs.rm(join(chatPagesDir('missing-page'), '000002.json'))+ const staleIndex = await readJsonFile<{+ chats: Array<{ id: string; messageCount: number }>+ }>(agentPath('index.json'))+ staleIndex.chats.find(chat => chat.id === 'missing-page')!.messageCount = 1+ await fs.writeFile(agentPath('index.json'), JSON.stringify(staleIndex))const restartedStore = new ChatStore(tempDir, {pageSize: 2,@@ -791,6 +796,10 @@ describe('messages', () => {chatMetaPath('missing-page'))expect(repairedMeta.localMessageCount).toBe(6)+ expect(+ (await restartedStore.listChats('agent-1')).find(chat => chat.id === 'missing-page')+ ?.messageCount+ ).toBe(6)})it('adopts a fully written orphan page left by an interrupted append', async () => {@@ -1005,6 +1014,34 @@ describe('messages', () => {expect(compatibility.messages.map(message => message.id)).toEqual(['m1'])})+ it('does not retry an unreadable auxiliary downgrade snapshot on every hot read', async () => {+ await store.createChat('agent-1', 'unreadable-downgrade-snapshot')+ await store.saveMessages('agent-1', 'unreadable-downgrade-snapshot', [+ { id: 'm1', role: 'user', content: 'still durable', timestamp: 1 },+ ])+ const restartedStore = new ChatStore(tempDir)+ const originalReadFile = fs.readFile.bind(fs)+ let compatibilityReadAttempts = 0+ vi.spyOn(fs, 'readFile').mockImplementation(async (...args) => {+ if (String(args[0]) === agentPath('unreadable-downgrade-snapshot.json')) {+ compatibilityReadAttempts += 1+ const error = new Error('permission denied') as NodeJS.ErrnoException+ error.code = 'EACCES'+ throw error+ }+ return originalReadFile(...(args as Parameters<typeof fs.readFile>))+ })++ await expect(+ restartedStore.loadMessages('agent-1', 'unreadable-downgrade-snapshot')+ ).resolves.toHaveLength(1)+ await expect(+ restartedStore.loadMessages('agent-1', 'unreadable-downgrade-snapshot')+ ).resolves.toHaveLength(1)++ expect(compatibilityReadAttempts).toBe(1)+ })+it('does not hide a failed legacy migration as an empty chat', async () => {const agentDir = join(tempDir, 'agent-1')await fs.mkdir(agentDir, { recursive: true })diff --git a/desktop-app/src/chatMessageMerge.ts b/desktop-app/src/chatMessageMerge.tsindex 8a4e295bf..d7b38a4cd 100644--- a/desktop-app/src/chatMessageMerge.ts+++ b/desktop-app/src/chatMessageMerge.ts@@ -23,12 +23,15 @@ function preferredServerMessage(server: ChatMessage, local: ChatMessage | undefi* Replace the authoritative server-turn range as a unit.** Turnless optimistic messages positioned inside that range are paired by role- * and replaced even when content or clocks differ. Unmatched in-flight messages- * remain, while orphaned optimistic messages are evicted.+ * and replaced even when content or clocks differ. Only task IDs explicitly+ * reported as active remain; a persisted task_id alone does not prove liveness+ * because completed local echoes retain it. Orphaned optimistic messages are+ * evicted, while non-turn roles and durable errors remain untouched.*/export function mergeAuthoritativeServerMessages(existing: ChatMessage[],- incoming: ChatMessage[]+ incoming: ChatMessage[],+ options: { activeTaskIds?: ReadonlySet<string> } = {}): ChatMessage[] {const authoritative = incoming.filter(message => messageServerTurnNumber(message) !== undefined)@@ -68,8 +71,12 @@ export function mergeAuthoritativeServerMessages(turn === undefined &&(previousTurns[index] ?? Number.NEGATIVE_INFINITY) < firstTurn &&(nextTurns[index] ?? Number.POSITIVE_INFINITY) >= firstTurn+ const replaceableTurnRole = message.role === 'user' || message.role === 'assistant'+ const belongsToActiveTask =+ message.task_id !== undefined && options.activeTaskIds?.has(message.task_id) === trueconst shouldReplace =- numberedInRange || (turnlessInRange && !message.task_id && !message.isError)+ numberedInRange ||+ (turnlessInRange && replaceableTurnRole && !message.isError && !belongsToActiveTask)if (shouldReplace) {insertionIndex ??= kept.lengthremoved.push(message)diff --git a/desktop-app/src/chatStore.ts b/desktop-app/src/chatStore.tsindex 7a18e0d59..5420cc0d1 100644--- a/desktop-app/src/chatStore.ts+++ b/desktop-app/src/chatStore.ts@@ -494,9 +494,16 @@ export class ChatStore {} catch (error) {if (isRawFilesystemError(error)) {console.warn(`[chatStore] Downgrade snapshot unavailable for ${chatId}:`, error)+ this.compatibilityCheckedKeys.add(compatibilityKey)return meta}- return this.refreshLegacyCompatibilitySnapshotUnlocked(agentRef, chatId, meta)+ const refreshed = await this.refreshLegacyCompatibilitySnapshotUnlocked(+ agentRef,+ chatId,+ meta+ )+ this.compatibilityCheckedKeys.add(compatibilityKey)+ return refreshed}if (!legacyMessages) {const refreshed = await this.refreshLegacyCompatibilitySnapshotUnlocked(@@ -811,6 +818,7 @@ export class ChatStore {await this.writePagedChatUnlocked(agentRef, chatId, recovered, {messageCount: recovered.length,})+ await this.updateIndexedMessageCount(agentRef, chatId, recovered.length)return true}diff --git a/desktop-app/ui/src/hooks/domain/__tests__/pendingChatSelection.characterization.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/pendingChatSelection.characterization.test.tsxindex 5fc51acfc..697053e9f 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/pendingChatSelection.characterization.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/pendingChatSelection.characterization.test.tsx@@ -224,6 +224,17 @@ describe('pendingChatSelection effect', () => {})it('none → selects nothing and clears the spinner', async () => {+ clerum.rpc.listSessions.mockResolvedValue({+ items: [+ {+ agent: 'agent-x',+ chatId: 'must-not-auto-select',+ turnCount: 1,+ messageCount: 2,+ lastActivityAt: '2026-05-01T00:00:00Z',+ },+ ],+ })const { result, rerender } = renderController({ navItem: 'agents' })await settleMount()@@ -235,6 +246,7 @@ describe('pendingChatSelection effect', () => {})await waitFor(() => expect(result.current.chatMessagesLoading).toBe(false))+ await waitFor(() => expect(clerum.rpc.listSessions).toHaveBeenCalled())expect(result.current.activeChatId).toBeNull()})diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.tsindex 8198b130b..1565d88cc 100644--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts@@ -154,9 +154,10 @@ function mergeUniqueMessages(function mergeServerMessages(existing: AgentChatMessage[],- incoming: AgentChatMessage[]+ incoming: AgentChatMessage[],+ activeTaskIds?: ReadonlySet<string>): AgentChatMessage[] {- return mergeAuthoritativeServerMessages(existing, incoming)+ return mergeAuthoritativeServerMessages(existing, incoming, { activeTaskIds })}function sameMessageSequence(a: AgentChatMessage[], b: AgentChatMessage[]): boolean {@@ -913,7 +914,12 @@ export function useAgentChatController({)if (!isStillRelevant()) returnconst older = turnsToChatMessages(response.turns) as AgentChatMessage[]- const merged = mergeServerMessages(chatMessagesRef.current, older)+ const activeTaskId = tracker.get(makeTaskKey(requestAgent, requestChatId))?.taskId+ const merged = mergeServerMessages(+ chatMessagesRef.current,+ older,+ activeTaskId ? new Set([activeTaskId]) : undefined+ )chatMessagesRef.current = mergedsetChatMessages(merged)if (!isStillRelevant()) return@@ -940,6 +946,7 @@ export function useAgentChatController({chatStore.loadSessionMessages,chatStore.replaceMessages,selectedAgent,+ tracker,])// Agent selection → load chats@@ -1333,7 +1340,11 @@ export function useAgentChatController({return { rendered: localMessages, replaced: false, cached: localMessages }}const rendered = localHasServerTurns- ? mergeServerMessages(localMessages, hydratedWithAttachments)+ ? mergeServerMessages(+ localMessages,+ hydratedWithAttachments,+ resp.activeTaskId ? new Set([resp.activeTaskId]) : undefined+ ): hydratedWithAttachmentsif (sameMessageSequence(rendered, localMessages)) {return { rendered: localMessages, replaced: false, cached: localMessages }diff --git a/desktop-app/ui/src/hooks/domain/useChatListController.ts b/desktop-app/ui/src/hooks/domain/useChatListController.tsindex 7c05b3cd7..56e2895b1 100644--- a/desktop-app/ui/src/hooks/domain/useChatListController.ts+++ b/desktop-app/ui/src/hooks/domain/useChatListController.ts@@ -214,11 +214,15 @@ export function useChatListController({})const latestServerSession = serverSessions[0]+ // A mode:none request suppresses this one deferred catalog result. Consume+ // it here, after the post-paint continuation reaches the auto-select gate,+ // instead of clearing it with the synchronous local-index selection.+ const suppressAutoSelection = suppressAutoSelectionByAgentRef.current.delete(agentRef)if (latestServerSession &&host.current?.getActiveChatId() === null &&host.current.shouldAutoSelectLatest() &&- !suppressAutoSelectionByAgentRef.current.has(agentRef)+ !suppressAutoSelection) {void host.current.switchToChat(agentRef, latestServerSession.chatId)}@@ -459,7 +463,6 @@ export function useChatListController({)const clearPendingSelection = useCallback((agentName: string) => {delete pendingChatSelectionByAgentRef.current[agentName]- suppressAutoSelectionByAgentRef.current.delete(agentName)}, [])// ─── Chat CRUD ───diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex a003ab769..65762d649 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.215",+ "version": "0.1.216","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.215",+ "version": "0.1.216","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex fd8da4977..496b24415 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.215",+ "version": "0.1.216","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/server/__tests__/wireProjections.test.ts b/mcp-host/src/server/__tests__/wireProjections.test.tsindex 42206dcc3..5c5ef98c8 100644--- a/mcp-host/src/server/__tests__/wireProjections.test.ts+++ b/mcp-host/src/server/__tests__/wireProjections.test.ts@@ -36,6 +36,7 @@ describe('session pagination projections', () => {key: 'a',})expect(paginateSessionSummaries(entries, 2).nextCursor).toBeUndefined()+ expect(paginateSessionSummaries(entries, undefined)).toEqual({ page: entries })})it('projects bounded message-window navigation consistently', () => {@@ -52,6 +53,27 @@ describe('session pagination projections', () => {hasMoreAfter: true,})})++ it('reports closed boundaries and empty windows without false pagination affordances', () => {+ expect(+ projectMessageWindowBounds(+ [{ number: 1 }, { number: 6 }],+ { firstTurnNumber: 1, lastTurnNumber: 6 },+ {}+ )+ ).toEqual({+ oldestTurnNumber: 1,+ latestTurnNumber: 6,+ hasMoreBefore: false,+ hasMoreAfter: false,+ })+ expect(projectMessageWindowBounds([], {}, {})).toEqual({+ oldestTurnNumber: undefined,+ latestTurnNumber: undefined,+ hasMoreBefore: false,+ hasMoreAfter: false,+ })+ })})function makeConversation(overrides: Partial<Conversation> = {}): Conversation {