diff --git a/server/src/services/remote-workspace-recovery-attachments.test.ts b/server/src/services/remote-workspace-recovery-attachments.test.ts index 6bd276c4fab..358dabf5d6f 100644 --- a/server/src/services/remote-workspace-recovery-attachments.test.ts +++ b/server/src/services/remote-workspace-recovery-attachments.test.ts @@ -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 }; diff --git a/server/src/services/remote-workspace-transport.ts b/server/src/services/remote-workspace-transport.ts index b47b1fd8a9a..bf043ab5bca 100644 --- a/server/src/services/remote-workspace-transport.ts +++ b/server/src/services/remote-workspace-transport.ts @@ -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