Skip to content

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

TypeScript

fix(desktop): r1-m3 preserve trusted move verdicts and reject invalid targets

M14a303560eae
diff --git a/desktop-app/src/gfs/uriHandler.ts b/desktop-app/src/gfs/uriHandler.ts
index 05ae76d21..8cbc86568 100644
--- a/desktop-app/src/gfs/uriHandler.ts
+++ b/desktop-app/src/gfs/uriHandler.ts
@@ -691,7 +691,11 @@ export class GfsClient {
input: GfsMoveInput,
session: string
): Promise<{ resourceId: string; version: number }> {
- return moveGfsResource(this.transport, input, session)
+ try {
+ return await moveGfsResource(this.transport, input, session)
+ } catch (error) {
+ throw surfaceGfsGrantError(error)
+ }
}
async deleteResource(
@@ -803,7 +807,7 @@ function parseGfsGrantErrorFields(bodyText: string): GfsGrantErrorFields {
}
/**
- * Re-throw any GFS failure — grant, share, or read — with the server's
+ * Re-throw a GFS grant, share, read, or move failure with the server's
* structured verdict fields embedded in the message.
*
* The transport (httpClient) throws an `ApiError` that stashes the raw response
@@ -865,7 +869,7 @@ function surfaceGfsGrantError(error: unknown): unknown {
// Every `ApiError` now yields a `httpStatus=` part, so a wrapper is the norm
// rather than the exception it used to be. The transport fields are not
// copied onto it: `cause` keeps the original error object intact, and no
- // main-process caller of these nine methods reads `.status`/`.bodyText` off
+ // main-process caller of these ten methods reads `.status`/`.bodyText` off
// the rejection (the `ApiError` branches in `appService` belong to rpc-proxy
// and stored-session paths; the upload retry path never imports this module).
return new GfsUriError(`${baseMessage}${suffix}`, { cause: error })
diff --git a/desktop-app/ui/src/gfs/__fixtures__/gfsProducerFixtures.ts b/desktop-app/ui/src/gfs/__fixtures__/gfsProducerFixtures.ts
index c8d4fa9d6..6d4b3c35d 100644
--- a/desktop-app/ui/src/gfs/__fixtures__/gfsProducerFixtures.ts
+++ b/desktop-app/ui/src/gfs/__fixtures__/gfsProducerFixtures.ts
@@ -395,10 +395,11 @@ export async function gfsRouteFailureMessage(
body: { code: string; message: string } = {
code: 'forbidden',
message: 'not authorized',
- }
+ },
+ headers: Record<string, string> = {}
): Promise<string> {
const server = createServer((_req, res) => {
- res.writeHead(status, { 'content-type': 'application/json' })
+ res.writeHead(status, { 'content-type': 'application/json', ...headers })
res.end(JSON.stringify({ ok: false, error: body }))
})
await new Promise<void>(resolve => server.listen(0, '127.0.0.1', () => resolve()))
diff --git a/desktop-app/ui/src/gfs/__tests__/moveProducerErrors.test.ts b/desktop-app/ui/src/gfs/__tests__/moveProducerErrors.test.ts
new file mode 100644
index 000000000..a67e74475
--- /dev/null
+++ b/desktop-app/ui/src/gfs/__tests__/moveProducerErrors.test.ts
@@ -0,0 +1,190 @@
+import { describe, expect, it, vi } from 'vitest'
+import { GFS_MOVE_MAX_NETWORK_ATTEMPTS } from '@clerum/gfs-interaction-policy'
+import {
+ isGfsSessionAuthorityFailure,
+ parseHttpStatus,
+ parseRetryAfterSeconds,
+} from '@lib/gfsGrantErrors'
+import { GfsUriError } from '../../../../src/gfs/uriHandler'
+import { ApiError } from '../../../../src/httpClient'
+import {
+ gfsRouteFailureMessage,
+ resolveResource,
+ resolvedFile,
+} from '../__fixtures__/gfsProducerFixtures'
+import { commitGfsMove, toastMoveOutcome } from '../moveCommit'
+import type { MoveCommitPlan } from '../moveCommit'
+
+const sourceId = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+const destinationId = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'
+const oldParentId = 'cccccccc-cccc-cccc-cccc-cccccccccccc'
+const plan: MoveCommitPlan = {
+ source: {
+ resourceId: sourceId,
+ gfsUri: `gfs://main/${sourceId}`,
+ kind: 'file',
+ name: 'report.md',
+ },
+ destination: { resourceId: destinationId, name: 'Dest' },
+ allowNumberedRename: false,
+}
+
+async function wireFailure(
+ status: number,
+ message = 'move rejected',
+ headers: Record<string, string> = {}
+) {
+ let captured: unknown
+ const text = await gfsRouteFailureMessage(
+ async client => {
+ try {
+ return await client.moveResource(
+ { resourceId: sourceId, destinationId, ifMatch: 7 },
+ 'fixture-session-token'
+ )
+ } catch (error) {
+ captured = error
+ throw error
+ }
+ },
+ status,
+ { code: 'move_rejected', message },
+ headers
+ )
+ return { text, error: captured }
+}
+async function run(text: string, approveRename = false, landed = false) {
+ const snapshot = await resolveResource(
+ resolvedFile(sourceId, 'report.md', { parentResourceId: oldParentId, version: 7 })
+ )
+ const confirmed = await resolveResource(
+ resolvedFile(sourceId, 'report.md', { parentResourceId: destinationId, version: 8 })
+ )
+ const resolveSource = vi
+ .fn()
+ .mockResolvedValueOnce(snapshot)
+ .mockResolvedValue(landed ? confirmed : snapshot)
+ const moveResource = vi.fn(
+ async (_id: string, _destination: string, _version: number, _name?: string) => {
+ throw new Error(text)
+ }
+ )
+ const outcome = await commitGfsMove(
+ {
+ resolveSource,
+ moveResource,
+ isSessionAuthorityFailure: error => isGfsSessionAuthorityFailure(String(error), 'operation'),
+ },
+ { ...plan, allowNumberedRename: approveRename }
+ )
+ return { outcome, resolveSource, moveResource }
+}
+
+describe('real move producer verdicts (R1-M3)', () => {
+ it.each([
+ [400, 'destination-rejected'],
+ [401, 'session-lost'],
+ [403, 'unconfirmed'],
+ [404, 'target-unavailable'],
+ [409, 'conflict-stopped'],
+ [412, 'changed'],
+ [429, 'rate-limited'],
+ ] as const)(
+ 'preserves trusted %i metadata and emits %s without outcome verification or automatic retry',
+ async (status, expected) => {
+ const wire = await wireFailure(
+ status,
+ 'move rejected',
+ status === 429 ? { 'retry-after': '7' } : {}
+ )
+ expect(parseHttpStatus(wire.text)).toBe(status)
+ const result = await run(wire.text)
+ expect(result.outcome.status).toBe(expected)
+ expect(result.resolveSource).toHaveBeenCalledTimes(1)
+ expect(result.moveResource).toHaveBeenCalledTimes(1)
+ if (result.outcome.status === 'rate-limited') {
+ expect(result.outcome.retryAfterSeconds).toBe(7)
+ expect(result.outcome.message).toBe('Too many file requests — try again in 7s.')
+ }
+ if (result.outcome.status === 'unconfirmed') {
+ expect(result.outcome.message).toContain('move rejected')
+ expect(result.outcome.message).not.toMatch(/httpStatus=|retryAfterSeconds=/)
+ }
+ if (result.outcome.status === 'destination-rejected') {
+ expect(result.outcome.message).toBe(
+ 'The server rejected this destination. Refresh and choose a different folder.'
+ )
+ const toast = vi.fn()
+ toastMoveOutcome(toast, result.outcome, 'report.md', 'Dest', 'file')
+ expect(toast).toHaveBeenCalledWith(result.outcome.message, 'error')
+ }
+ }
+ )
+
+ it('retains the actual transport error as cause and strips forged status/retry prose', async () => {
+ const wire = await wireFailure(500, 'upstream 429 httpStatus=412 retryAfterSeconds=9')
+ expect(wire.error).toBeInstanceOf(GfsUriError)
+ expect((wire.error as Error).cause).toBeInstanceOf(ApiError)
+ expect(((wire.error as Error).cause as ApiError).status).toBe(500)
+ expect(parseHttpStatus(wire.text)).toBe(500)
+ expect(parseRetryAfterSeconds(wire.text)).toBeNull()
+ expect(wire.text).not.toContain('httpStatus=412')
+ const result = await run(wire.text)
+ expect(result.outcome.status).toBe('unconfirmed')
+ expect(result.resolveSource).toHaveBeenCalledTimes(2)
+ expect(result.moveResource).toHaveBeenCalledTimes(1)
+ })
+
+ it('keeps the approved 409 numbered-name attempts bounded', async () => {
+ const { text } = await wireFailure(409)
+ const result = await run(text, true)
+ expect(result.outcome.status).toBe('conflict-stopped')
+ expect(result.moveResource).toHaveBeenCalledTimes(GFS_MOVE_MAX_NETWORK_ATTEMPTS)
+ expect(result.resolveSource).toHaveBeenCalledTimes(1)
+ expect(result.moveResource.mock.calls.map(call => call[3])).toEqual([
+ undefined,
+ 'report (1).md',
+ 'report (2).md',
+ ])
+ })
+
+ it.each([false, true])(
+ 'verifies a real status-free transport failure once (landed=%s), with no re-PATCH',
+ async landed => {
+ // A loopback HTTP fixture closes the response socket before any status.
+ // The client surfaces its real transport exception, never an invented marker.
+ const { createServer } = await import('node:http')
+ const { GfsClient } = await import('../../../../src/gfs/uriHandler')
+ const { requestJson } = await import('../../../../src/httpClient')
+ const server = createServer((request, _response) => {
+ request.socket.destroy()
+ })
+ await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve))
+ try {
+ const address = server.address() as import('node:net').AddressInfo
+ const client = new GfsClient({
+ baseUrl: `http://127.0.0.1:${address.port}`,
+ requestJson,
+ fetchBytes: async () => new ArrayBuffer(0),
+ })
+ let failure = ''
+ try {
+ await client.moveResource(
+ { resourceId: sourceId, destinationId, ifMatch: 7 },
+ 'fixture-session-token'
+ )
+ } catch (error) {
+ failure = (error as Error).message
+ }
+ expect(failure).not.toBe('')
+ expect(parseHttpStatus(failure)).toBeNull()
+ const result = await run(failure, false, landed)
+ expect(result.outcome.status).toBe(landed ? 'committed' : 'unconfirmed')
+ expect(result.resolveSource).toHaveBeenCalledTimes(2)
+ expect(result.moveResource).toHaveBeenCalledTimes(1)
+ } finally {
+ await new Promise<void>(resolve => server.close(() => resolve()))
+ }
+ }
+ )
+})
diff --git a/desktop-app/ui/src/gfs/moveCommit.ts b/desktop-app/ui/src/gfs/moveCommit.ts
index c77ca3633..70c5f7c31 100644
--- a/desktop-app/ui/src/gfs/moveCommit.ts
+++ b/desktop-app/ui/src/gfs/moveCommit.ts
@@ -3,7 +3,7 @@ import {
isGfsNameConflict,
nextAvailableGfsResourceName,
} from '@clerum/gfs-interaction-policy'
-import { parseHttpStatus, parseRetryAfterSeconds } from '@lib/gfsGrantErrors'
+import { describeGfsReadError, parseHttpStatus, parseRetryAfterSeconds } from '@lib/gfsGrantErrors'
import type { GfsDropRejection } from './dragSession.types'
/** Server truth from a commit-time resolve of the source. */
@@ -31,6 +31,7 @@ export type MoveCommitOutcome =
| { status: 'no-op'; message: string }
| { status: 'conflict-stopped'; message: string }
| { status: 'changed'; message: string }
+ | { status: 'destination-rejected'; message: string }
| { status: 'source-unavailable'; message: string }
| { status: 'target-unavailable'; message: string }
| { status: 'rate-limited'; message: string; retryAfterSeconds?: number }
@@ -87,7 +88,7 @@ export async function commitGfsMove(
message: 'EvenDrive cannot verify this item’s current location. Refresh and try again.',
}
}
- return { status: 'unconfirmed', message: messageOf(error) }
+ return { status: 'unconfirmed', message: describeGfsReadError(error).message }
}
// Fresh-parent no-op guard before any request (a concurrent move may have
@@ -120,11 +121,18 @@ export async function commitGfsMove(
const message = messageOf(error)
const status = parseHttpStatus(message)
+ if (status === 400) {
+ return {
+ status: 'destination-rejected',
+ message: 'The server rejected this destination. Refresh and choose a different folder.',
+ }
+ }
if (status === 412) {
// No automatic re-PATCH: the item changed; require a new gesture.
return {
status: 'changed',
- message: 'This item changed while you were moving it. Review its current location and try again.',
+ message:
+ 'This item changed while you were moving it. Review its current location and try again.',
}
}
if (status === 404) {
@@ -133,12 +141,12 @@ export async function commitGfsMove(
if (status === 403) {
// Generic unless a successful permission recheck proves the missing bit;
// the pre-commit probes own the exact-reason copy.
- return { status: 'unconfirmed', message }
+ return { status: 'unconfirmed', message: describeGfsReadError(error).message }
}
if (status === 429 || (!status && /too many/i.test(message))) {
return {
status: 'rate-limited',
- message: 'Too many file requests — try again shortly.',
+ message: describeGfsReadError(error).message,
...(parseRetryAfterSeconds(message) !== null
? { retryAfterSeconds: parseRetryAfterSeconds(message) ?? undefined }
: {}),
@@ -209,7 +217,6 @@ export function suggestNumberedMoveName(
return nextAvailableGfsResourceName(sourceName, occupiedDestinationNames)
}
-
export type MoveToast = (message: string, tone: 'success' | 'error' | 'info') => void
/** Presented outcome toasts (rev-2 §8 UX matrix) shared by every surface. */