Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): r6-m1 isolate stream refresh retries
Josuéa7100d4c0441
diff --git a/control-ui/components/GfsBrowser.tsx b/control-ui/components/GfsBrowser.tsxindex 1fbb9d376..699e770b6 100644--- a/control-ui/components/GfsBrowser.tsx+++ b/control-ui/components/GfsBrowser.tsx@@ -405,7 +405,6 @@ export function GfsBrowser(): React.JSX.Element {{ kind: 'video' }> | null>(null)const previewRefreshGenerationRef = useRef(0)- const scheduleEntityChangeRecoveryRef = useRef<(() => void) | null>(null)const openPreviewsRef = useRef<OpenPreviewState[]>([])openPreviewsRef.current = [imagePreview, markdownPreview, videoPreview].filter((preview): preview is OpenPreviewState => preview !== null@@ -550,10 +549,7 @@ export function GfsBrowser(): React.JSX.Element {}} catch (err) {if (!isCurrent()) return- if (isTransientEntityChangeRefetchError(err)) scheduleEntityChangeRecoveryRef.current?.()if (!isSilentApiError(err)) {- // Background revalidation keeps the (stale) rows visible but still- // surfaces the failure instead of silently ignoring it.setError(err instanceof Error ? err.message : 'Failed to load EvenDrive')}} finally {@@ -693,8 +689,6 @@ export function GfsBrowser(): React.JSX.Element {invalidateVisibleState()}, delay)}- scheduleEntityChangeRecoveryRef.current = scheduleRecovery-const revalidateActionTargets = async (signal: AbortSignal) => {const targets = new Map<string, GfsChild>()for (const target of [selectedRef.current, renameTargetRef.current, moveTargetRef.current]) {@@ -748,6 +742,64 @@ export function GfsBrowser(): React.JSX.Element {)}+ const refreshVisibleDirectory = async (crumb: Crumb, signal: AbortSignal): Promise<void> => {+ const path =+ crumb.id === null+ ? '/api/v1/gfs/tree'+ : `/api/v1/gfs/resources/${encodeURIComponent(crumb.id)}/children`+ const targetPageCount = Math.max(1, loadedPageCountRef.current)+ try {+ let page = (await apiGet(path, { drive: DRIVE }, { signal })) as TreePage+ const rootResourceId = page.rootResourceId+ const refreshedItems = [...page.items]+ let nextPageCursor = page.nextCursor+ let fetchedPageCount = 1+ for (let index = 1; index < targetPageCount && nextPageCursor; index += 1) {+ page = (await apiGet(+ path,+ { drive: DRIVE, cursor: nextPageCursor },+ { signal }+ )) as TreePage+ refreshedItems.push(...page.items)+ nextPageCursor = page.nextCursor+ fetchedPageCount += 1+ if (signal.aborted) return+ }+ if (signal.aborted || currentCrumbRef.current?.id !== crumb.id) return+ if (crumb.id === null && rootResourceId) {+ setCrumbs(previous =>+ previous[0]?.id === null+ ? [+ {+ ...previous[0],+ id: rootResourceId,+ rid: ridOfResourceId(rootResourceId),+ },+ ...previous.slice(1),+ ]+ : previous+ )+ }+ setItems(sortChildrenWithDirectoriesFirst(refreshedItems))+ setNextCursor(nextPageCursor)+ loadedPageCountRef.current = fetchedPageCount+ if (crumb.id !== null) {+ childCacheRef.current.set(crumb.id, {+ items: refreshedItems,+ nextCursor: nextPageCursor,+ loadedPageCount: fetchedPageCount,+ })+ }+ setError('')+ } catch (error) {+ if (signal.aborted || currentCrumbRef.current?.id !== crumb.id) return+ if (!isSilentApiError(error)) {+ setError(error instanceof Error ? error.message : 'Failed to refresh EvenDrive')+ }+ if (isTransientEntityChangeRefetchError(error)) scheduleRecovery()+ }+ }+invalidateVisibleState = (cursor?: string) => {// A committed remote change supersedes any local move/retry ancestry// reconstruction still in flight. Its older response must not replace@@ -765,7 +817,6 @@ export function GfsBrowser(): React.JSX.Element {const signal = revalidationController.signalchildCacheRef.current.clear()revalidateNextLoadRef.current = false- setError('')void revalidateActionTargets(signal)const previews = openPreviewsRef.currentif (previews.length > 0) {@@ -900,10 +951,9 @@ export function GfsBrowser(): React.JSX.Element {}const visibleCrumb = currentCrumbRef.currentif (!visibleCrumb) return- // Keep loaded rows, pagination, selection, and action dialogs visible- // while the authoritative background read runs. `load` has a separate- // sequence for background work, so it cannot cancel user navigation.- void load(visibleCrumb, undefined, { background: true, signal })+ // Stream-triggered reads have their own non-destructive path. They never+ // enter the navigation/paging loader or clear its rows, dialogs, or error.+ void refreshVisibleDirectory(visibleCrumb, signal)if (visibleCrumb.id === null) returnconst visibleResourceId = visibleCrumb.id@@ -1034,9 +1084,6 @@ export function GfsBrowser(): React.JSX.Element {entityChangeRefetchControllerRef.current = nullif (retryTimer) clearTimeout(retryTimer)if (recoveryTimer) clearTimeout(recoveryTimer)- if (scheduleEntityChangeRecoveryRef.current === scheduleRecovery) {- scheduleEntityChangeRecoveryRef.current = null- }}}, [load])diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsxindex 607017e88..8070c8689 100644--- a/control-ui/components/__tests__/GfsBrowser.test.tsx+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx@@ -781,6 +781,82 @@ describe('GfsBrowser', () => {)})+ it('keeps the visible error and browser state while a stream refresh retries', async () => {+ const streamControllers: ReadableStreamDefaultController<Uint8Array>[] = []+ const report = child('report.md', 'file', 1, 2)+ mockApiGet.mockResolvedValueOnce({ items: [report], nextCursor: null })+ vi.stubGlobal(+ 'fetch',+ vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {+ const body = new ReadableStream<Uint8Array>({+ start(controller) {+ streamControllers.push(controller)+ init?.signal?.addEventListener('abort', () => controller.close(), { once: true })+ },+ })+ return new Response(body, {+ status: 200,+ headers: { 'content-type': 'application/x-ndjson' },+ })+ })+ )++ renderBrowser()+ await waitFor(() => expect(streamControllers).toHaveLength(1))+ await screen.findByRole('button', { name: 'report.md' })+ await openResourceMenu('report.md')+ fireEvent.click(screen.getByRole('menuitem', { name: 'Rename' }))+ const dialog = await screen.findByRole('dialog', { name: 'Rename file' })+ const frame = await controlApiProducerFrame()++ let releaseRetry: ((page: { items: (typeof report)[]; nextCursor: null }) => void) | undefined+ let treeReads = 0+ mockApiGet.mockImplementation(async (path: string, query?: Record<string, string>) => {+ if (path === '/api/v1/gfs/tree') {+ treeReads += 1+ if (treeReads === 1) {+ throw Object.assign(new Error('503 Service Unavailable'), { status: 503 })+ }+ return new Promise(resolve => {+ releaseRetry = resolve+ })+ }+ if (path === '/api/v1/gfs/resolve' && query?.uri === report.gfsUri) {+ return {+ resourceId: report.resourceId,+ rid: report.rid,+ gfsUri: report.gfsUri,+ name: report.name,+ kind: report.kind,+ bytes: report.bytes,+ version: report.version,+ }+ }+ return { items: [], nextCursor: null }+ })++ await act(async () => {+ streamControllers[0]!.enqueue(new TextEncoder().encode(`${frame}\n`))+ })+ await waitFor(() => expect(treeReads).toBe(1))+ expect(screen.getByRole('button', { name: 'report.md' })).toBeVisible()+ expect(screen.getByRole('dialog', { name: 'Rename file' })).toBe(dialog)+ expect(screen.getByRole('alert')).toHaveTextContent('503 Service Unavailable')++ await waitFor(() => expect(releaseRetry).toBeDefined(), { timeout: 1500 })+ expect(treeReads).toBe(2)+ expect(screen.getByRole('button', { name: 'report.md' })).toBeVisible()+ expect(screen.getByRole('dialog', { name: 'Rename file' })).toBe(dialog)+ expect(screen.getByRole('alert')).toHaveTextContent('503 Service Unavailable')++ await act(async () => {+ releaseRetry?.({ items: [report], nextCursor: null })+ })+ expect(screen.getByRole('button', { name: 'report.md' })).toBeVisible()+ expect(screen.getByRole('dialog', { name: 'Rename file' })).toBe(dialog)+ expect(screen.queryByRole('alert')).toBeNull()+ })+it.each(['avatar.PNG', 'notes.md', 'demo.mp4'])('does not reload an unchanged open %s preview after a scope invalidation',async fileName => {diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 871fc5353..491f2716d 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.663",+ "version": "0.1.664","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.663",+ "version": "0.1.664","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-components": "file:../packages/frontend-components",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 42dfc7727..fa162db2a 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.663",+ "version": "0.1.664","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",