Skip to content

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

TypeScript

fix(desktop): r7-b1 bound scope revalidation reads

Josuébd7863ade317
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 3b5e8e0ff..5f25349de 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -39,7 +39,7 @@ import { useWindowFocusBridge } from '@hooks/useWindowFocusBridge'
import type { ChatLocalMatch } from '@lib/chatLocalSearch'
import { buildLoadedChatSemanticModels } from '@lib/chatMessageSemantics'
import { EntityChangeRegistry } from '@lib/entityChangeRegistry'
-import { authoritativeGfsStatus } from '@lib/gfsEntityChangeState'
+import { authoritativeGfsStatus, shouldRevalidateGfsQuery } from '@lib/gfsEntityChangeState'
import { resolveGfsPreview } from '@lib/gfsPreview'
import { desktopQueryClient } from '@lib/queryClient'
import {
@@ -1060,6 +1060,7 @@ export function App() {
// queries refetch; only an authoritative 403/404 purges a preview.
void queryClient.invalidateQueries({
queryKey: desktopQueryKeys.gfsRoot,
+ predicate: query => shouldRevalidateGfsQuery(query.queryKey),
refetchType: 'active',
})
const resources = new Set(
diff --git a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
index 55106f1dc..4b1d9ebd6 100644
--- a/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
+++ b/desktop-app/ui/src/__tests__/App.chatDrawer.test.tsx
@@ -4,8 +4,10 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { useNotificationsContext } from '@contexts/NotificationsContext'
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { DESKTOP_ROUTES } from '@constants/navigation'
+import { desktopQueryKeys } from '@hooks/domain/queryKeys'
import { useAppController } from '@hooks/useAppController'
import type { GfsPreviewResource } from '@lib/gfsPreview'
+import { desktopQueryClient } from '@lib/queryClient'
import {
activeWorkspaceTab,
createWorkspaceTabsState,
@@ -1304,11 +1306,15 @@ describe('App live GFS preview revalidation', () => {
afterEach(() => {
cleanup()
+ vi.restoreAllMocks()
delete (window as { clerum?: unknown }).clerum
})
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
+ .spyOn(desktopQueryClient, 'invalidateQueries')
+ .mockResolvedValue(undefined)
let finishResolve!: (value: ReturnType<typeof resolvedFile>) => void
resolve.mockImplementationOnce(
() =>
@@ -1330,6 +1336,18 @@ describe('App live GFS preview revalidation', () => {
scopes: ['authorization'],
})
)
+ const queryFilter = invalidateQueries.mock.calls.at(-1)?.[0]
+ expect(queryFilter?.queryKey).toEqual(desktopQueryKeys.gfsRoot)
+ expect(
+ queryFilter?.predicate?.({
+ queryKey: desktopQueryKeys.gfsAffordances('session', 'resource-id', 'main'),
+ } as never)
+ ).toBe(false)
+ expect(
+ queryFilter?.predicate?.({
+ queryKey: desktopQueryKeys.gfsChildren('session', 'resource-id', 'main'),
+ } as never)
+ ).toBe(true)
expect(initial()).toEqual(before)
await act(async () => {
diff --git a/desktop-app/ui/src/lib/gfsEntityChangeState.ts b/desktop-app/ui/src/lib/gfsEntityChangeState.ts
index 42d0c3eb4..dea05e06a 100644
--- a/desktop-app/ui/src/lib/gfsEntityChangeState.ts
+++ b/desktop-app/ui/src/lib/gfsEntityChangeState.ts
@@ -9,3 +9,8 @@ export function authoritativeGfsStatus(error: unknown): number | undefined {
const message = error instanceof Error ? error.message : String(error ?? '')
return parseHttpStatus(message) ?? undefined
}
+
+/** Keep long-lived per-resource write affordances out of periodic content refreshes. */
+export function shouldRevalidateGfsQuery(queryKey: readonly unknown[]): boolean {
+ return queryKey[0] === 'desktop-app' && queryKey[1] === 'gfs' && queryKey[3] !== 'affordances'
+}