Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(evendrive): label the stale trail when post-move path reconstruction fails
M7cdb3a0b0d8c
diff --git a/control-ui/components/GfsBrowser.tsx b/control-ui/components/GfsBrowser.tsxindex 5ac029620..1d97fe937 100644--- a/control-ui/components/GfsBrowser.tsx+++ b/control-ui/components/GfsBrowser.tsx@@ -247,6 +247,16 @@ export function GfsBrowser(): React.JSX.Element {const [dragOverFolderId, setDragOverFolderId] = useState<string | null>(null)const [movingResourceId, setMovingResourceId] = useState<string | null>(null)const [moveTarget, setMoveTarget] = useState<GfsChild | null>(null)+ // R5-M1 recovery: the Move PATCH succeeded but the breadcrumb trail could+ // not be reconstructed from the folder's new location. The trail stays+ // as-was — explicitly stale, never shortened and presented as+ // authoritative — with this notice until a retry rebuilds it or the+ // operator navigates away from the moved folder.+ const [trailRecovery, setTrailRecovery] = useState<{+ source: GfsChild+ moveName: string+ version: number | undefined+ } | null>(null)const draggingResourceRef = useRef<GfsChild | null>(null)const movingResourceRef = useRef<string | null>(null)const [imagePreview, setImagePreview] = useState<{@@ -473,6 +483,15 @@ export function GfsBrowser(): React.JSX.Element {// Reload whenever the current folder changes (navigation).}, [current, load])+ // Navigating away from the moved folder retires the recovery notice: the+ // stale trail it labels is no longer on screen.+ useEffect(() => {+ if (!trailRecovery) return+ if (!crumbs.some(crumb => crumb.id === trailRecovery.source.resourceId)) {+ setTrailRecovery(null)+ }+ }, [crumbs, trailRecovery])+useEffect(() => {if ((!selected && !renameTarget) || imagePreview || markdownPreview || videoPreview) returnfunction handleKeyDown(event: KeyboardEvent) {@@ -681,7 +700,29 @@ export function GfsBrowser(): React.JSX.Element {// later navigation revalidates instead of serving the stale page.const oldParent = crumbs[movedCrumbIndex - 1]if (oldParent?.id) childCacheRef.current.delete(oldParent.id)- await rebuildTrailFromNewLocation(source, moveName, nextVersion)+ const rebuilt = await rebuildTrailFromNewLocation(source, moveName, nextVersion)+ if (!rebuilt) {+ // The MOVE succeeded but the trail could not be reconstructed from+ // the new location. Keep the trail the operator was looking at+ // (explicitly stale — never a shortened path presented as+ // authoritative), refresh the moved crumb's own metadata, and+ // surface a recovery notice with a retry until reconstruction+ // succeeds.+ setCrumbs(prev =>+ prev.map(crumb =>+ crumb.id === source.resourceId+ ? {+ ...crumb,+ name: moveName,+ ...(nextVersion === undefined+ ? { version: undefined }+ : { version: nextVersion }),+ }+ : crumb+ )+ )+ setTrailRecovery({ source, moveName, version: nextVersion })+ }return}await refreshCurrent()@@ -700,36 +741,45 @@ export function GfsBrowser(): React.JSX.Element {* The resolve contract answers with the folder's new `path`; every* ancestor prefix is then resolved by-path so the trail reflects the new* ancestor chain rather than the old one. Crumbs below the moved folder- * keep their relative order — its descendants moved with it. Ancestors- * that fail to resolve are dropped, never guessed; a failed leaf resolve- * falls back to the truthful [root, folder] trail (the same partial-trail- * behavior as "Open EvenDrive link"). */+ * keep their relative order — its descendants moved with it.+ *+ * Reconstruction is ALL-OR-NOTHING and returns whether it succeeded: a+ * failed leaf resolve, a null `path`, or any failed ancestor by-path+ * lookup leaves the current trail UNTOUCHED (never a partial ancestry+ * presented as authoritative) so the caller can surface recovery state+ * instead. */async function rebuildTrailFromNewLocation(source: GfsChild,moveName: string,nextVersion: number | undefined- ): Promise<void> {- let ancestors: Crumb[] = []+ ): Promise<boolean> {+ let view: { path?: string | null }try {- const view = (await apiGet('/api/v1/gfs/resolve', { uri: source.gfsUri })) as {+ view = (await apiGet('/api/v1/gfs/resolve', { uri: source.gfsUri })) as {path?: string | null}- const segments =- typeof view.path === 'string' && view.path.length > 1- ? view.path.split('/').filter(segment => segment.length > 0)- : []- for (let depth = 1; depth < segments.length; depth += 1) {- const ancestor = await getGfsResourceByPath(DRIVE, '/' + segments.slice(0, depth).join('/'))- ancestors.push({- id: ancestor.resourceId,- rid: ancestor.rid,- name: ancestor.name,- kind: 'directory',- gfsUri: ancestor.gfsUri,- })- }} catch {- ancestors = []+ return false+ }+ // A null path means the server could not name the new location — that is+ // a failed reconstruction, not a root-level folder ('/org' is).+ if (typeof view.path !== 'string' || view.path.length <= 1) return false+ const segments = view.path.split('/').filter(segment => segment.length > 0)+ const ancestors: Crumb[] = []+ for (let depth = 1; depth < segments.length; depth += 1) {+ let ancestor: Awaited<ReturnType<typeof getGfsResourceByPath>>+ try {+ ancestor = await getGfsResourceByPath(DRIVE, '/' + segments.slice(0, depth).join('/'))+ } catch {+ return false+ }+ ancestors.push({+ id: ancestor.resourceId,+ rid: ancestor.rid,+ name: ancestor.name,+ kind: 'directory',+ gfsUri: ancestor.gfsUri,+ })}setCrumbs(prev => {const index = prev.findIndex(crumb => crumb.id === source.resourceId)@@ -754,6 +804,21 @@ export function GfsBrowser(): React.JSX.Element {),]})+ return true+ }++ /** Retry a failed post-move trail reconstruction. The recovery notice+ * stays up on a second failure — the trail is only swapped once a retry+ * has fully rebuilt it from the new location. */+ async function retryTrailRecovery(): Promise<void> {+ const recovery = trailRecovery+ if (!recovery) return+ const rebuilt = await rebuildTrailFromNewLocation(+ recovery.source,+ recovery.moveName,+ recovery.version+ )+ if (rebuilt) setTrailRecovery(null)}async function handleFolderDrop(@@ -1381,6 +1446,18 @@ export function GfsBrowser(): React.JSX.Element {</div>) : null}+ {trailRecovery ? (+ <div className="cu-banner cu-banner--warning cu-banner--dismissible" role="alert">+ <span>+ “{trailRecovery.moveName}” moved, but its folder path could not be+ refreshed — the breadcrumb may not show the real location.+ </span>+ <Button size="sm" onClick={() => void retryTrailRecovery()}>+ Retry+ </Button>+ </div>+ ) : null}+<div className="cu-gfs-panel"><div className="cu-gfs-panel__toolbar"><nav aria-label="Breadcrumb" className="cu-gfs-breadcrumb">diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsxindex b8d92c488..2b695864c 100644--- a/control-ui/components/__tests__/GfsBrowser.test.tsx+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx@@ -1720,6 +1720,176 @@ describe('GfsBrowser', () => {expect(mockApiSend).not.toHaveBeenCalled()})+ // R5-M1 failure path (leaf resolve fails): after a successful Move PATCH,+ // the breadcrumb must NOT be replaced by a shortened trail presented as+ // authoritative. The stale trail stays on screen, a visible notice says+ // the path could not be refreshed, and Retry rebuilds the trail once+ // resolve recovers.+ it('keeps the stale trail with a retry notice when the post-move resolve fails', async () => {+ const rootId = '11111111-1111-1111-1111-111111111111'+ const work = child('work', 'directory', 1, 3)+ const org = child('org', 'directory', 2, 7)+ const archive = child('archive', 'directory', 3, 5)+ const resolveView = (resourceId: string, rid: string, name: string, path: string) => ({+ resourceId,+ rid,+ gfsUri: `gfs://main/${rid}`,+ drive: 'main',+ name,+ kind: 'directory',+ path,+ updatedAt: '2026-09-24T00:00:00.000Z',+ })+ let resolveCalls = 0+ mockApiGet.mockImplementation(async (path: string) => {+ if (path === '/api/v1/gfs/tree' || path === `/api/v1/gfs/resources/${rootId}/children`) {+ return { rootResourceId: rootId, items: [work, archive], nextCursor: null }+ }+ if (path === `/api/v1/gfs/resources/${work.resourceId}/children`) {+ return { items: [org], nextCursor: null }+ }+ if (path === '/api/v1/gfs/resolve') {+ resolveCalls += 1+ if (resolveCalls === 1) throw new Error('resolve unavailable')+ return resolveView(org.resourceId, org.rid, 'org', '/archive/org')+ }+ return { items: [], nextCursor: null }+ })+ mockGetGfsResourceByPath.mockReset()+ mockGetGfsResourceByPath.mockImplementation(async (_drive: string, path: string) =>+ resolveView(archive.resourceId, archive.rid, archive.name, path)+ )+ mockApiSend.mockResolvedValueOnce({+ ok: true,+ data: { resourceId: org.resourceId, version: 8 },+ })+ renderBrowser()++ // Open /work/org so the pre-move trail is deep enough to prove the+ // stale trail is PRESERVED (work stays in it), not truncated.+ fireEvent.click(await screen.findByRole('button', { name: 'work' }))+ fireEvent.click(await screen.findByRole('button', { name: 'org' }))+ await screen.findByText('No resources are visible in this folder.')++ const breadcrumb = screen.getByRole('navigation', { name: 'Breadcrumb' })+ const labels = () =>+ within(breadcrumb)+ .getAllByRole('button')+ .map(button => button.getAttribute('aria-label') ?? button.textContent)+ fireEvent.click(within(breadcrumb).getByRole('button', { name: 'Actions for org' }))+ fireEvent.click(screen.getByRole('menuitem', { name: 'Move to…' }))+ const moveDialog = await screen.findByRole('dialog', { name: 'Move folder org' })+ fireEvent.click(await within(moveDialog).findByRole('button', { name: 'archive' }))+ fireEvent.click(within(moveDialog).getByRole('button', { name: 'Move here (archive)' }))++ // The Move PATCH succeeded with the pre-move version.+ await waitFor(() =>+ expect(mockApiSend).toHaveBeenCalledWith(+ 'PATCH',+ `/api/v1/gfs/resources/${org.resourceId}`,+ { drive: 'main', newParentId: archive.resourceId, ifMatch: 7 },+ { drive: 'main' }+ )+ )++ // Reconstruction failed: the OLD trail is preserved and explicitly+ // labeled — never shortened to main / org as if reconstruction+ // succeeded.+ const notice = await screen.findByRole('alert')+ expect(notice.textContent).toMatch(/folder path could not be refreshed/)+ expect(within(notice).getByRole('button', { name: 'Retry' })).toBeTruthy()+ expect(labels()).toEqual(['main', 'work', 'org', 'Actions for org'])++ // Retry: resolve now answers, the trail rebuilds from the new location,+ // and the notice clears.+ fireEvent.click(within(notice).getByRole('button', { name: 'Retry' }))+ await waitFor(() => expect(labels()).toEqual(['main', 'archive', 'org', 'Actions for org']))+ await waitFor(() => expect(screen.queryByRole('alert')).toBeNull())+ })++ // R5-M1 failure path (ancestor by-path fails): resolve names the new+ // location, but an ancestor by-path lookup fails. Same contract — the+ // stale trail is preserved and labeled, never partially applied, and+ // Retry rebuilds it once by-path recovers.+ it('keeps the stale trail with a retry notice when a post-move ancestor by-path lookup fails', async () => {+ const rootId = '11111111-1111-1111-1111-111111111111'+ const work = child('work', 'directory', 1, 3)+ const org = child('org', 'directory', 2, 7)+ const archive = child('archive', 'directory', 3, 5)+ const resolveView = (resourceId: string, rid: string, name: string, path: string) => ({+ resourceId,+ rid,+ gfsUri: `gfs://main/${rid}`,+ drive: 'main',+ name,+ kind: 'directory',+ path,+ updatedAt: '2026-09-24T00:00:00.000Z',+ })+ mockApiGet.mockImplementation(async (path: string) => {+ if (path === '/api/v1/gfs/tree' || path === `/api/v1/gfs/resources/${rootId}/children`) {+ return { rootResourceId: rootId, items: [work, archive], nextCursor: null }+ }+ if (path === `/api/v1/gfs/resources/${work.resourceId}/children`) {+ return { items: [org], nextCursor: null }+ }+ if (path === '/api/v1/gfs/resolve') {+ return resolveView(org.resourceId, org.rid, 'org', '/archive/org')+ }+ return { items: [], nextCursor: null }+ })+ let byPathCalls = 0+ mockGetGfsResourceByPath.mockReset()+ mockGetGfsResourceByPath.mockImplementation(async (_drive: string, path: string) => {+ byPathCalls += 1+ if (byPathCalls === 1) throw new Error('by-path unavailable')+ return resolveView(archive.resourceId, archive.rid, archive.name, path)+ })+ mockApiSend.mockResolvedValueOnce({+ ok: true,+ data: { resourceId: org.resourceId, version: 8 },+ })+ renderBrowser()++ fireEvent.click(await screen.findByRole('button', { name: 'work' }))+ fireEvent.click(await screen.findByRole('button', { name: 'org' }))+ await screen.findByText('No resources are visible in this folder.')++ const breadcrumb = screen.getByRole('navigation', { name: 'Breadcrumb' })+ const labels = () =>+ within(breadcrumb)+ .getAllByRole('button')+ .map(button => button.getAttribute('aria-label') ?? button.textContent)+ fireEvent.click(within(breadcrumb).getByRole('button', { name: 'Actions for org' }))+ fireEvent.click(screen.getByRole('menuitem', { name: 'Move to…' }))+ const moveDialog = await screen.findByRole('dialog', { name: 'Move folder org' })+ fireEvent.click(await within(moveDialog).findByRole('button', { name: 'archive' }))+ fireEvent.click(within(moveDialog).getByRole('button', { name: 'Move here (archive)' }))++ await waitFor(() =>+ expect(mockApiSend).toHaveBeenCalledWith(+ 'PATCH',+ `/api/v1/gfs/resources/${org.resourceId}`,+ { drive: 'main', newParentId: archive.resourceId, ifMatch: 7 },+ { drive: 'main' }+ )+ )+ // Resolve DID name the new location; only the ancestor lookup failed —+ // still no partial trail.+ await waitFor(() =>+ expect(mockApiGet).toHaveBeenCalledWith('/api/v1/gfs/resolve', { uri: org.gfsUri })+ )+ expect(byPathCalls).toBe(1)+ const notice = await screen.findByRole('alert')+ expect(notice.textContent).toMatch(/folder path could not be refreshed/)+ expect(within(notice).getByRole('button', { name: 'Retry' })).toBeTruthy()+ expect(labels()).toEqual(['main', 'work', 'org', 'Actions for org'])++ fireEvent.click(within(notice).getByRole('button', { name: 'Retry' }))+ await waitFor(() => expect(labels()).toEqual(['main', 'archive', 'org', 'Actions for org']))+ await waitFor(() => expect(screen.queryByRole('alert')).toBeNull())+ })+it('does not fall back to legacy when replacing a persisted resumable session', async () => {const lastModified = 1_725_000_000_000const uploadId = '66666666-6666-4666-8666-666666666666'diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 3e36f6fe6..d6f52cf37 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.611",+ "version": "0.1.612","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.611",+ "version": "0.1.612","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 10127ee47..554a7f1c1 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.611",+ "version": "0.1.612","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",