Skip to content

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

TypeScript

fix(desktop-ui): r8-l4 report detached switch failures

Josuéa02fa1bd0a35
diff --git a/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsx b/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsx
index 03921fa72..61aec382d 100644
--- a/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsx
+++ b/desktop-app/ui/src/hooks/__tests__/useAppController.chatDrawer.test.tsx
@@ -293,4 +293,104 @@ describe('useAppController — chat drawer keepNavItem', () => {
unmount = null
}
})
+
+ it('reports a failed notification switch without starting an unobserved fallback', async () => {
+ const { clerum } = installAppControllerClerum({ agentNames: ['agent-x'] })
+ await clerum.chat.create('agent-x', 'chat-1')
+ await clerum.chat.upsertMessages('agent-x', 'chat-1', [
+ { id: 'chat-1-message', role: 'user', content: 'first chat', timestamp: 1 },
+ ])
+ await clerum.chat.create('agent-x', 'chat-2')
+ const app = renderAppController()
+ unmount = app.unmount
+
+ try {
+ await waitFor(() => expect(app.result.current.isAuthenticated).toBe(true))
+ await waitFor(() => expect(app.result.current.initialExperienceLoading).toBe(false))
+ act(() => {
+ app.result.current.handleSelectChatAgent('agent-x', {
+ chatId: 'chat-1',
+ selectLatest: false,
+ })
+ })
+ await waitFor(() => {
+ expect(app.result.current.activeChatId).toBe('chat-1')
+ expect(app.result.current.chatMessagesLoading).toBe(false)
+ })
+
+ const callsBeforeOpen = clerum.chat.setLastActive.mock.calls.length
+ clerum.chat.setLastActive.mockRejectedValueOnce(new Error('chat store write failed'))
+ await act(async () => {
+ await app.result.current.handleOpenNotification({
+ id: 'n-failing-chat',
+ kind: 'approval_required',
+ agentName: 'agent-x',
+ chatId: 'chat-2',
+ teamId: 'team-1',
+ text: 'Open chat two',
+ timestamp: Date.now(),
+ read: false,
+ approval: { taskId: 't2', requestId: 'r2' },
+ } as Parameters<typeof app.result.current.handleOpenNotification>[0])
+ })
+ await waitFor(() => expect(app.result.current.chatMessagesLoading).toBe(false))
+
+ expect({
+ switchAttempts: clerum.chat.setLastActive.mock.calls.length - callsBeforeOpen,
+ statusText: app.result.current.statusText,
+ statusTone: app.result.current.statusTone,
+ loading: app.result.current.chatMessagesLoading,
+ }).toEqual({
+ switchAttempts: 1,
+ statusText: expect.stringContaining('Could not open notification'),
+ statusTone: 'error',
+ loading: false,
+ })
+ } finally {
+ app.unmount()
+ unmount = null
+ }
+ })
+
+ it('reports a failed direct chat-tab switch', async () => {
+ const { clerum } = installAppControllerClerum({ agentNames: ['agent-x'] })
+ await clerum.chat.create('agent-x', 'chat-1')
+ await clerum.chat.create('agent-x', 'chat-2')
+ const app = renderAppController()
+ unmount = app.unmount
+
+ try {
+ await waitFor(() => expect(app.result.current.isAuthenticated).toBe(true))
+ await waitFor(() => expect(app.result.current.initialExperienceLoading).toBe(false))
+ act(() => {
+ app.result.current.handleSelectChatAgent('agent-x', {
+ chatId: 'chat-1',
+ selectLatest: false,
+ })
+ })
+ await waitFor(() => {
+ expect(app.result.current.activeChatId).toBe('chat-1')
+ expect(app.result.current.chatMessagesLoading).toBe(false)
+ })
+
+ const callsBeforeSwitch = clerum.chat.setLastActive.mock.calls.length
+ clerum.chat.setLastActive.mockRejectedValueOnce(new Error('chat store write failed'))
+ act(() => {
+ app.result.current.handleSelectChatAgent('agent-x', {
+ chatId: 'chat-2',
+ selectLatest: false,
+ })
+ })
+
+ await waitFor(() => {
+ expect(app.result.current.statusText).toContain('Could not open conversation')
+ expect(app.result.current.statusTone).toBe('error')
+ expect(app.result.current.chatMessagesLoading).toBe(false)
+ })
+ expect(clerum.chat.setLastActive).toHaveBeenCalledTimes(callsBeforeSwitch + 1)
+ } finally {
+ app.unmount()
+ unmount = null
+ }
+ })
})
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/selectionLoadingOwnership.r7.characterization.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/selectionLoadingOwnership.r7.characterization.test.tsx
index 4584b3c63..322a65323 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/selectionLoadingOwnership.r7.characterization.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/selectionLoadingOwnership.r7.characterization.test.tsx
@@ -167,6 +167,32 @@ describe('Round 7 selection loading ownership', () => {
controller.unmount()
}
})
+
+ it('surfaces a rejected imperative pending-chat switch and settles its spinner', async () => {
+ const controller = renderController({ navItem: 'chat', loadMenuData: false })
+ const switchError = new Error('chat store write failed')
+
+ try {
+ await waitFor(() => expect(controller.result.current.chatListLoading).toBe(false))
+ await clerum.chat.create('agent-x', 'chat-imperative')
+ clerum.chat.setLastActive.mockRejectedValueOnce(switchError)
+
+ act(() => {
+ controller.result.current.setPendingChatSelection('agent-x', 'chat-imperative')
+ })
+
+ await waitFor(() => {
+ expect(controller.result.current.chatMessagesLoading).toBe(false)
+ expect(controller.spies.pushToast).toHaveBeenCalledWith(
+ 'Could not open conversation: chat store write failed',
+ 'error'
+ )
+ })
+ expect(controller.result.current.activeChatId).toBe('chat-imperative')
+ } finally {
+ controller.unmount()
+ }
+ })
it('loads a newer specific chat when it supersedes a held implicit switch', async () => {
await clerum.chat.create('agent-x', 'chat-b')
await clerum.chat.upsertMessages('agent-x', 'chat-b', [
diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
index 2fe2fbfcf..cf51c8c65 100644
--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
@@ -1181,13 +1181,19 @@ export function useAgentChatController({
if (isHostAccessBlocked(agentRef) || isChatDeleted(agentRef, chatId)) return
const selectionIntentRevision = beginSelectionIntent(true)
clearPendingSelection(agentRef, chatId)
- await switchToChatForIntent(agentRef, chatId, selectionIntentRevision)
+ try {
+ await switchToChatForIntent(agentRef, chatId, selectionIntentRevision)
+ } catch (error) {
+ settleChatMessagesLoading(selectionIntentRevision)
+ throw error
+ }
},
[
beginSelectionIntent,
clearPendingSelection,
isChatDeleted,
isHostAccessBlocked,
+ settleChatMessagesLoading,
switchToChatForIntent,
]
)
@@ -1512,7 +1518,14 @@ export function useAgentChatController({
}
}
settleChatMessagesLoading(selectionIntentRevision)
- })()
+ })().catch(error => {
+ if (cancelled || selectionIntentRevisionRef.current !== selectionIntentRevision) return
+ settleChatMessagesLoading(selectionIntentRevision)
+ pushToast(
+ `Could not open conversation: ${error instanceof Error ? error.message : String(error)}`,
+ 'error'
+ )
+ })
return () => {
cancelled = true
@@ -1524,6 +1537,7 @@ export function useAgentChatController({
navItem,
selectedAgent,
isHostAccessBlocked,
+ pushToast,
settleChatMessagesLoading,
switchToChatForIntent,
])
@@ -3916,7 +3930,12 @@ export function useAgentChatController({
if (options.title) {
upsertProvisionalEntry(chatId!, options.title, options.isRemote === true)
}
- void switchToChat(agentName, chatId!)
+ void switchToChat(agentName, chatId!).catch(error => {
+ pushToast(
+ `Could not open conversation: ${error instanceof Error ? error.message : String(error)}`,
+ 'error'
+ )
+ })
return
}
// A same-agent no-chat notification can record a pending none selection
@@ -3963,6 +3982,7 @@ export function useAgentChatController({
clearPendingSelection,
currentTeamId,
writePendingSelection,
+ pushToast,
upsertProvisionalEntry,
selectedAgent,
navItem,
diff --git a/desktop-app/ui/src/hooks/domain/useChatListController.ts b/desktop-app/ui/src/hooks/domain/useChatListController.ts
index a0ae065fa..afcc8c853 100644
--- a/desktop-app/ui/src/hooks/domain/useChatListController.ts
+++ b/desktop-app/ui/src/hooks/domain/useChatListController.ts
@@ -646,7 +646,15 @@ export function useChatListController({
!suppressAutoSelection
) {
currentHost.markAutoSelectedChat(latestServerSession.chatId)
- void currentHost.switchToChat(agentRef, latestServerSession.chatId)
+ const switchRequest = currentHost.switchToChat(agentRef, latestServerSession.chatId)
+ const switchSelectionRevision = currentHost.getSelectionIntentRevision()
+ void switchRequest.catch(error => {
+ if (currentHost.getSelectionIntentRevision() !== switchSelectionRevision) return
+ currentHost.pushToast(
+ `Could not open conversation: ${error instanceof Error ? error.message : String(error)}`,
+ 'error'
+ )
+ })
}
// Persist server freshness into the local index (spec §5.3): keeps the
@@ -1061,7 +1069,14 @@ export function useChatListController({
: null
if (restoreChatId) {
const restore = host.current?.switchToChat(agentRef, restoreChatId)
- void restore?.catch(() => undefined)
+ const restoreSelectionRevision = host.current?.getSelectionIntentRevision()
+ void restore?.catch(error => {
+ if (host.current?.getSelectionIntentRevision() !== restoreSelectionRevision) return
+ host.current?.pushToast(
+ `Could not restore conversation: ${error instanceof Error ? error.message : String(error)}`,
+ 'error'
+ )
+ })
}
}
throw error
diff --git a/desktop-app/ui/src/hooks/useAppController.ts b/desktop-app/ui/src/hooks/useAppController.ts
index 2897e62c9..33dde9b19 100644
--- a/desktop-app/ui/src/hooks/useAppController.ts
+++ b/desktop-app/ui/src/hooks/useAppController.ts
@@ -1030,7 +1030,12 @@ export function useAppController() {
) {
// D.4: switchToChat is now a single unified path (no isRemote) — the
// server is the source of truth and hydrates server-only chats itself.
- void chat.switchToChat(agentName, targetChatId)
+ void chat.switchToChat(agentName, targetChatId).catch(error => {
+ fullSetStatus(
+ `Could not open conversation: ${error instanceof Error ? error.message : String(error)}`,
+ 'error'
+ )
+ })
nav.setSelectedAgentRoute(AGENT_WORKSPACE_ROUTES.connectors)
// Activate the chat tab (dedupes/focuses by chatId). We are already on
// the chat route, so `navItem` stays `chat` — same-commit derivation, no
@@ -1073,13 +1078,19 @@ export function useAppController() {
// effect replays into its `specific` branch instead of the reset branch;
// both switches target the same chat and `switchToChat` coalesces them.
if (options.keepNavItem && targetChatId && nav.selectedAgent === agentName) {
- void chat.switchToChat(agentName, targetChatId)
+ void chat.switchToChat(agentName, targetChatId).catch(error => {
+ fullSetStatus(
+ `Could not open conversation: ${error instanceof Error ? error.message : String(error)}`,
+ 'error'
+ )
+ })
}
},
[
chat.clearActiveChat,
chat.setPendingChatSelection,
chat.switchToChat,
+ fullSetStatus,
nav.activateChatTab,
nav.navItem,
nav.selectedAgent,
@@ -1193,13 +1204,9 @@ export function useAppController() {
nav.selectedAgent === targetAgent &&
nav.navItem === DESKTOP_ROUTES.chat
) {
- try {
- await chat.switchToChat(targetAgent, targetChatId)
- nav.activateChatTab(targetAgent, targetChatId)
- return
- } catch {
- // Fall through to pending selection so the normal agent load path can retry.
- }
+ await chat.switchToChat(targetAgent, targetChatId)
+ nav.activateChatTab(targetAgent, targetChatId)
+ return
}
chat.setPendingChatSelection(targetAgent, targetChatId || null)