diff --git a/server/src/__tests__/run-failure-sentry.test.ts b/server/src/__tests__/run-failure-sentry.test.ts index 61ff2314e60..aaf853b5a41 100644 --- a/server/src/__tests__/run-failure-sentry.test.ts +++ b/server/src/__tests__/run-failure-sentry.test.ts @@ -247,7 +247,7 @@ describe("captureRunFailure", () => { { code: "remote_workspace_writer_pending" }))); sentryModule.captureRunFailure(setupFailure(conflict("This workspace requires a supported remote execution environment.", { code: "remote_workspace_execution_required" }))); - sentryModule.captureRunFailure(setupFailure(conflict("Workspace ownership changed."))); + sentryModule.captureRunFailure(setupFailure(conflict("The task workspace selection changed."))); const prefix = ["setup_failed", "paperclip_runner", "setup"]; expect(captureException.mock.calls.map(([, context]) => context?.fingerprint)).toEqual([ diff --git a/server/src/services/remote-workspaces.integration.test.ts b/server/src/services/remote-workspaces.integration.test.ts index c3040a41830..cdda1b06bdc 100644 --- a/server/src/services/remote-workspaces.integration.test.ts +++ b/server/src/services/remote-workspaces.integration.test.ts @@ -300,6 +300,19 @@ suite("remote workspace lifecycle with real Postgres and independent filesystem if (remoteRoot) expect(await fs.readFile(path.join(remoteRoot, "saved.txt"), "utf8")).toBe("keep prior files\n"); }); + it.each(["archived", "cleanup_failed"] as const)("refuses a task workspace in %s status with a stable conflict code", async status => { + const reserved = await reserve({ kind: "empty" }); + await db.update(heartbeatRuns).set({ status: "succeeded", finishedAt: new Date() }).where(eq(heartbeatRuns.id, ids.run)); + await db.update(executionWorkspaces).set({ status }).where(eq(executionWorkspaces.id, reserved.id)); + const nextRun = randomUUID(); + await db.insert(heartbeatRuns).values({ id: nextRun, companyId: ids.company, agentId: ids.agent, + nativeIssueId: ids.issue, runtimeMode: "native", status: "running" }); + await expect(reserveRemoteWorkspace({ db, storage, companyId: ids.company, issueId: ids.issue, + runId: nextRun, agentId: ids.agent, environmentId: ids.environment, projectId: null, projectWorkspaceId: null, + existingWorkspaceId: reserved.id, source: { kind: "empty" } })).rejects.toMatchObject({ + status: 409, message: "Workspace ownership changed.", details: { code: "remote_workspace_retired" } }); + }); + it.each(["initial", "follow-up"] as const)("edits and cold-restores both an anchor and a referenced project's task copy (%s attachment)", async attachment => { vi.stubEnv("PAPERCLIP_MULTI_PROJECT_WORKSPACE_SYNC", "true"); vi.stubEnv("PAPERCLIP_MULTI_PROJECT_WORKSPACE_SYNC_REMOTE", "true"); diff --git a/server/src/services/remote-workspaces.ts b/server/src/services/remote-workspaces.ts index 17a1b411cab..8c1f286adf0 100644 --- a/server/src/services/remote-workspaces.ts +++ b/server/src/services/remote-workspaces.ts @@ -243,7 +243,7 @@ export async function reserveRemoteWorkspace(input: { let authority = readRemoteWorkspaceAuthority(existing?.metadata); if (existing && !authority) throw conflict("Import this existing workspace before enabling remote storage.", { code: "remote_workspace_migration_required" }); if (existing && authority) { - if (["archived", "cleanup_failed"].includes(existing.status)) throw conflict("Workspace ownership changed."); + if (["archived", "cleanup_failed"].includes(existing.status)) throw conflict("Workspace ownership changed.", { code: "remote_workspace_retired" }); if (existing.sourceIssueId !== input.issueId) { const actor = { type: "agent", source: "agent_jwt", companyId: input.companyId, agentId: input.agentId, runId: input.runId,