Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): share GFS revoked-access state across controller mounts (R1-H2)
Diego Zacarias9878d79328c3
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsxindex 33e7dc93b..7876965d2 100644--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx@@ -3,6 +3,7 @@ import { useRef, useState } from 'react'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { QueryClient, QueryClientProvider, focusManager } from '@tanstack/react-query'import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'+import { useGfsBrowserController } from '@hooks/domain/useGfsBrowserController'import { desktopQueryDefaults } from '@lib/queryClient'import { activeWorkspaceTab, openFilesTab } from '@lib/workspaceTabs'import type { WorkspaceTabsState } from '@lib/workspaceTabs.types'@@ -591,3 +592,63 @@ describe('FileExplorerTree — unreadable rows refuse activation (R1-H1)', () =>expect(within(folderButton).getByText('No access')).toBeTruthy()})})++describe('FileExplorerTree — shared revoked access across controller mounts (R1-H2)', () => {+ // The sidebar tree, FilesPage and FilePreviewPage each mount their OWN+ // `useGfsBrowserController`. A session-authority 401 in any one of them must+ // revoke ALL of them, and a retry in one must re-activate all — otherwise a+ // 401 in the tree leaves FilesPage live against caches the session can no+ // longer authorize, and FilesPage's Retry never re-enables the still-mounted+ // tree. The revoked flag is shared through the query cache, so every mount on+ // the SAME queryClient observes it. This second mount is an independent+ // controller consumer, not the tree's own instance.+ function AccessStateProbe() {+ const ctrl = useGfsBrowserController()+ return <div data-testid="probe-access">{ctrl.accessState}</div>+ }++ it('revokes a second mount from a tree 401 and re-activates both on retry (not the empty state)', async () => {+ // Discovery succeeds; the 401 comes from the tree's own listChildren — an+ // operation-surface authority failure that ONLY the tree's controller+ // observes. Under per-mount state the probe would never see it.+ const listAccessible = vi.fn(async () =>+ listAccessiblePage([accessibleResource('reports', 'Reports', 'directory')])+ )+ let childrenCall = 0+ const listChildren = vi.fn(async () => {+ childrenCall += 1+ if (childrenCall === 1) throw new Error('401 Unauthorized')+ return listChildrenPage([childView('r-1', 'r.md', 'file')])+ })+ installClerum({ listAccessible, listChildren })++ // ONE queryClient shared by both mounts is the sharing boundary. Run it+ // under the REAL desktop cache policy so nothing but the shared flag carries+ // the revoke across mounts.+ const queryClient = new QueryClient({ defaultOptions: desktopQueryDefaults })+ render(+ <QueryClientProvider client={queryClient}>+ <FileExplorerTree onOpenFolder={vi.fn()} onOpenPreview={vi.fn()} pushToast={vi.fn()} />+ <AccessStateProbe />+ </QueryClientProvider>+ )++ await screen.findByRole('button', { name: 'Reports' })+ expect(screen.getByTestId('probe-access').textContent).toBe('active')++ // Expand the folder → the tree's listChildren 401s → the tree revokes.+ fireEvent.click(screen.getByRole('button', { name: 'Expand Reports' }))++ // (a) The tree shows the unauthorized + retry surface — NOT "No shared files+ // yet." (b) The independent second mount reads revoked (shared flag).+ expect(await screen.findByText('File access is not authorized')).toBeTruthy()+ expect(screen.queryByText('No shared files yet.')).toBeNull()+ await waitFor(() => expect(screen.getByTestId('probe-access').textContent).toBe('revoked'))++ // (c) Retry from the tree re-activates BOTH mounts and re-enables the+ // queries, so discovery reloads and the tree renders its root again.+ fireEvent.click(screen.getByRole('button', { name: 'Retry file access' }))+ await waitFor(() => expect(screen.getByTestId('probe-access').textContent).toBe('active'))+ expect(await screen.findByRole('button', { name: 'Reports' })).toBeTruthy()+ })+})diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsxindex 9c7b1368a..dde3bb554 100644--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx@@ -345,7 +345,22 @@ export function FileExplorerTree({return (<div className="da-file-explorer">- {ctrl.accessibleNotice ? (+ {ctrl.accessState === 'revoked' ? (+ // Mirror the Files page's revoked surface, adapted to the sidebar's+ // compact chrome. Without this branch a revoked drive falls through to+ // "No shared files yet." — the fail-closed purge has already dropped the+ // discovery error and roots, so an unauthorized drive would read empty.+ <div className="da-file-explorer__revoked" role="alert">+ <p className="da-file-explorer__revoked-title">File access is not authorized</p>+ <p className="da-file-explorer__revoked-body">+ Your current session cannot access these files. Sign in again or contact an+ administrator.+ </p>+ <Button onClick={() => ctrl.retryAccess()} size="xs" variant="text">+ Retry file access+ </Button>+ </div>+ ) : ctrl.accessibleNotice ? (<p className="da-file-explorer__message muted">{ctrl.accessibleNotice}</p>) : ctrl.accessibleError ? (<StatusBanner tone="error" text={ctrl.accessibleError} compact />diff --git a/desktop-app/ui/src/hooks/domain/queryKeys.ts b/desktop-app/ui/src/hooks/domain/queryKeys.tsindex 1214aac8d..60507182e 100644--- a/desktop-app/ui/src/hooks/domain/queryKeys.ts+++ b/desktop-app/ui/src/hooks/domain/queryKeys.ts@@ -17,6 +17,12 @@ export const desktopQueryKeys = {sharedFilesDirectory: (contextId: string, filesystemName: string, path: string) =>['desktop-app', 'shared-files', 'directory', contextId, filesystemName, path] as const,gfsRoot: ['desktop-app', 'gfs'] as const,+ // Session-authority revoked flag, SHARED across every GFS controller mount+ // (sidebar tree, FilesPage, FilePreviewPage) via the query cache. Kept OUTSIDE+ // the `gfsRoot` prefix on purpose: the fail-closed purge removes everything+ // under `gfsRoot`, and the revoked flag must survive that purge (it is set in+ // the same turn). Keyed by sessionScope so a user/team/env switch reads fresh.+ gfsAccessState: (sessionScope: string) => ['desktop-app', 'gfs-access', sessionScope] as const,gfsAccessible: (sessionScope: string, drive: string) =>['desktop-app', 'gfs', sessionScope, 'accessible', drive] as const,gfsChildren: (sessionScope: string, resourceId: string, drive: string) =>diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.tsindex aea7d5be0..185d230ae 100644--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts@@ -29,6 +29,8 @@ import { desktopQueryKeys } from './queryKeys'const DRIVE = 'main'+type GfsAccessState = 'active' | 'revoked'+export interface GfsBrowserChild {resourceId: stringrid: string@@ -193,12 +195,6 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {const [crumbs, setCrumbs] = useState<GfsCrumb[]>([])const [openError, setOpenError] = useState<string | null>(null)const [resolving, setResolving] = useState(false)- // Deliberately session-local. A server authorization failure must never- // leave cached GFS metadata (listings, affordances, grants, shares)- // visible: production query defaults keep data for 30 minutes without- // revalidation, so the only safe response is to drop it all. A later- // server-backed request (retryAccess) is the only way back in.- const [accessState, setAccessState] = useState<'active' | 'revoked'>('active')const previousSessionScopeRef = useRef<string | null>(null)// Per controller-mount timestamp: discovery (`refetchOnMount: 'always'`) must// land a response newer than this before cached GFS state may render again.@@ -218,6 +214,35 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {)const canListAccessibleResources = typeof window.clerum?.gfs?.listAccessible === 'function'+ // Session-authority access state, SHARED across every controller mount (the+ // sidebar tree, FilesPage, FilePreviewPage each mount their own controller).+ // A server authorization failure must never leave cached GFS metadata visible+ // — production defaults keep data for 30 minutes without revalidation, so the+ // only safe response is to drop it all and gate the queries off. That decision+ // has to be observed by EVERY mount: a 401 in one surface must revoke the+ // others, and a retry in one must re-enable them. It therefore lives in the+ // query cache (a pure subscription here; never fetches — writes go through+ // `setAccessState`), keyed by sessionScope and OUTSIDE `gfsRoot` so the+ // fail-closed purge below does not clear the flag it just set. `gcTime:+ // Infinity` keeps the revoked decision alive across a gap with no mounts, so a+ // later mount still fails closed; only retryAccess (a server round-trip) or a+ // session-scope change returns to 'active'.+ const accessStateQuery = useQuery({+ queryKey: desktopQueryKeys.gfsAccessState(sessionScope ?? 'anonymous'),+ queryFn: () => 'active' as GfsAccessState,+ enabled: false,+ initialData: 'active' as GfsAccessState,+ gcTime: Infinity,+ staleTime: Infinity,+ })+ const accessState: GfsAccessState = accessStateQuery.data ?? 'active'+ const setAccessState = useCallback(+ (next: GfsAccessState) => {+ queryClient.setQueryData(desktopQueryKeys.gfsAccessState(sessionScope ?? 'anonymous'), next)+ },+ [queryClient, sessionScope]+ )+useEffect(() => {const previous = previousSessionScopeRef.currentif (previous === sessionScope) return@@ -228,7 +253,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {setAccessState('active')void queryClient.removeQueries({ queryKey: desktopQueryKeys.gfsRoot })}- }, [queryClient, sessionScope])+ }, [queryClient, sessionScope, setAccessState])const accessibleQuery = useInfiniteQuery({queryKey: desktopQueryKeys.gfsAccessible(sessionScope ?? 'anonymous', DRIVE),@@ -387,12 +412,13 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {const revokeAccess = useCallback(() => {setAccessState('revoked')clearGfsState()- }, [clearGfsState])+ }, [clearGfsState, setAccessState])const retryAccess = useCallback(() => {// This restores no local capability; it only re-enables the queries so a- // server-side re-grant (or a fresh sign-in) is the sole way back in.+ // server-side re-grant (or a fresh sign-in) is the sole way back in. Because+ // the flag is shared, a retry here re-activates every mounted controller.setAccessState('active')- }, [])+ }, [setAccessState])/** For imperative flows (openUri, revoke mutations): fail closed on a* session-authority rejection; returns true when it did. */const handleAuthorityFailure = useCallback(diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.cssindex f2c8825fa..39bf5aa10 100644--- a/desktop-app/ui/src/styles.css+++ b/desktop-app/ui/src/styles.css@@ -1844,6 +1844,29 @@ h3 {font-size: var(--font-size-xs);}+/* Revoked-access surface for the sidebar tree — the compact-chrome sibling of+ the Files page's "File access is not authorized" empty state + Retry. */+.da-file-explorer__revoked {+ display: grid;+ gap: var(--space-1);+ padding: var(--space-2) var(--space-1);+}++.da-file-explorer__revoked-title {+ margin: 0;+ color: var(--text);+ font-size: var(--font-size-sm);+ font-weight: var(--font-weight-semibold);+ line-height: var(--line-height-tight);+}++.da-file-explorer__revoked-body {+ margin: 0;+ color: var(--text-dim);+ font-size: var(--font-size-xs);+ line-height: var(--line-height-normal);+}+.da-file-explorer__tree,.da-file-explorer__group {display: grid;