fix(workspaces): keep only the script's closed refusal non-fatal for retired copies

isRemoteRecoveryAttachmentRefusal() accepted any recovery_attachment exit,
so an SSH connection failure (exit 255, no reason) was logged and preparation
continued. Require exit=1 with the script's closed reason; transport failures
and unexplained exits still stop preparation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
paperclipbugbotandClaude Opus 5.5 committed 2026-12-01 23:07:28 +00:00
1 parent ac26f81a28
commit c62fcb52eb
2 files changed
+26 -4

No files matched your search

@@ -80,6 +80,22 @@ describe("retired recovered copies with real sandbox commands", () => {
else expect(await fs.readFile(path.join(outside || directory, "files", "kept.txt"), "utf8")).toBe("kept\n");
});
it.each([
["an SSH connection failure", 255, "ssh: connect to host sandbox port 22: Connection refused"],
["an unexplained exit", 1, "node: command not found"],
] as const)("does not hide %s while removing a retired recovered copy", async (_name, exitCode, stderr) => {
const operationId = randomUUID(), sourceRunId = randomUUID();
const item = { operationId, sourceRunId, path: `.paperclip-recovered/${operationId}`, provenance: "{}", retired: true };
const { remote, execute } = target();
execute.mockResolvedValueOnce({ exitCode, stdout: "", stderr, timedOut: false, signal: null,
pid: process.pid, startedAt: new Date().toISOString() });
await expect(retainRemoteRecoveryAttachments({ db: {} as never, runId: randomUUID(), remoteRoot: workspace,
target: remote, recoveredFiles: [], retiredOperationIds: new Set([operationId]),
workspace: { id: randomUUID(), companyId: randomUUID(), sourceIssueId: null,
metadata: { remoteWorkspaceRecoveredFiles: [item] } } }))
.rejects.toThrow(new RegExp(`^remote_workspace_operation_failed: operation=recovery_attachment exit=${exitCode}$`));
});
it("does not hide a provider failure while removing a retired recovered copy", async () => {
const operationId = randomUUID(), sourceRunId = randomUUID();
const item = { operationId, sourceRunId, path: `.paperclip-recovered/${operationId}`, provenance: "{}", retired: true };
@@ -363,11 +363,17 @@ export async function removeRemoteRecoveryAttachment(input: {
return output === "removed";
}
/** The sandbox ran the recovered-copy check and refused it with an exit status.
* Timeouts and provider transport failures are not refusals. */
// The recovered-copy script exits 1 after writing one closed reason. Any other
// failure, such as an SSH connection error (exit 255) with no reason, is not a
// refusal by the script.
const RECOVERY_ATTACHMENT_REFUSAL = new RegExp(
`^remote_workspace_operation_failed: operation=recovery_attachment exit=1; ${SANDBOX_RECOVERY_ATTACHMENT_CAUSE.source.slice(1)}`);
/** The sandbox ran the recovered-copy check and refused it with its closed
* reason. Timeouts, provider transport failures and unexplained exits are not
* refusals. */
export function isRemoteRecoveryAttachmentRefusal(error: unknown): error is RemoteWorkspaceOperationError {
return error instanceof RemoteWorkspaceOperationError
&& error.message.startsWith("remote_workspace_operation_failed: operation=recovery_attachment exit=");
return error instanceof RemoteWorkspaceOperationError && RECOVERY_ATTACHMENT_REFUSAL.test(error.message);
}
// A fresh clone from a network remote is blobless (--filter=blob:none): it gets