Skip to content

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

TypeScript

fix(desktop-ui): preserve logout after session refresh failure (R13-L3)

Josué32f150745a9c
diff --git a/desktop-app/ui/src/hooks/__tests__/useAppController.desktopEnvironmentHandoff.test.tsx b/desktop-app/ui/src/hooks/__tests__/useAppController.desktopEnvironmentHandoff.test.tsx
index c7a7c1fac..0ca0675ed 100644
--- a/desktop-app/ui/src/hooks/__tests__/useAppController.desktopEnvironmentHandoff.test.tsx
+++ b/desktop-app/ui/src/hooks/__tests__/useAppController.desktopEnvironmentHandoff.test.tsx
@@ -112,4 +112,20 @@ describe('useAppController desktop environment handoff', () => {
activeOptionId: 'target-profile',
})
})
+
+ it('keeps the committed logout when renderer session reload fails', async () => {
+ const { app, handle, handoff } = await openSwitchConfirmation()
+ handle.setSessionStateError(new Error('session read unavailable'))
+
+ await act(async () => app.result.current.handleConfirmDesktopEnvironmentSwitchConfirmation())
+ await act(async () => handoff)
+
+ expect(handle.logout).toHaveBeenCalledOnce()
+ expect(handle.selectRuntimeConfigForHandoff).toHaveBeenCalledWith('target-profile', 1)
+ expect(app.result.current.isAuthenticated).toBe(false)
+ expect(app.result.current.runtimeConfigState?.activeOptionId).toBe('target-profile')
+ expect(app.result.current.statusText).toContain(
+ 'Could not load the selected desktop environment'
+ )
+ })
})
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx b/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx
index 6eb669d80..10d84e6fc 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx
@@ -105,6 +105,8 @@ export interface AppControllerClerumOptions {
healthError?: unknown
/** Make `auth.passwordLogin` reject with this instead of signing in. */
passwordLoginError?: unknown
+ /** Make `auth.getSessionState` reject after mount when requested by a test. */
+ sessionStateError?: unknown
/** Payload for `auth.getDesktopReleaseStatus`. */
desktopReleaseStatus?: typeof DEFAULT_DESKTOP_RELEASE_STATUS
/** Payload for `team.directory` / `team.initialDirectory` / `team.list`. */
@@ -144,6 +146,7 @@ export interface AppControllerClerumHandle {
resolveHealth: () => void
/** Settles whatever `delayAuthenticatedLoad` is holding open. */
resolveAuthenticatedLoad: () => void
+ setSessionStateError: (error: unknown) => void
}
/**
@@ -161,6 +164,7 @@ export function extendMockClerumForAppController(
let authenticated = options.startAuthenticated ?? true
let sessionGeneration = 0
+ let sessionStateError = options.sessionStateError
let runtimeConfigState: DesktopRuntimeConfigState = options.runtimeConfigState ?? {
configured: true,
isLocalhost: false,
@@ -186,7 +190,10 @@ export function extendMockClerumForAppController(
if (options.healthError) throw options.healthError
return options.delayHealth ? healthDeferred.promise : createHealth()
})
- const getSessionState = vi.fn(async () => createSessionState(authenticated, sessionMe))
+ const getSessionState = vi.fn(async () => {
+ if (sessionStateError) throw sessionStateError
+ return createSessionState(authenticated, sessionMe)
+ })
const passwordLogin = vi.fn(async () => {
if (options.passwordLoginError) throw options.passwordLoginError
authenticated = true
@@ -387,6 +394,9 @@ export function extendMockClerumForAppController(
catalogDeferred.resolve(createCatalog(agentNames))
approvalsDeferred.resolve([])
},
+ setSessionStateError(error) {
+ sessionStateError = error
+ },
}
}
diff --git a/desktop-app/ui/src/hooks/useAppController.ts b/desktop-app/ui/src/hooks/useAppController.ts
index cf2094b19..a1a0a8536 100644
--- a/desktop-app/ui/src/hooks/useAppController.ts
+++ b/desktop-app/ui/src/hooks/useAppController.ts
@@ -900,6 +900,12 @@ export function useAppController() {
// ─── Cross-domain: handleLogout ───
const logoutAndGetSessionGeneration = useCallback(async (): Promise<number | null> => {
+ let logoutGeneration: number | null = null
+ const reflectSignedOutState = () => {
+ auth.setIsAuthenticated(false)
+ auth.setMe(null)
+ auth.setPassword('')
+ }
try {
auth.setBusy(true)
await chat.stopAllActivityStreams()
@@ -919,12 +925,30 @@ export function useAppController() {
activeAuthenticatedSessionIdentityRef.current = null
authenticatedSessionIdentityRef.current = null
const logoutResult = await window.clerum.auth.logout()
+ logoutGeneration = logoutResult.sessionGeneration
+ reflectSignedOutState()
chat.resetChat()
notif.resetNotifications()
fullSetStatus('Logged out.', 'success')
- await loadSession()
- return logoutResult.sessionGeneration
+ try {
+ await loadSession()
+ } catch (error) {
+ reflectSignedOutState()
+ fullSetStatus(
+ `Signed out, but could not refresh the desktop session: ${error instanceof Error ? error.message : String(error)}`,
+ 'warn'
+ )
+ }
+ return logoutGeneration
} catch (error) {
+ if (logoutGeneration !== null) {
+ reflectSignedOutState()
+ fullSetStatus(
+ `Signed out, but could not refresh the desktop session: ${error instanceof Error ? error.message : String(error)}`,
+ 'warn'
+ )
+ return logoutGeneration
+ }
fullSetStatus(
`Logout failed: ${error instanceof Error ? error.message : String(error)}`,
'error'
@@ -936,6 +960,9 @@ export function useAppController() {
}, [
agentsData.reset,
auth.setBusy,
+ auth.setIsAuthenticated,
+ auth.setMe,
+ auth.setPassword,
chat.resetChat,
chat.stopAllActivityStreams,
connectorsData.reset,