fix(server): give the retired task workspace conflict a stable code (#23582)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Before a run starts, Paperclip reserves the task's remote workspace.
It refuses a workspace that is archived or whose cleanup failed, with
the message "Workspace ownership changed.".
> - When setup fails, the server sends a run-failure report to Sentry.
Since #23568, the report groups a setup conflict by the stable code in
its details.
> - This conflict has no code. Its reports use the fallback grouping and
share a Sentry group with other uncoded setup conflicts.
> - This pull request gives the conflict the code
`remote_workspace_retired`.
> - The benefit is a separate Sentry group for runs that fail on a
retired task workspace.

## Linked Issues or Issue Description

**What happened**
A task's execution workspace was archived. Automatic recovery then
started new runs for the task. Each run failed setup with "Workspace
ownership changed.". These reports went into a shared Sentry group with
unrelated setup conflicts, because the conflict had no code.

**Expected behavior**
The conflict has a stable code. Its run-failure reports get their own
Sentry group.

**Steps to reproduce**
1. Reserve a remote task workspace, then set its status to `archived` or
`cleanup_failed`.
2. Reserve the workspace again for a new run.
3. The reservation rejects with a 409 conflict that has no
`details.code`.

**Paperclip version or commit**
master at 8379dedd9.

Refs #23568 (reads `details.code` for run-failure grouping).

## What Changed

- `remote-workspaces.ts`: the "Workspace ownership changed." conflict
now has `details.code` `remote_workspace_retired`. The message and the
409 status do not change.
- `remote-workspaces.integration.test.ts`: a new test reserves an
`archived` and a `cleanup_failed` workspace and expects the conflict
with the new code.
- `run-failure-sentry.test.ts`: the example of an uncoded conflict now
uses another conflict that still has no code.

## Verification

- `cd server && npx vitest run
src/services/remote-workspaces.integration.test.ts -t "stable conflict
code"`: 2 of 2 pass. Without the change to `remote-workspaces.ts`, both
fail.
- `npx vitest run src/services/remote-workspaces.integration.test.ts
src/__tests__/run-failure-sentry.test.ts
src/services/__tests__/run-failure-diagnostics.test.ts`: 301 of 302
pass. The one failure, "cleans saved reads with read-only folders", also
fails on unchanged master in my sandbox (file mode 256 instead of 292).
It is not related to this change.

## Risks

- Low risk. The message, the status and the control flow do not change.
Only the conflict details get a code.
- Expected change: after deploy, Sentry reports for this conflict move
to a new group.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), with tool use and code execution
in a sandbox.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [ ] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-12-02 22:13:09 -08:00
1 parent fc09515c7e
commit 917a38efd7
3 files changed
+15 -2

No files matched your search

@@ -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([
@@ -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");
+1 -1
View File
@@ -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,