Skip to content

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

TypeScript

fix(desktop): r8-l8 purge previews on session authority loss

Josuéa43a2678c1f1
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 25e5afd44..5b631604a 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -28,6 +28,7 @@ import { WorkspaceTabStrip } from '@components/WorkspaceTabStrip'
import { DESKTOP_ROUTES, SIDEBAR_COLLAPSED_KEY } from '@constants/navigation'
import { THEME_STORAGE_KEY } from '@constants/theme'
import { desktopQueryKeys } from '@hooks/domain/queryKeys'
+import { isGfsSessionAuthorityFailure } from '@hooks/domain/useGfsBrowserController'
import { useAgentChatActionsValue } from '@hooks/useAgentChatActionsValue'
import { useAppController } from '@hooks/useAppController'
import {
@@ -1046,10 +1047,12 @@ export function App() {
} catch (error) {
if (previewRefreshGenerationRef.current.get(gfsUri) !== generation) return
const status = authoritativeGfsStatus(error)
- if (status === 401) {
+ const message = error instanceof Error ? error.message : String(error ?? '')
+ if (status === 401 || isGfsSessionAuthorityFailure(message, 'operation')) {
// A 401 is session-wide, unlike a resource-scoped 403/404. Purge
- // every open GFS preview and its cache immediately; never keep
- // displaying bytes fetched under a rejected session.
+ // and typed session-authority failures are session-wide. Purge every
+ // open GFS preview immediately; never keep displaying bytes fetched
+ // under a rejected session.
for (const [uri, timer] of previewRetryTimersRef.current) {
window.clearTimeout(timer)
previewRefreshGenerationRef.current.set(
diff --git a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
index 7add2cd96..2b072632a 100644
--- a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
+++ b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
@@ -1583,6 +1583,7 @@ describe('App live GFS preview revalidation', () => {
const before = initial()
expect(before?.kind).toBe('preview')
act(() => dispatchEntityChange?.({ ...USER_SCOPE_INVALIDATED }))
+ await waitFor(() => expect(resolve).toHaveBeenCalledTimes(1))
const queryFilter = invalidateQueries.mock.calls.at(-1)?.[0]
expect(queryFilter?.queryKey).toEqual(desktopQueryKeys.gfsRoot)
expect(
@@ -1662,6 +1663,34 @@ describe('App live GFS preview revalidation', () => {
})
})
+ it('purges every open GFS preview for a status-free session authority failure', async () => {
+ currentController.workspaceTabs = openPreviewTab(currentController.workspaceTabs, {
+ id: 'preview-image',
+ title: 'diagram.png',
+ gfsUri: 'gfs://main/diagram',
+ fileKind: 'image',
+ byteLength: 128,
+ mimeType: 'image/png',
+ resourceVersion: 7,
+ })
+ const resolve = vi.mocked(window.clerum.gfs.resolve)
+ resolve.mockImplementation(uri => {
+ if (uri === 'gfs://main/readme')
+ return Promise.reject(new Error('Not authenticated')) as never
+ return new Promise(() => {}) as never
+ })
+ render(<App />)
+ await waitFor(() => expect(dispatchEntityChange).toBeTypeOf('function'))
+
+ act(() => dispatchEntityChange?.({ ...USER_SCOPE_INVALIDATED }))
+
+ await waitFor(() => {
+ const previews = currentController.workspaceTabs.tabs.filter(tab => tab.kind === 'preview')
+ expect(previews).toHaveLength(2)
+ expect(previews.every(tab => tab.preview?.unavailable)).toBe(true)
+ })
+ })
+
it('does not retry a preview after its last tab owner closes', async () => {
const unavailableMessage = await resolveDeniedMessage(
'gfs://main/readme',