Skip to content

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

TypeScript

fix(evendrive): rebuild move-recovery ancestry from live crumb state

Md98066de6ff3
diff --git a/control-ui/components/GfsBrowser.tsx b/control-ui/components/GfsBrowser.tsx
index 1d97fe937..48bb7fc4e 100644
--- a/control-ui/components/GfsBrowser.tsx
+++ b/control-ui/components/GfsBrowser.tsx
@@ -251,11 +251,13 @@ export function GfsBrowser(): React.JSX.Element {
// 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.
+ // operator navigates away from the moved folder. The snapshot carries
+ // IMMUTABLE identity only (R7-M1): name and version are deliberately NOT
+ // captured, so a retry can never replay move-time metadata over a crumb
+ // that a later rename/mutation has since advanced.
const [trailRecovery, setTrailRecovery] = useState<{
- source: GfsChild
- moveName: string
- version: number | undefined
+ resourceId: string
+ gfsUri: string
} | null>(null)
const draggingResourceRef = useRef<GfsChild | null>(null)
const movingResourceRef = useRef<string | null>(null)
@@ -487,7 +489,7 @@ export function GfsBrowser(): React.JSX.Element {
// stale trail it labels is no longer on screen.
useEffect(() => {
if (!trailRecovery) return
- if (!crumbs.some(crumb => crumb.id === trailRecovery.source.resourceId)) {
+ if (!crumbs.some(crumb => crumb.id === trailRecovery.resourceId)) {
setTrailRecovery(null)
}
}, [crumbs, trailRecovery])
@@ -690,9 +692,7 @@ export function GfsBrowser(): React.JSX.Element {
// is part of the open breadcrumb trail, patching only its own crumb
// would leave every crumb above it describing the OLD location (R5-M1):
// with /org open and /org moved under /archive, the trail must become
- // main / archive / org — not stay main / org. Rebuild the trail from
- // the folder's new location instead; the children effect reloads the
- // trail's leaf afterwards.
+ // main / archive / org — not stay main / org.
const movedCrumbIndex = crumbs.findIndex(crumb => crumb.id === source.resourceId)
if (movedCrumbIndex >= 0) {
// The listing the moved folder left behind (its old parent, an
@@ -700,28 +700,32 @@ 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)
- const rebuilt = await rebuildTrailFromNewLocation(source, moveName, nextVersion)
+ // The crumb adopts the receipt metadata FIRST — this is the
+ // resource's truthful post-move state. The ancestry rebuild below
+ // (and any later retry of it) preserves this metadata from LIVE
+ // crumb state, never from a move-time snapshot (R7-M1), so a rename
+ // that lands while recovery is pending is never rolled back.
+ setCrumbs(prev =>
+ prev.map(crumb =>
+ crumb.id === source.resourceId
+ ? {
+ ...crumb,
+ name: moveName,
+ ...(nextVersion === undefined
+ ? { version: undefined }
+ : { version: nextVersion }),
+ }
+ : crumb
+ )
+ )
+ const rebuilt = await rebuildTrailFromNewLocation(source.resourceId, source.gfsUri)
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 })
+ // authoritative) and surface a recovery notice with a retry until
+ // reconstruction succeeds.
+ setTrailRecovery({ resourceId: source.resourceId, gfsUri: source.gfsUri })
}
return
}
@@ -737,25 +741,25 @@ export function GfsBrowser(): React.JSX.Element {
}
}
- /** Rebuild the breadcrumb trail from a moved trail-folder's NEW location.
- * 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.
+ /** Rebuild the breadcrumb trail ANCESTRY for a moved trail-folder. 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.
+ *
+ * This touches ancestry ONLY: the moved crumb and every crumb below it
+ * are carried over from the LIVE trail (R7-M1), so a rename or other
+ * mutation that landed while recovery was pending keeps its newer
+ * name/version — no move-time snapshot is ever replayed.
*
* 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<boolean> {
+ async function rebuildTrailFromNewLocation(resourceId: string, gfsUri: string): Promise<boolean> {
let view: { path?: string | null }
try {
- view = (await apiGet('/api/v1/gfs/resolve', { uri: source.gfsUri })) as {
+ view = (await apiGet('/api/v1/gfs/resolve', { uri: gfsUri })) as {
path?: string | null
}
} catch {
@@ -782,42 +786,29 @@ export function GfsBrowser(): React.JSX.Element {
})
}
setCrumbs(prev => {
- const index = prev.findIndex(crumb => crumb.id === source.resourceId)
+ const index = prev.findIndex(crumb => crumb.id === resourceId)
// The user navigated while the resolve walk was in flight — never
// clobber the trail they navigated to.
if (index < 0) return prev
return [
{ id: null, rid: null, name: '/' },
...ancestors,
- ...prev.slice(index).map((crumb, position) =>
- position === 0
- ? {
- ...crumb,
- name: moveName,
- // Without a receipt version the pre-move version is stale by
- // definition; drop it so the crumb honestly loses its
- // mutating menu (crumbToChild → null) instead of issuing a
- // guaranteed-conflict ifMatch later.
- ...(nextVersion === undefined ? { version: undefined } : { version: nextVersion }),
- }
- : crumb
- ),
+ // Live crumb state (name/version included) — see the doc note above.
+ ...prev.slice(index),
]
})
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. */
+ /** Retry a failed post-move trail ancestry reconstruction. Runs from the
+ * recovery snapshot's IMMUTABLE identity plus the live trail — never a
+ * captured name/version — so the rebuilt crumb reflects every mutation
+ * that landed since the move. The notice stays up on a second failure;
+ * the trail is only swapped once a retry has fully rebuilt it. */
async function retryTrailRecovery(): Promise<void> {
const recovery = trailRecovery
if (!recovery) return
- const rebuilt = await rebuildTrailFromNewLocation(
- recovery.source,
- recovery.moveName,
- recovery.version
- )
+ const rebuilt = await rebuildTrailFromNewLocation(recovery.resourceId, recovery.gfsUri)
if (rebuilt) setTrailRecovery(null)
}
@@ -1449,8 +1440,11 @@ export function GfsBrowser(): React.JSX.Element {
{trailRecovery ? (
<div className="cu-banner cu-banner--warning cu-banner--dismissible" role="alert">
<span>
- &ldquo;{trailRecovery.moveName}&rdquo; moved, but its folder path could not be
- refreshed — the breadcrumb may not show the real location.
+ &ldquo;
+ {crumbs.find(crumb => crumb.id === trailRecovery.resourceId)?.name ??
+ trailRecovery.resourceId}
+ &rdquo; 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
diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsx
index 2b695864c..addc836ce 100644
--- a/control-ui/components/__tests__/GfsBrowser.test.tsx
+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx
@@ -1890,6 +1890,144 @@ describe('GfsBrowser', () => {
await waitFor(() => expect(screen.queryByRole('alert')).toBeNull())
})
+ // R7-M1: the recovery snapshot must carry IDENTITY only. A rename that
+ // lands between the failed post-move reconstruction and Retry keeps its
+ // newer name/version — Retry rebuilds the ancestry from the server and the
+ // crumb metadata from LIVE state, never replaying the move-time snapshot.
+ it('retry preserves a rename that landed while move recovery was pending', 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')
+ // Retry resolves the RENAMED folder at its real new location.
+ return resolveView(org.resourceId, org.rid, 'org-renamed', '/archive/org-renamed')
+ }
+ 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 },
+ })
+ .mockResolvedValueOnce({
+ ok: true,
+ data: { resourceId: org.resourceId, version: 9 },
+ })
+ .mockResolvedValueOnce({
+ ok: true,
+ data: { resourceId: org.resourceId, version: 10 },
+ })
+ 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)
+ // Move /work/org under /archive — the PATCH succeeds (version 7 → 8)…
+ 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).toHaveBeenNthCalledWith(
+ 1,
+ 'PATCH',
+ `/api/v1/gfs/resources/${org.resourceId}`,
+ { drive: 'main', newParentId: archive.resourceId, ifMatch: 7 },
+ { drive: 'main' }
+ )
+ )
+ // …but reconstruction fails: stale trail kept, warning + Retry shown.
+ const notice = await screen.findByRole('alert')
+ expect(within(notice).getByRole('button', { name: 'Retry' })).toBeTruthy()
+ expect(labels()).toEqual(['main', 'work', 'org', 'Actions for org'])
+
+ // BEFORE Retry: rename the active crumb. It succeeds and advances the
+ // name/version (8 → 9, 'org' → 'org-renamed').
+ fireEvent.click(within(breadcrumb).getByRole('button', { name: 'Actions for org' }))
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Rename' }))
+ const renameForm = await within(breadcrumb).findByRole('form', { name: 'Rename resource' })
+ fireEvent.change(within(renameForm).getByLabelText('New name'), {
+ target: { value: 'org-renamed' },
+ })
+ fireEvent.click(within(renameForm).getByRole('button', { name: 'Save name' }))
+ await waitFor(() =>
+ expect(mockApiSend).toHaveBeenNthCalledWith(
+ 2,
+ 'PATCH',
+ `/api/v1/gfs/resources/${org.resourceId}`,
+ { drive: 'main', newName: 'org-renamed', ifMatch: 8 },
+ { drive: 'main' }
+ )
+ )
+ await waitFor(() =>
+ expect(within(breadcrumb).getByRole('button', { name: 'org-renamed' })).toBeTruthy()
+ )
+ // The notice reads the LIVE crumb name, not a move-time snapshot.
+ expect(screen.getByRole('alert').textContent).toContain('org-renamed')
+
+ // Retry now succeeds: the ancestry rebuilds from the server while the
+ // crumb keeps the renamed identity and version 9.
+ fireEvent.click(within(screen.getByRole('alert')).getByRole('button', { name: 'Retry' }))
+ await waitFor(() =>
+ expect(labels()).toEqual(['main', 'archive', 'org-renamed', 'Actions for org-renamed'])
+ )
+ await waitFor(() => expect(screen.queryByRole('alert')).toBeNull())
+
+ // The next breadcrumb mutation uses the LATEST version (9), not the
+ // earlier Move version (8) — a stale ifMatch here would 409.
+ fireEvent.click(within(breadcrumb).getByRole('button', { name: 'Actions for org-renamed' }))
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Rename' }))
+ const finalRenameForm = await within(breadcrumb).findByRole('form', { name: 'Rename resource' })
+ fireEvent.change(within(finalRenameForm).getByLabelText('New name'), {
+ target: { value: 'org-final' },
+ })
+ fireEvent.click(within(finalRenameForm).getByRole('button', { name: 'Save name' }))
+ await waitFor(() =>
+ expect(mockApiSend).toHaveBeenNthCalledWith(
+ 3,
+ 'PATCH',
+ `/api/v1/gfs/resources/${org.resourceId}`,
+ { drive: 'main', newName: 'org-final', ifMatch: 9 },
+ { drive: 'main' }
+ )
+ )
+ await waitFor(() =>
+ expect(within(breadcrumb).getByRole('button', { name: 'org-final' })).toBeTruthy()
+ )
+ })
+
it('does not fall back to legacy when replacing a persisted resumable session', async () => {
const lastModified = 1_725_000_000_000
const uploadId = '66666666-6666-4666-8666-666666666666'
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index d6f52cf37..9ad09d12d 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.612",
+ "version": "0.1.613",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.612",
+ "version": "0.1.613",
"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.json
index 554a7f1c1..89c0b1731 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.612",
+ "version": "0.1.613",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",