Skip to content

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

TypeScript

fix(desktop-app): r6-h4 prioritize user navigation

Josué6aba22249d04
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 94c9790c9..98e6b416b 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
@@ -144,6 +144,15 @@ function Probe() {
<button type="button" onClick={() => swallow(ctrl.refreshCurrentLocation())}>
refresh current location
</button>
+ <button
+ type="button"
+ onClick={() => swallow(ctrl.refreshCurrentLocation({ background: true }))}
+ >
+ background refresh current location
+ </button>
+ <button type="button" onClick={() => swallow(ctrl.openUri('gfs://main/folder-b'))}>
+ open user destination
+ </button>
<button type="button" onClick={() => swallow(ctrl.refreshAffordances())}>
refresh permissions
</button>
@@ -367,6 +376,53 @@ describe('useGfsBrowserController', () => {
}
)
+ it('does not let a live background refresh supersede a pending user navigation', async () => {
+ const folderA = await resolveResource(
+ resolvedDirectory('folder-a', 'Folder A', { gfsUri: 'gfs://main/root' })
+ )
+ const folderB = await resolveResource(
+ resolvedDirectory('folder-b', 'Folder B', { gfsUri: 'gfs://main/folder-b' })
+ )
+ let finishUserNavigation!: (resource: typeof folderB) => void
+ const deferredUserNavigation = new Promise<typeof folderB>(resolve => {
+ finishUserNavigation = resolve
+ })
+ const resolve = vi
+ .fn()
+ .mockResolvedValueOnce(folderA)
+ .mockImplementationOnce(() => deferredUserNavigation)
+ .mockResolvedValueOnce(folderA)
+
+ 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('folder-a'))
+
+ screen.getByRole('button', { name: 'open user destination' }).click()
+ await waitFor(() => expect(resolve).toHaveBeenCalledTimes(2))
+ await act(async () => {
+ screen.getByRole('button', { name: 'background refresh current location' }).click()
+ })
+ await act(async () => finishUserNavigation(folderB))
+
+ await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('folder-b'))
+ })
+
it('exposes the presented verdict for a failed affordances read, not the IPC wrapper', async () => {
// Every rejection that crosses ipcRenderer.invoke arrives wrapped in
// "Error invoking remote method '<channel>': ", which names our own
diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
index 69fe860be..9c70f7879 100644
--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
@@ -304,6 +304,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
const [openError, setOpenError] = useState<string | null>(null)
const [resolving, setResolving] = useState(false)
const openUriGenerationRef = useRef(0)
+ const backgroundOpenUriGenerationRef = 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
@@ -901,13 +902,22 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
: null
const openUri = useCallback(
- async (uri: string, options?: { clearIfUnavailable?: boolean }) => {
- const generation = ++openUriGenerationRef.current
- setOpenError(null)
- setResolving(true)
+ async (uri: string, options?: { clearIfUnavailable?: boolean; background?: boolean }) => {
+ const background = options?.background === true
+ const generation = background ? openUriGenerationRef.current : ++openUriGenerationRef.current
+ const backgroundGeneration = background ? ++backgroundOpenUriGenerationRef.current : undefined
+ const isCurrent = () =>
+ openUriGenerationRef.current === generation &&
+ (!background ||
+ (backgroundOpenUriGenerationRef.current === backgroundGeneration &&
+ currentCrumbRef.current?.gfsUri === uri))
+ if (!background) {
+ setOpenError(null)
+ setResolving(true)
+ }
try {
const resource = await window.clerum.gfs.resolve(uri.trim())
- if (openUriGenerationRef.current !== generation) return false
+ if (!isCurrent()) return false
const crumb: GfsCrumb = {
resourceId: resource.resourceId,
gfsUri: resource.gfsUri,
@@ -928,7 +938,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
try {
const parentRid = parentResourceId.replace(/-/g, '').toLowerCase()
const parent = await window.clerum.gfs.resolve(`gfs://${resource.drive}/${parentRid}`)
- if (openUriGenerationRef.current !== generation) return false
+ if (!isCurrent()) return false
if (parent.kind !== 'directory') break
if (parent.name) {
ancestors.push({
@@ -948,11 +958,11 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
}
}
- if (openUriGenerationRef.current !== generation) return false
+ if (!isCurrent()) return false
setCrumbsState([...ancestors.reverse(), crumb])
return crumb
} catch (error) {
- if (openUriGenerationRef.current !== generation) return false
+ if (!isCurrent()) return false
const message = toMessage(error)
// Opening a URI is an operation on one resource. A generic 403 may be
// a per-resource policy decision; only a session-authority failure
@@ -972,17 +982,20 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
}
return false
} finally {
- if (openUriGenerationRef.current === generation) setResolving(false)
+ if (!background && openUriGenerationRef.current === generation) setResolving(false)
}
},
[handleAuthorityFailure, queryClient]
)
- const refreshCurrentLocation = useCallback(async () => {
- const uri = current?.gfsUri
- if (!uri) return false
- return openUri(uri, { clearIfUnavailable: true })
- }, [current?.gfsUri, openUri])
+ const refreshCurrentLocation = useCallback(
+ async (options?: { background?: boolean }) => {
+ const uri = current?.gfsUri
+ if (!uri) return false
+ return openUri(uri, { clearIfUnavailable: true, background: options?.background })
+ },
+ [current?.gfsUri, openUri]
+ )
// Move refreshes the old parent's children, the destination's children,
// and the accessible roots in one shot via refreshGfs. The moved resource's
diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsx
index 4344a51e7..49a8952cd 100644
--- a/desktop-app/ui/src/pages/FilesPage.tsx
+++ b/desktop-app/ui/src/pages/FilesPage.tsx
@@ -316,7 +316,7 @@ export function FilesPage({
if (remoteGfsChangeEpoch === undefined) return
if (lastRemoteGfsChangeEpochRef.current === remoteGfsChangeEpoch) return
lastRemoteGfsChangeEpochRef.current = remoteGfsChangeEpoch
- void ctrl.refreshCurrentLocation()
+ void ctrl.refreshCurrentLocation({ background: true })
}, [ctrl.refreshCurrentLocation, remoteGfsChangeEpoch])
// Warm the cache for directory rows in the current view so clicking into a