Skip to content

The agent that grows with you

fix(desktop): share the missing-snapshot fallback verdict

David Dudok de Wit8fbd2d917641
diff --git a/apps/desktop/src/api/sessions-mutations.test.ts b/apps/desktop/src/api/sessions-mutations.test.ts
index be6afbaa2ac..f70f162823f 100644
--- a/apps/desktop/src/api/sessions-mutations.test.ts
+++ b/apps/desktop/src/api/sessions-mutations.test.ts
@@ -12,6 +12,41 @@ import { deleteSession, renameSession, setSessionArchived, setSessionPinnedRemot
beforeEach(() => { vi.mocked(hermesApi).mockReset(); setApiRequestConnection('owner'); setApiRequestProfile('work') })
+it('concurrent equal sidebar edits share the missing-snapshot verdict on older standalone servers', async () => {
+ vi.mocked(hermesApi).mockImplementation(async request => {
+ if (!request.method || request.method === 'GET') {
+ throw new Error('404: {"detail":"No such API endpoint: /api/sessions/shared-old/mutation-snapshot"}')
+ }
+
+ return { ok: true } as never
+ })
+
+ const results = await Promise.allSettled([
+ renameSession('shared-old', 'same name', 'work'),
+ renameSession('shared-old', 'same name', 'work')
+ ])
+
+ expect(results.map(result => result.status)).toEqual(['fulfilled', 'fulfilled'])
+ expect(vi.mocked(hermesApi).mock.calls.filter(([request]) => !request.method || request.method === 'GET')).toHaveLength(1)
+})
+
+it('a missing-route response from a write never selects an unfenced retry', async () => {
+ const missing = new Error('404: {"detail":"No such API endpoint: /api/sessions/write-only"}')
+ const writes: unknown[] = []
+ vi.mocked(hermesApi).mockImplementation(async request => {
+ if (!request.method || request.method === 'GET') {
+ return { exists: true, runtime_revision: 2, runtime_generation: 1 } as never
+ }
+
+ writes.push(request.body)
+ throw missing
+ })
+
+ await expect(renameSession('write-only', 'same name', 'work')).rejects.toBe(missing)
+ expect(writes).toHaveLength(1)
+ expect(writes[0]).toMatchObject({ request_id: expect.any(String), expected_revision: 2 })
+})
+
it('uses owner snapshots and preserves the exact delete identity after a lost reply', async () => {
let lost = true
const writes: unknown[] = []
diff --git a/apps/desktop/src/api/sessions.ts b/apps/desktop/src/api/sessions.ts
index a9a6c409eeb..cfd28017d80 100644
--- a/apps/desktop/src/api/sessions.ts
+++ b/apps/desktop/src/api/sessions.ts
@@ -374,6 +374,8 @@ export async function listSidebarSessions(req: SidebarSessionsRequest): Promise<
const runSessionMutation = createSessionMutationClient()
+class MissingMutationSnapshotRoute extends Error {}
+
/** Run one fenced session edit. The fencing protocol is a backend capability: an older
* standalone runtime has no snapshot route and keeps its base write. Only that route-level
* verdict on the read, before any write was attempted, selects it; a session/profile 404,
@@ -381,13 +383,13 @@ const runSessionMutation = createSessionMutationClient()
* identity. */
export function mutateSessionFenced<T>(key: string, read: () => Promise<SessionMutationSnapshot>,
send: (identity: Partial<SessionMutationIdentity>) => Promise<T>): Promise<T> {
- let unfenced = false
-
return runSessionMutation(key, () => read().catch(error => {
- unfenced = isUnroutedRestPath(error)
+ // The prepared read is shared by equal concurrent edits; its verdict must
+ // travel with that rejection, rather than one caller's local closure.
+ if (isUnroutedRestPath(error)) { throw new MissingMutationSnapshotRoute(String(error), { cause: error }) }
throw error
}), send).catch(error => {
- if (!unfenced) { throw error }
+ if (!(error instanceof MissingMutationSnapshotRoute)) { throw error }
return send({})
})