Skip to content

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

TypeScript

fix(desktop): med-5xx-as-conflict classify a name conflict only by its 409 status

M0eaded4841a8
diff --git a/desktop-app/ui/src/gfs/__tests__/moveCommit.test.ts b/desktop-app/ui/src/gfs/__tests__/moveCommit.test.ts
index 43c860de2..3ea52515b 100644
--- a/desktop-app/ui/src/gfs/__tests__/moveCommit.test.ts
+++ b/desktop-app/ui/src/gfs/__tests__/moveCommit.test.ts
@@ -230,6 +230,55 @@ describe('commitGfsMove — server verdicts', () => {
expect(outcome.status).toBe('unconfirmed')
expect(moveResource).toHaveBeenCalledTimes(1)
})
+
+ it('a validated 5xx that merely mentions "already exists" is not a name conflict', async () => {
+ // The vetted status is the verdict. A 5xx body can carry the phrase for
+ // any reason; re-PATCHing under a new name would rename an item the
+ // server never rejected.
+ const moveResource = vi.fn(async () => {
+ throw new Error(
+ 'Error invoking remote method: Error: 500 Internal Server Error: a resource with this name already exists httpStatus=500'
+ )
+ })
+ const outcome = await commitGfsMove(deps({ moveResource }), plan({ allowNumberedRename: true }))
+ expect(outcome.status).toBe('unconfirmed')
+ // No numbered-name retry: the move was never a collision.
+ expect(moveResource).toHaveBeenCalledTimes(1)
+ })
+
+ it('a validated 503 that mentions "already exists" is verified, never retried', async () => {
+ const moveResource = vi.fn(async () => {
+ throw new Error(
+ 'Error invoking remote method: Error: 503 Service Unavailable: destination already exists upstream httpStatus=503'
+ )
+ })
+ const resolveSource = vi
+ .fn()
+ .mockResolvedValueOnce(resolved())
+ .mockResolvedValueOnce(resolved({ parentResourceId: 'dest-1', version: 12 }))
+ const outcome = await commitGfsMove(
+ deps({ moveResource, resolveSource }),
+ plan({ allowNumberedRename: true })
+ )
+ // The move actually landed: the outcome is verified, not retried.
+ expect(outcome).toEqual({
+ status: 'committed',
+ version: 12,
+ previousParentId: 'old-parent',
+ })
+ expect(moveResource).toHaveBeenCalledTimes(1)
+ })
+ it('a 5xx body that mentions "already exists" without a vetted marker is not a name conflict', async () => {
+ // No `httpStatus=` marker crossed the boundary, but the response still
+ // carries its own status line: 5xx is not a collision, so the outcome is
+ // verified instead of retried under a new name.
+ const moveResource = vi.fn(async () => {
+ throw new Error('500 Internal Server Error: a resource with this name already exists')
+ })
+ const outcome = await commitGfsMove(deps({ moveResource }), plan({ allowNumberedRename: true }))
+ expect(outcome.status).toBe('unconfirmed')
+ expect(moveResource).toHaveBeenCalledTimes(1)
+ })
})
describe('commitGfsMove — gesture ownership (rev-2 §4.1)', () => {
diff --git a/desktop-app/ui/src/gfs/moveCommit.ts b/desktop-app/ui/src/gfs/moveCommit.ts
index bb8994d0e..e28e6a4ad 100644
--- a/desktop-app/ui/src/gfs/moveCommit.ts
+++ b/desktop-app/ui/src/gfs/moveCommit.ts
@@ -1,5 +1,6 @@
import {
GFS_MOVE_MAX_NETWORK_ATTEMPTS,
+ gfsHttpStatusOf,
isGfsNameConflict,
nextAvailableGfsResourceName,
} from '@clerum/gfs-interaction-policy'
@@ -85,6 +86,27 @@ function messageOf(error: unknown): string {
return error instanceof Error ? error.message : String(error)
}
+/**
+ * A name conflict is a 409 and nothing else.
+ *
+ * The shared classifier also accepts body PROSE ("already exists"), and a
+ * 5xx body can carry that prose while describing something else entirely
+ * (an upstream conflict, a replayed error, a message about a different
+ * resource). Treating such a response as a collision would skip the outcome
+ * verification and re-PATCH the move under a NEW name — renaming an item the
+ * server never rejected.
+ *
+ * The response's own status decides: the vetted `httpStatus=` marker first,
+ * then the shared status reader for a response that never carried one. Only
+ * when no status can be read at all does the prose classifier apply, because
+ * it is then the only evidence available.
+ */
+function isNameConflictResponse(error: unknown, status: number | null): boolean {
+ const effectiveStatus = status ?? gfsHttpStatusOf(error)
+ if (effectiveStatus !== null) return effectiveStatus === 409
+ return isGfsNameConflict(error)
+}
+
/**
* Shared move dispatch (rev-2 §5): one service called by the Files page,
* the sidebar explorer and the Move-dialog adapters. Every attempt is ONE
@@ -192,7 +214,7 @@ export async function commitGfsMove(
: {}),
}
}
- if (status !== 409 && !isGfsNameConflict(error)) {
+ if (!isNameConflictResponse(error, status)) {
// Transport loss after dispatch: verify the outcome by identity; never
// repeat a possibly committed move.
const verified = await verifyOutcomeByResolve(deps, plan, snapshot)