Skip to content

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

TypeScript

fix(desktop): r7-m7 preserve complete trail on refresh error

Josuéb1f3a3dc0057
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
index d3f5e09f4..2f3fce423 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
@@ -2114,6 +2114,55 @@ describe('useGfsBrowserController', () => {
expect(screen.getByTestId('open-error').textContent).toBe('none')
})
+ it('keeps the complete breadcrumb trail and retries a transient ancestor failure', async () => {
+ const parent = await resolveResource(
+ resolvedDirectory('parent', 'Parent', { gfsUri: 'gfs://main/parent', path: '/Parent' })
+ )
+ const leaf = await resolveResource(
+ resolvedDirectory('leaf', 'Leaf', {
+ gfsUri: 'gfs://main/root',
+ path: '/Parent/Leaf',
+ parentResourceId: 'parent',
+ })
+ )
+ const resolve = vi
+ .fn()
+ .mockResolvedValueOnce(leaf)
+ .mockResolvedValueOnce(parent)
+ .mockResolvedValueOnce(leaf)
+ .mockRejectedValueOnce(new Error('503 Service Unavailable'))
+ .mockResolvedValueOnce(leaf)
+ .mockResolvedValueOnce(parent)
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ gfs: {
+ resolve,
+ listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
+ affordances: vi.fn(async () => ({
+ held: [],
+ canDelegate: false,
+ grantableBits: [],
+ canCreateShare: false,
+ })),
+ },
+ },
+ })
+
+ render(<Probe />, { wrapper: Harness })
+ await act(async () => screen.getByRole('button', { name: 'open' }).click())
+ await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('leaf'))
+ expect(screen.getByTestId('crumbs').textContent).toBe('Parent / Leaf')
+
+ await act(async () => {
+ screen.getByRole('button', { name: 'background refresh current location' }).click()
+ })
+ await waitFor(() => expect(resolve).toHaveBeenCalledTimes(4))
+ expect(screen.getByTestId('crumbs').textContent).toBe('Parent / Leaf')
+ await waitFor(() => expect(resolve).toHaveBeenCalledTimes(6), { timeout: 2000 })
+ expect(screen.getByTestId('crumbs').textContent).toBe('Parent / Leaf')
+ })
+
it('revalidates accessible resources on remount even under production cache defaults', async () => {
const listAccessible = vi.fn(async () => ({ items: [], nextCursor: null }))
Object.defineProperty(window, 'clerum', {
diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
index 47e18dc2b..26065831c 100644
--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
@@ -307,6 +307,9 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
const foregroundOpenUriPendingRef = useRef<number | null>(null)
const backgroundOpenUriGenerationRef = useRef(0)
const pendingDeniedResourceIdRef = useRef<string | null>(null)
+ const backgroundLocationRetryRef = useRef<(uri: string) => void>(() => undefined)
+ const backgroundLocationRetryTimerRef = useRef<number | null>(null)
+ const backgroundLocationRetryAttemptRef = useRef(0)
// Any browser-location update supersedes an in-flight URI resolution. This
// includes navigation through the tree/crumbs as well as metadata updates,
// so an older refresh (including a late 403/404) cannot overwrite a newer
@@ -623,6 +626,22 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
},
[revokeAccess]
)
+ const scheduleBackgroundLocationRetry = useCallback((uri: string, error: unknown) => {
+ const message = toMessage(error)
+ const status = parseHttpStatus(message)
+ if (status !== null && status !== 429 && status < 500) return
+ if (backgroundLocationRetryTimerRef.current !== null) return
+ const attempt = backgroundLocationRetryAttemptRef.current + 1
+ backgroundLocationRetryAttemptRef.current = attempt
+ const retryAfterSeconds = parseRetryAfterSeconds(message)
+ const delayMs = retryAfterSeconds
+ ? Math.min(retryAfterSeconds * 1000, 60_000)
+ : Math.min(500 * 2 ** Math.min(attempt - 1, 4), 8_000)
+ backgroundLocationRetryTimerRef.current = window.setTimeout(() => {
+ backgroundLocationRetryTimerRef.current = null
+ backgroundLocationRetryRef.current(uri)
+ }, delayMs)
+ }, [])
// All GFS mutations share the central fail-closed boundary: an authority
// rejection (401 / typed lifecycle code) revokes the session even when the
// caller would only have toasted. Policy verdicts (403/412) stay local.
@@ -953,6 +972,11 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
(backgroundOpenUriGenerationRef.current === backgroundGeneration &&
currentCrumbRef.current?.gfsUri === uri))
if (!background) {
+ if (backgroundLocationRetryTimerRef.current !== null) {
+ window.clearTimeout(backgroundLocationRetryTimerRef.current)
+ backgroundLocationRetryTimerRef.current = null
+ }
+ backgroundLocationRetryAttemptRef.current = 0
foregroundOpenUriPendingRef.current = generation
setOpenError(null)
setResolving(true)
@@ -993,7 +1017,12 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
})
}
parentResourceId = parent.parentResourceId
- } catch {
+ } catch (error) {
+ if (background) {
+ setOpenError(toPresentedMessage(error))
+ scheduleBackgroundLocationRetry(uri, error)
+ return false
+ }
// A direct file grant can be readable while its parent is not. Keep
// the file open and show only the ancestors the caller may resolve.
break
@@ -1001,7 +1030,14 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
}
if (!isCurrent()) return false
- if (!background) setOpenError(null)
+ setOpenError(null)
+ if (background) {
+ if (backgroundLocationRetryTimerRef.current !== null) {
+ window.clearTimeout(backgroundLocationRetryTimerRef.current)
+ backgroundLocationRetryTimerRef.current = null
+ }
+ backgroundLocationRetryAttemptRef.current = 0
+ }
setCrumbsState([...ancestors.reverse(), crumb])
return crumb
} catch (error) {
@@ -1019,6 +1055,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
clearInaccessibleGfsLocation()
} else {
setOpenError(toPresentedMessage(error))
+ if (background) scheduleBackgroundLocationRetry(uri, error)
}
}
return false
@@ -1029,8 +1066,20 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
}
}
},
- [clearInaccessibleGfsLocation, handleAuthorityFailure]
+ [clearInaccessibleGfsLocation, handleAuthorityFailure, scheduleBackgroundLocationRetry]
)
+ useEffect(() => {
+ backgroundLocationRetryRef.current = uri => {
+ void openUri(uri, { background: true, clearIfUnavailable: true })
+ }
+ return () => {
+ backgroundLocationRetryRef.current = () => undefined
+ if (backgroundLocationRetryTimerRef.current !== null) {
+ window.clearTimeout(backgroundLocationRetryTimerRef.current)
+ backgroundLocationRetryTimerRef.current = null
+ }
+ }
+ }, [openUri, sessionScope])
const refreshCurrentLocation = useCallback(
async (options?: { background?: boolean }) => {