Skip to content

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

TypeScript

fix(desktop-app): r8-m12 hard-resync permission caches

Josué3e0053a1d43a
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index b8c16c1fa..25e5afd44 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -1105,22 +1105,25 @@ export function App() {
let stopSubscription: (() => Promise<void>) | null = null
let gfsRevalidationInFlight = false
let gfsRevalidationPending = false
+ let gfsHardRecoveryPending = false
const gfsQueryFilter = {
queryKey: desktopQueryKeys.gfsRoot,
predicate: (query: { queryKey: readonly unknown[] }) =>
shouldRevalidateGfsQuery(query.queryKey),
}
- const revalidateGfs = () => {
+ const revalidateGfs = (hardRecovery = false) => {
if (!active) return
if (gfsRevalidationInFlight) {
gfsRevalidationPending = true
+ gfsHardRecoveryPending ||= hardRecovery
return
}
gfsRevalidationInFlight = true
- const foregroundReadWasActive = queryClient.isFetching(gfsQueryFilter) > 0
+ const queryFilter = hardRecovery ? { queryKey: desktopQueryKeys.gfsRoot } : gfsQueryFilter
+ const foregroundReadWasActive = queryClient.isFetching(queryFilter) > 0
setRemoteGfsChangeEpoch(epoch => epoch + 1)
void queryClient
- .invalidateQueries({ ...gfsQueryFilter, refetchType: 'active' }, { cancelRefetch: false })
+ .invalidateQueries({ ...queryFilter, refetchType: 'active' }, { cancelRefetch: false })
.then(async () => {
const resources = new Set(
workspaceTabsRef.current.tabs
@@ -1135,19 +1138,24 @@ export function App() {
gfsRevalidationInFlight = false
if (!active) return
if (gfsRevalidationPending || foregroundReadWasActive) {
+ const nextIsHardRecovery =
+ gfsHardRecoveryPending || (hardRecovery && foregroundReadWasActive)
gfsRevalidationPending = false
- revalidateGfs()
+ gfsHardRecoveryPending = false
+ revalidateGfs(nextIsHardRecovery)
}
})
}
- const unsubscribeGfs = entityChangeRegistry.subscribe(['gfs', 'authorization'], () => {
+ const unsubscribeGfs = entityChangeRegistry.subscribe(['gfs', 'authorization'], event => {
// Scope invalidations are soft convergence hints, not proof that cached
// data is no longer authorized. Keep visible/paginated rows while active
// queries refetch; only an authoritative 403/404 purges a preview.
// TanStack's default refetch cancels an active request. Serialize these
// soft passes and retain one trailing pass so a second frame cannot abort
// a foreground navigation/page chain or lose a mutation during that read.
- revalidateGfs()
+ // Resync also refreshes cached permission affordances; inactive caches stay
+ // invalidated and re-read when they are next mounted.
+ revalidateGfs(event.type === 'resync_required')
})
void entityChangeBridge
.subscribe(event => entityChangeRegistry.dispatch(event))
diff --git a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
index 5121b3285..7add2cd96 100644
--- a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
+++ b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
@@ -1519,6 +1519,51 @@ describe('App live GFS preview revalidation', () => {
expect(listChildren).toHaveBeenCalledTimes(4)
})
+ it('hard-resyncs active permission affordances as well as open previews', async () => {
+ const affordanceKey = desktopQueryKeys.gfsAffordances('session', 'folder', 'main')
+ const affordances = vi.fn(async () => ({ held: ['read'] }))
+ Object.assign(window.clerum.gfs, { affordances })
+ desktopQueryClient.setQueryData(affordanceKey, { held: [] })
+ const resolve = vi.mocked(window.clerum.gfs.resolve).mockResolvedValue(
+ resolvedFile('readme', 'README.md', {
+ gfsUri: 'gfs://main/readme',
+ bytes: 14,
+ version: 4,
+ }) as never
+ )
+
+ function CurrentFolderAffordances() {
+ useQuery({
+ queryKey: affordanceKey,
+ queryFn: () => window.clerum.gfs.affordances('folder', 'main'),
+ })
+ return null
+ }
+
+ render(
+ <QueryClientProvider client={desktopQueryClient}>
+ <CurrentFolderAffordances />
+ <App />
+ </QueryClientProvider>
+ )
+ await waitFor(() => expect(dispatchEntityChange).toBeTypeOf('function'))
+ act(() =>
+ dispatchEntityChange?.({
+ schemaVersion: 1,
+ type: 'resync_required',
+ cursor: '00000000-0000-0000-0000-000000000000',
+ scopes: ['gfs', 'authorization'],
+ })
+ )
+
+ await waitFor(() => expect(affordances).toHaveBeenCalledTimes(1))
+ await waitFor(() => expect(resolve).toHaveBeenCalledTimes(1))
+ expect(desktopQueryClient.getQueryData(affordanceKey)).toEqual({ held: ['read'] })
+ expect(
+ currentController.workspaceTabs.tabs.find(tab => tab.id === 'preview-md')?.preview
+ ).toMatchObject({ resourceVersion: 4 })
+ })
+
it('preserves an unchanged preview during soft scope revalidation and purges only on 403', async () => {
const resolve = vi.mocked(window.clerum.gfs.resolve)
const invalidateQueries = vi