Skip to content

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

TypeScript

fix(desktop): med-transport-loss converge the cache after a verified-committed move

Mb9b4e232b3ad
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
index 7824d399f..bad166f4f 100644
--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
@@ -707,6 +707,11 @@ export function FileExplorerTree({
movingResourceIdRef.current = source.resourceId
setMovingResourceId(source.resourceId)
try {
+ // A transport loss after dispatch leaves the mutation REJECTED even
+ // though the PATCH landed. The commit verifies that by resolve; the
+ // convergence then has to run here, because the mutation's own success
+ // path never did.
+ let dispatchConfirmed = false
const outcome = await commitGfsMove(
{
resolveSource: async gfsUri => {
@@ -720,14 +725,17 @@ export function FileExplorerTree({
parentResourceId: resolved.parentResourceId,
}
},
- moveResource: (resourceId, destinationId, ifMatch, newName) =>
- ctrl.moveResource(
+ moveResource: async (resourceId, destinationId, ifMatch, newName) => {
+ const receipt = await ctrl.moveResource(
resourceId,
destinationId,
ifMatch,
newName,
source.parentKnown ? source.parentResourceId : null
- ),
+ )
+ dispatchConfirmed = true
+ return receipt
+ },
isSessionAuthorityFailure: error =>
ctrl.handleAuthorityFailure(
error instanceof Error ? error.message : String(error),
@@ -747,6 +755,20 @@ export function FileExplorerTree({
occupiedDestinationNames: cachedDestinationNames(destination.resourceId),
}
)
+ if (outcome.status === 'committed' && !dispatchConfirmed) {
+ // The PATCH landed but the response was lost: the mutation rejected,
+ // so its success path (and the convergence it owns) never ran. The
+ // item HAS moved — converge the cache now so it stops rendering in
+ // the old folder.
+ await ctrl.convergeCommittedMove(
+ {
+ resourceId: source.resourceId,
+ destinationId: destination.resourceId,
+ oldParentId: outcome.previousParentId,
+ },
+ { version: outcome.version }
+ )
+ }
toastMoveOutcome(pushToast, outcome, source.name, destination.name, source.kind)
return outcome
} finally {
diff --git a/desktop-app/ui/src/gfs/__tests__/dragOwnership.test.tsx b/desktop-app/ui/src/gfs/__tests__/dragOwnership.test.tsx
index cf2331a07..3c145af98 100644
--- a/desktop-app/ui/src/gfs/__tests__/dragOwnership.test.tsx
+++ b/desktop-app/ui/src/gfs/__tests__/dragOwnership.test.tsx
@@ -92,6 +92,7 @@ function baseController() {
replaceFileFromPath: vi.fn(),
renameResource: vi.fn(),
moveResource: vi.fn(),
+ convergeCommittedMove: vi.fn(),
deleteResource: vi.fn(),
mutating: false,
reset: vi.fn(),
@@ -476,5 +477,34 @@ for (const surface of ['sidebar', 'files'] as const) {
expect(h.moveResource).not.toHaveBeenCalled()
expect(h.toast).not.toHaveBeenCalled()
})
+
+ it('converges the cache when the move landed but its response was lost', async () => {
+ // The PATCH lands, the response never arrives: the mutation REJECTS, so
+ // the mutation's own success path (and the convergence it owns) never
+ // runs. The commit verifies the move by resolve, and the surface then
+ // converges the cache itself — otherwise the item keeps rendering in
+ // the old folder until the next navigation.
+ const h = await setup('file')
+ const original = h.resolve.getMockImplementation()!
+ let resolveCalls = 0
+ h.resolve.mockImplementation(async (uri: string) => {
+ resolveCalls += 1
+ const resolved = await original(uri)
+ // The commit-time resolve still sees the OLD parent; the verification
+ // resolve sees the item in the destination.
+ return resolveCalls >= 2 ? { ...resolved, parentResourceId: 'target' } : resolved
+ })
+ h.moveResource.mockImplementationOnce(async () => {
+ throw new Error('network error')
+ })
+ h.start()
+ h.drop()
+ await waitFor(() => expect(h.ctrl.convergeCommittedMove).toHaveBeenCalled())
+ expect(h.ctrl.convergeCommittedMove).toHaveBeenCalledWith(
+ { resourceId: 'source', destinationId: 'target', oldParentId: 'grand' },
+ { version: expect.any(Number) }
+ )
+ expect(h.toast).toHaveBeenCalledWith('Moved Source to Target', 'success')
+ })
})
}
diff --git a/desktop-app/ui/src/gfs/__tests__/moveCommit.test.ts b/desktop-app/ui/src/gfs/__tests__/moveCommit.test.ts
index a808331ee..e82386a26 100644
--- a/desktop-app/ui/src/gfs/__tests__/moveCommit.test.ts
+++ b/desktop-app/ui/src/gfs/__tests__/moveCommit.test.ts
@@ -37,7 +37,7 @@ describe('commitGfsMove — commit-time source refresh', () => {
it('resolves the source and sends exactly one PATCH with the fresh version and ifMatch', async () => {
const moveResource = vi.fn(async () => ({ resourceId: 'r-1', version: 8 }))
const outcome = await commitGfsMove(deps({ moveResource }), plan())
- expect(outcome).toEqual({ status: 'committed', version: 8 })
+ expect(outcome).toEqual({ status: 'committed', version: 8, previousParentId: 'old-parent' })
expect(moveResource).toHaveBeenCalledTimes(1)
expect(moveResource).toHaveBeenCalledWith('r-1', 'dest-1', 7, undefined)
})
@@ -109,7 +109,12 @@ describe('commitGfsMove — conflict policy (rev-2 §5)', () => {
return { resourceId: 'r-1', version: 9 }
})
const outcome = await commitGfsMove(deps({ moveResource }), plan({ allowNumberedRename: true }))
- expect(outcome).toEqual({ status: 'committed', version: 9, renamedTo: 'report (1).md' })
+ expect(outcome).toEqual({
+ status: 'committed',
+ version: 9,
+ renamedTo: 'report (1).md',
+ previousParentId: 'old-parent',
+ })
expect(moveResource).toHaveBeenCalledTimes(2)
expect(moveResource).toHaveBeenLastCalledWith('r-1', 'dest-1', 7, 'report (1).md')
})
@@ -138,7 +143,12 @@ describe('commitGfsMove — conflict policy (rev-2 §5)', () => {
occupiedDestinationNames: new Set(['report.md', 'report (1).md', 'report (2).md']),
})
)
- expect(outcome).toEqual({ status: 'committed', version: 10, renamedTo: 'report (3).md' })
+ expect(outcome).toEqual({
+ status: 'committed',
+ version: 10,
+ renamedTo: 'report (3).md',
+ previousParentId: 'old-parent',
+ })
expect(moveResource).toHaveBeenCalledTimes(2)
expect(moveResource).toHaveBeenLastCalledWith('r-1', 'dest-1', 7, 'report (3).md')
})
@@ -204,7 +214,11 @@ describe('commitGfsMove — server verdicts', () => {
// Post-loss verification: the move actually landed.
.mockResolvedValueOnce(resolved({ parentResourceId: 'dest-1', version: 11 }))
const outcome = await commitGfsMove(deps({ moveResource, resolveSource }), plan())
- expect(outcome).toEqual({ status: 'committed', version: 11 })
+ expect(outcome).toEqual({
+ status: 'committed',
+ version: 11,
+ previousParentId: 'old-parent',
+ })
expect(moveResource).toHaveBeenCalledTimes(1)
})
@@ -253,7 +267,7 @@ describe('commitGfsMove — gesture ownership (rev-2 §4.1)', () => {
it('dispatches when the gesture is still current', async () => {
const moveResource = vi.fn(async () => ({ resourceId: 'r-1', version: 8 }))
const outcome = await commitGfsMove(deps({ moveResource, isCurrent: () => true }), plan())
- expect(outcome).toEqual({ status: 'committed', version: 8 })
+ expect(outcome).toEqual({ status: 'committed', version: 8, previousParentId: 'old-parent' })
expect(moveResource).toHaveBeenCalledTimes(1)
})
})
diff --git a/desktop-app/ui/src/gfs/moveCommit.ts b/desktop-app/ui/src/gfs/moveCommit.ts
index 5d33fda7e..3e6ca8646 100644
--- a/desktop-app/ui/src/gfs/moveCommit.ts
+++ b/desktop-app/ui/src/gfs/moveCommit.ts
@@ -27,7 +27,19 @@ export interface MoveCommitPlan {
}
export type MoveCommitOutcome =
- | { status: 'committed'; version: number; renamedTo?: string }
+ | {
+ status: 'committed'
+ version: number
+ renamedTo?: string
+ /**
+ * The parent the item lived in at COMMIT time (the fresh resolve's
+ * observation, never the drag-start guess). The convergence needs the
+ * real old parent to drop the item from that folder's cached listing —
+ * including on the transport-loss path, where the mutation that would
+ * normally converge it never succeeded.
+ */
+ previousParentId: string | null
+ }
| { status: 'no-op'; message: string }
| { status: 'conflict-stopped'; message: string }
| { status: 'changed'; message: string }
@@ -129,6 +141,7 @@ export async function commitGfsMove(
return {
status: 'committed',
version: receipt.version,
+ previousParentId: snapshot.parentResourceId,
...(moveName !== snapshot.name ? { renamedTo: moveName } : {}),
}
} catch (attemptError) {
@@ -216,6 +229,10 @@ async function verifyOutcomeByResolve(
return {
status: 'committed',
version: resolved.version,
+ // The pre-move parent from the commit-time resolve: the transport-loss
+ // path has no mutation receipt to converge with, so the outcome
+ // carries the parent the item actually left.
+ previousParentId: before.parentResourceId,
...(resolved.name !== before.name ? { renamedTo: resolved.name } : {}),
}
}
diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
index 86adde4ab..441f0300c 100644
--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
@@ -1091,22 +1091,22 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
// reconcile navigation to the new location (resolve + ancestor walk) so a
// follow-up Rename/Delete/Move runs with the post-move version, not the
// pre-move one (which would 409 on ifMatch).
- const moveResourceMutation = useMutation({
- mutationFn: (input: {
- resourceId: string
- destinationId: string
- ifMatch?: number
- newName?: string
- oldParentId?: string | null
- }) =>
- window.clerum.gfs.moveResource(
- input.resourceId,
- input.destinationId,
- DRIVE,
- input.ifMatch,
- input.newName
- ),
- onSuccess: async (receipt, input) => {
+ //
+ // The convergence is a named step because it has TWO entry points: the
+ // mutation's success path, and the transport-loss path where the PATCH
+ // landed but its response never arrived (the mutation rejected, so its
+ // success path never ran — without this the item kept rendering in the old
+ // folder until the next navigation).
+ const convergeCommittedMove = useCallback(
+ async (
+ input: {
+ resourceId: string
+ destinationId: string
+ newName?: string
+ oldParentId?: string | null
+ },
+ receipt: { version: number }
+ ) => {
const movedCrumb = crumbs.find(crumb => crumb.resourceId === input.resourceId)
setCrumbs(prev =>
prev.map(crumb =>
@@ -1130,6 +1130,27 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
}
if (movedCrumb) await openUri(movedCrumb.gfsUri)
},
+ [crumbs, openUri, queryClient, refreshGfs, sessionScope]
+ )
+
+ const moveResourceMutation = useMutation({
+ mutationFn: (input: {
+ resourceId: string
+ destinationId: string
+ ifMatch?: number
+ newName?: string
+ oldParentId?: string | null
+ }) =>
+ window.clerum.gfs.moveResource(
+ input.resourceId,
+ input.destinationId,
+ DRIVE,
+ input.ifMatch,
+ input.newName
+ ),
+ onSuccess: async (receipt, input) => {
+ await convergeCommittedMove(input, receipt)
+ },
onError: failClosedOnMutationError,
})
@@ -1378,6 +1399,12 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
}),
deleteResource: (resourceId: string, ifMatch?: number) =>
deleteResourceMutation.mutateAsync({ resourceId, ifMatch }),
+ /**
+ * Convergence for a move that landed without a receipt (transport loss):
+ * the mutation rejected, so its success path never ran, and the item would
+ * otherwise keep rendering in the old folder until the next navigation.
+ */
+ convergeCommittedMove,
mutating:
createFolderMutation.isPending ||
createFileMutation.isPending ||
diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsx
index fb091055e..636816cb5 100644
--- a/desktop-app/ui/src/pages/FilesPage.tsx
+++ b/desktop-app/ui/src/pages/FilesPage.tsx
@@ -1338,6 +1338,11 @@ export function FilesPage({
movingResourceRef.current = source.resourceId
setMovingResourceId(source.resourceId)
try {
+ // A transport loss after dispatch leaves the mutation REJECTED even
+ // though the PATCH landed. The commit verifies that by resolve; the
+ // convergence then has to run here, because the mutation's own success
+ // path never did.
+ let dispatchConfirmed = false
const outcome = await commitGfsMove(
{
resolveSource: async gfsUri => {
@@ -1351,14 +1356,17 @@ export function FilesPage({
parentResourceId: resolved.parentResourceId,
}
},
- moveResource: (resourceId, destinationId, ifMatch, newName) =>
- ctrl.moveResource(
+ moveResource: async (resourceId, destinationId, ifMatch, newName) => {
+ const receipt = await ctrl.moveResource(
resourceId,
destinationId,
ifMatch,
newName,
source.parentKnown ? source.parentResourceId : null
- ),
+ )
+ dispatchConfirmed = true
+ return receipt
+ },
isSessionAuthorityFailure: error => failClosedOnAuthorizationError(error),
...(isCurrent ? { isCurrent } : {}),
},
@@ -1374,6 +1382,20 @@ export function FilesPage({
occupiedDestinationNames: cachedDestinationNames(destination.resourceId),
}
)
+ if (outcome.status === 'committed' && !dispatchConfirmed) {
+ // The PATCH landed but the response was lost: the mutation rejected,
+ // so its success path (and the convergence it owns) never ran. The
+ // item HAS moved — converge the cache now so it stops rendering in
+ // the old folder.
+ await ctrl.convergeCommittedMove(
+ {
+ resourceId: source.resourceId,
+ destinationId: destination.resourceId,
+ oldParentId: outcome.previousParentId,
+ },
+ { version: outcome.version }
+ )
+ }
switch (outcome.status) {
case 'committed':
pushToast?.(
diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
index c7909dfed..e97fe5cb9 100644
--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
@@ -78,6 +78,7 @@ function baseController() {
replaceFileFromPath: vi.fn(),
renameResource: vi.fn(),
moveResource: vi.fn(),
+ convergeCommittedMove: vi.fn(),
deleteResource: vi.fn(),
mutating: false,
reset: vi.fn(),