Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-ui): r6-l2 suppress superseded notification feedback
Josuéaf10cfce3047
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/notificationSwitchErrors.characterization.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/notificationSwitchErrors.characterization.test.tsxnew file mode 100644index 000000000..341a4ce93--- /dev/null+++ b/desktop-app/ui/src/hooks/domain/__tests__/notificationSwitchErrors.characterization.test.tsx@@ -0,0 +1,87 @@+// @vitest-environment jsdom+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { act, cleanup, waitFor } from '@testing-library/react'+import { DESKTOP_ROUTES } from '@constants/navigation'+import {+ installAppControllerClerum,+ renderAppController,+} from './__fixtures__/appControllerHarness'+import { deferred } from './__fixtures__/catalogFixtures'+import { renderController } from './__fixtures__/controllerHarness'+import { installMockClerum, uninstallMockClerum } from './__fixtures__/mockClerum'++beforeEach(() => vi.clearAllMocks())+afterEach(() => {+ cleanup()+ vi.restoreAllMocks()+ uninstallMockClerum()+})++describe('notification switch error ownership', () => {+ it('suppresses a stale awaited notification failure after chat-3 loads', async () => {+ const { clerum } = installAppControllerClerum({ agentNames: ['agent-x'] })+ for (const id of ['chat-1', 'chat-2', 'chat-3']) {+ await clerum.chat.create('agent-x', id)+ await clerum.chat.upsertMessages('agent-x', id, [+ { id: `${id}-history`, role: 'user', content: `${id} actual history`, timestamp: 1 },+ ])+ }+ const app = renderAppController()+ await waitFor(() => expect(app.result.current.initialExperienceLoading).toBe(false))+ act(() => app.result.current.handleSelectChatAgent('agent-x', { chatId: 'chat-1' }))+ await waitFor(() =>+ expect(app.result.current.activeMessages).toEqual([+ expect.objectContaining({ id: 'chat-1-history' }),+ ])+ )+ const gate = deferred<void>()+ const entered = deferred<void>()+ const setLastActive = clerum.chat.setLastActive.getMockImplementation()!+ clerum.chat.setLastActive.mockImplementation(async (agent, chat) => {+ if (chat === 'chat-2') {+ entered.resolve()+ await gate.promise+ }+ return setLastActive(agent, chat)+ })+ let notification!: Promise<void>+ act(() => {+ notification = app.result.current.handleOpenNotification({+ id: 'held-notification',+ kind: 'approval_required',+ agentName: 'agent-x',+ chatId: 'chat-2',+ teamId: 'team-1',+ text: 'Open chat two',+ timestamp: 1,+ read: false,+ approval: { taskId: 't2', requestId: 'r2' },+ } as Parameters<typeof app.result.current.handleOpenNotification>[0])+ })+ try {+ await entered.promise+ act(() => app.result.current.handleSelectChatAgent('agent-x', { chatId: 'chat-3' }))+ await waitFor(() =>+ expect(app.result.current.activeMessages).toEqual([+ expect.objectContaining({ id: 'chat-3-history' }),+ ])+ )+ const status = app.result.current.statusText+ const toasts = app.result.current.toasts+ await act(async () => {+ gate.reject(new Error('obsolete notification failed'))+ await notification+ })+ expect(app.result.current.activeChatId).toBe('chat-3')+ expect(app.result.current.activeMessages).toEqual([+ expect.objectContaining({ id: 'chat-3-history' }),+ ])+ expect(app.result.current.chatMessagesLoading).toBe(false)+ expect(app.result.current.statusText).toBe(status)+ expect(app.result.current.toasts).toEqual(toasts)+ } finally {+ gate.resolve()+ await notification.catch(() => undefined)+ }+ })+})diff --git a/desktop-app/ui/src/hooks/useAppController.ts b/desktop-app/ui/src/hooks/useAppController.tsindex 314d84649..ef25cf79b 100644--- a/desktop-app/ui/src/hooks/useAppController.ts+++ b/desktop-app/ui/src/hooks/useAppController.ts@@ -1212,7 +1212,20 @@ export function useAppController() {nav.selectedAgent === targetAgent &&nav.navItem === DESKTOP_ROUTES.chat) {- await chat.switchToChat(targetAgent, targetChatId)+ try {+ await chat.switchToChat(targetAgent, targetChatId, {+ onCurrentError: error => {+ fullSetStatus(+ `Could not open notification: ${error instanceof Error ? error.message : String(error)}`,+ 'error'+ )+ },+ })+ } catch {+ // The request owns current feedback and still rejects to awaiters.+ // This UI event observes that rejection without reporting it again.+ return+ }nav.activateChatTab(targetAgent, targetChatId)return}