Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): med-probe-401 revoke the session on drag-probe 401s
Me4f222a83487
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsxindex 9b044c6f9..7824d399f 100644--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx@@ -441,6 +441,9 @@ export function FileExplorerTree({scope: ctrl.sessionScope,drive: GFS_DRIVE_MAIN,resolve: (uri: string) => window.clerum.gfs.resolve(uri),+ // A drag probe that answers 401 is a session failure, not a per-item+ // refusal: the drop is refused AND the session revoked.+ handleAuthorityFailure: (message: string) => ctrl.handleAuthorityFailure(message, 'operation'),})const [expandedIds, setExpandedIds] = useState<Set<string>>(() => new Set())const [selectedId, setSelectedId] = useState<string | null>(null)diff --git a/desktop-app/ui/src/gfs/__tests__/dragAdjudication.test.tsx b/desktop-app/ui/src/gfs/__tests__/dragAdjudication.test.tsxindex d2d25ecd3..b1e3bf63c 100644--- a/desktop-app/ui/src/gfs/__tests__/dragAdjudication.test.tsx+++ b/desktop-app/ui/src/gfs/__tests__/dragAdjudication.test.tsx@@ -71,7 +71,7 @@ function installClerumGfsBridge() {})}-function renderAdjudication() {+function renderAdjudication(handleAuthorityFailure?: (message: string) => boolean) {const queryClient = new QueryClient({ defaultOptions: desktopQueryDefaults })const wrapper = ({ children }: { children: ReactNode }) => (<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>@@ -87,6 +87,7 @@ function renderAdjudication() {name: stringversion: number}>,+ ...(handleAuthorityFailure ? { handleAuthorityFailure } : {}),}),{ wrapper })@@ -270,3 +271,73 @@ describe('useGfsDragAdjudication — required-probe drop admission (R1-H1)', ()}})})++describe('useGfsDragAdjudication — probe 401 revokes the session', () => {+ it('reports a 401 from the affordances probe to the fail-closed classifier', async () => {+ const message = await affordancesFailureMessage(401, {+ code: 'unauthorized',+ message: 'session expired',+ })+ probes = await grantedProbes({ 'dest-1': { error: new Error(message) } })+ const handleAuthorityFailure = vi.fn(() => true)+ const { result } = renderAdjudication(handleAuthorityFailure)++ const decision = await result.current.adjudicateDrop(dragSource(), dropTarget())++ expect(decision).toEqual({ allowed: false, reason: 'session-lost' })+ expect(handleAuthorityFailure).toHaveBeenCalledWith(message)+ })++ it('reports a 401 from the direct source resolve to the fail-closed classifier', async () => {+ // An unknown source parent forces the direct resolve of the source; a 401+ // there must revoke, not just refuse the drop.+ const message = 'Error invoking remote method: Error: 401 Unauthorized httpStatus=401'+ resolve = vi.fn(async () => {+ throw new Error(message)+ })+ probes = await grantedProbes()+ const handleAuthorityFailure = vi.fn(() => true)+ const { result } = renderAdjudication(handleAuthorityFailure)++ const decision = await result.current.adjudicateDrop(+ dragSource({ parentKnown: false, parentResourceId: null }),+ dropTarget()+ )++ expect(decision).toEqual({ allowed: false, reason: 'session-lost' })+ expect(handleAuthorityFailure).toHaveBeenCalledWith(message)+ })++ it('reports a 401 from the ancestor resolve to the fail-closed classifier', async () => {+ const message = 'Error invoking remote method: Error: 401 Unauthorized httpStatus=401'+ resolve = vi.fn(async () => {+ throw new Error(message)+ })+ probes = await grantedProbes()+ const handleAuthorityFailure = vi.fn(() => true)+ const { result } = renderAdjudication(handleAuthorityFailure)++ await result.current.adjudicateDrop(+ dragSource({ kind: 'directory', knownAncestorIds: [] }),+ // An unproven chain (no root sentinel) forces the ancestor resolve.+ { ...dropTarget(), ancestorIds: ['root-1'] }+ )++ expect(handleAuthorityFailure).toHaveBeenCalledWith(message)+ })++ it('leaves a policy verdict local: a 403 probe never reaches the classifier', async () => {+ const message = await affordancesFailureMessage(403, {+ code: 'forbidden',+ message: 'not authorized to read affordances',+ })+ probes = await grantedProbes({ 'dest-1': { error: new Error(message) } })+ const handleAuthorityFailure = vi.fn(() => true)+ const { result } = renderAdjudication(handleAuthorityFailure)++ const decision = await result.current.adjudicateDrop(dragSource(), dropTarget())++ expect(decision.allowed).toBe(false)+ expect(handleAuthorityFailure).not.toHaveBeenCalled()+ })+})diff --git a/desktop-app/ui/src/gfs/__tests__/dragOwnership.test.tsx b/desktop-app/ui/src/gfs/__tests__/dragOwnership.test.tsxindex ba95f3dae..cf2331a07 100644--- a/desktop-app/ui/src/gfs/__tests__/dragOwnership.test.tsx+++ b/desktop-app/ui/src/gfs/__tests__/dragOwnership.test.tsx@@ -459,5 +459,22 @@ for (const surface of ['sidebar', 'files'] as const) {expect(h.toast).not.toHaveBeenCalled()expect(h.api().activeSource()?.resourceId).toBe('external')})++ it('revokes the session when a drag probe answers 401', async () => {+ // A probe 401 is a session failure: the drop is refused AND the session+ // must be revoked, not left active over a dead session.+ const h = await setup('file')+ const message = 'Error invoking remote method: Error: 401 Unauthorized httpStatus=401'+ h.affordances.mockImplementation(async () => {+ throw new Error(message)+ })+ h.start()+ h.drop()+ await waitFor(() =>+ expect(h.ctrl.handleAuthorityFailure).toHaveBeenCalledWith(message, 'operation')+ )+ expect(h.moveResource).not.toHaveBeenCalled()+ expect(h.toast).not.toHaveBeenCalled()+ })})}diff --git a/desktop-app/ui/src/gfs/dragAdjudication.ts b/desktop-app/ui/src/gfs/dragAdjudication.tsindex 9328c4ea0..fd8789c87 100644--- a/desktop-app/ui/src/gfs/dragAdjudication.ts+++ b/desktop-app/ui/src/gfs/dragAdjudication.ts@@ -3,7 +3,11 @@ import { useQueryClient } from '@tanstack/react-query'import { decideDragAuthority, decideDragStructure } from '@clerum/gfs-interaction-policy'import { DRAG_COLD_CHECK_DEBOUNCE_MS } from '@constants/gfsBrowser'import { desktopQueryKeys } from '@hooks/domain/queryKeys'-import { describeGfsReadError, parseHttpStatus } from '@lib/gfsGrantErrors'+import {+ describeGfsReadError,+ isGfsSessionAuthorityFailure,+ parseHttpStatus,+} from '@lib/gfsGrantErrors'import { GfsHoverCheckBudget, useGfsDragSession } from './dragSession'import type {GfsDragSource,@@ -31,6 +35,15 @@ export interface GfsDragAdjudicationDeps {drive: string/** Resolve by stable URI (read plane; 403/404/429 throw). */resolve: (gfsUri: string) => Promise<ResolvedLike>+ /**+ * Central fail-closed classifier for the operation surface; returns true+ * when it revoked the session. A probe 401 is a SESSION failure, not a+ * per-resource policy verdict: the drop must be refused AND the session+ * revoked, otherwise observer-less views keep rendering a dead session's+ * data. Optional so a surface without an authority boundary still refuses+ * the drop.+ */+ handleAuthorityFailure?: (message: string) => boolean}interface HeldAffordances {@@ -91,6 +104,21 @@ export function useGfsDragAdjudication(deps: GfsDragAdjudicationDeps) {const localBudgetRef = useRef(new GfsHoverCheckBudget())const debounceTimerRef = useRef<number | null>(null)+ /**+ * Hand a probe failure to the surface's central fail-closed classifier when+ * it is a session-authority failure. The drop is refused either way; this+ * is what makes the refusal also REVOKE the session instead of leaving an+ * active accessState over a dead session.+ */+ const reportAuthorityFailure = useCallback(+ (error: unknown): boolean => {+ const message = error instanceof Error ? error.message : String(error ?? '')+ if (!isGfsSessionAuthorityFailure(message, 'operation')) return false+ return deps.handleAuthorityFailure?.(message) ?? false+ },+ [deps]+ )+const readCachedAffordances = useCallback((resourceId: string): HeldAffordances | null => {if (!deps.scope) return null@@ -114,10 +142,13 @@ export function useGfsDragAdjudication(deps: GfsDragAdjudicationDeps) {})return { ok: true, held: held.held }} catch (error) {+ // A 401 here is a session failure, not a refused probe: report it so+ // the surface revokes instead of leaving the drop silently dead.+ reportAuthorityFailure(error)return { ok: false, error }}},- [deps.drive, deps.scope, queryClient]+ [deps.drive, deps.scope, queryClient, reportAuthorityFailure])/** Warm hover verdict: cached structure + cached bits; ZERO network reads. */@@ -305,9 +336,12 @@ export function useGfsDragAdjudication(deps: GfsDragAdjudicationDeps) {targetAncestorIds: chain,knownSourceAncestorIds: new Set(source.knownAncestorIds),})- } catch {+ } catch (error) {// Unreadable ancestry stays server-check-required; proceed below —- // a read failure upward is a visibility boundary, not a denial.+ // a read failure upward is a visibility boundary, not a denial. A+ // session failure is not a boundary: report it so the session is+ // revoked instead of the drop dying quietly.+ reportAuthorityFailure(error)}}@@ -323,7 +357,12 @@ export function useGfsDragAdjudication(deps: GfsDragAdjudicationDeps) {sourceParentForProbe = resolved.parentResourceId} catch (error) {const status = parseHttpStatus(error instanceof Error ? error.message : String(error))- if (status === 401) return { allowed: false, reason: 'session-lost' }+ if (status === 401) {+ // The drop is refused AND the session revoked: a 401 here means the+ // session died, not that this item is off limits.+ reportAuthorityFailure(error)+ return { allowed: false, reason: 'session-lost' }+ }if (status === 404) {return {allowed: false,@@ -385,7 +424,7 @@ export function useGfsDragAdjudication(deps: GfsDragAdjudicationDeps) {authority: { kind: 'observed-allowed', checkedAt: Date.now() },}},- [deps, fetchAffordances, resolveAncestorsUpTo]+ [deps, fetchAffordances, reportAuthorityFailure, resolveAncestorsUpTo])/** Fresh (5 s) source-resource write probe for the rename policy. */diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsxindex 7ecdc4def..fb091055e 100644--- a/desktop-app/ui/src/pages/FilesPage.tsx+++ b/desktop-app/ui/src/pages/FilesPage.tsx@@ -345,6 +345,12 @@ export function FilesPage({scope: sessionScope,drive: GFS_DRIVE_MAIN,resolve: useCallback((uri: string) => window.clerum.gfs.resolve(uri), []),+ // A drag probe that answers 401 is a session failure, not a per-item+ // refusal: the drop is refused AND the session revoked.+ handleAuthorityFailure: useCallback(+ (message: string) => ctrl.handleAuthorityFailure(message, 'operation'),+ [ctrl]+ ),})useEffect(