diff --git a/server/src/__tests__/interrupted-preparation-hold-settle.test.ts b/server/src/__tests__/interrupted-preparation-hold-settle.test.ts index 6e5f2bb76bc..040a68e1f7f 100644 --- a/server/src/__tests__/interrupted-preparation-hold-settle.test.ts +++ b/server/src/__tests__/interrupted-preparation-hold-settle.test.ts @@ -21,6 +21,7 @@ import { import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js"; import { currentProcessSpaceHash } from "../services/controller-process-identity.js"; import { heartbeatService } from "../services/heartbeat.js"; +import { REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION } from "../services/remote-workspace-snapshot-archive.js"; import { settleHeldInterruptedPreparation } from "../services/interrupted-preparation-hold-settlement.js"; import { isAbandonedPreparedRemoteWorkspace } from "../services/remote-workspace-abandoned-preparation.js"; import { inspectWorkspaceRecoverySource } from "../services/workspace-recovery-source.js"; @@ -331,7 +332,7 @@ suite("held interrupted preparations on the shared ownership path", () => { workspaceRecovery: { schema: "paperclip.workspace-recovery.v1", runId: f.runId, status: "blocked", stage: "verifying_stop", attempt: 1, attemptLimit: 6, retryable: true, requestIds: [], message: "Automatic recovery of saved work failed (last failure: source_unavailable). Retry to try again; the agent will not repeat its work." }, - systemRecovery: { schema: "paperclip.system-recovery.v1", policyVersion: 1, capturePolicyVersion: 2, state: "exhausted", + systemRecovery: { schema: "paperclip.system-recovery.v1", policyVersion: 1, capturePolicyVersion: REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION, state: "exhausted", phase: "verify_execution", sourceRunId: f.runId, generationId: randomUUID(), attemptId: randomUUID(), intentId: null, attempts: 1, retriesUsed: 0, revision: 2, nextAttemptAt: null, providerCooldownAt: null, freshAttemptRunId: null, preservationOperationIds: [], failure: { code: "source_unavailable", retryClass: "use_alternative_strategy", diff --git a/server/src/services/remote-workspace-readonly-inventory.ts b/server/src/services/remote-workspace-readonly-inventory.ts index a304f2a0b9f..80e034117bc 100644 --- a/server/src/services/remote-workspace-readonly-inventory.ts +++ b/server/src/services/remote-workspace-readonly-inventory.ts @@ -57,7 +57,7 @@ export async function readWorkspaceInventory(root: string, controllerCopy = fals if (git >= 0 && ((foldedAdministrationPath === "config" && administrationPath !== "config") || ["commondir", "config.worktree", "objects/info/alternates", "objects/info/http-alternates"] .includes(foldedAdministrationPath))) fail(); - if (stat.isSocket()) { exclude.push(next); continue; } + if (stat.isSocket() || stat.isFIFO()) { exclude.push(next); continue; } if (stat.isDirectory()) { if (!controllerCopy && !inGit && name !== ".git") { const marker = await fs.lstat(name === "node_modules" ? path.join(directory, "package.json") diff --git a/server/src/services/remote-workspace-snapshot-archive.ts b/server/src/services/remote-workspace-snapshot-archive.ts index 011a6cfdd52..4649fd74c1e 100644 --- a/server/src/services/remote-workspace-snapshot-archive.ts +++ b/server/src/services/remote-workspace-snapshot-archive.ts @@ -5,8 +5,9 @@ import { Worker } from "node:worker_threads"; * release refused. Saves that recovery exhausted under an older version are * retried once under the new one (workspace-recovery-capture-policy). * 2: absolute or escaping symlinks are dropped and recorded instead of refusing the save. + * 3: named pipes are excluded and recorded like sockets. */ -export const REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION = 2; +export const REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION = 3; /** * A portable, streaming workspace archive. This function is intentionally @@ -468,7 +469,7 @@ export async function workspaceArchive(input: { if (!tracked) { excludedPaths.add(next); continue; } } } - if (stat.isSocket()) { + if (stat.isSocket() || stat.isFIFO()) { // Runtime IPC endpoints have no portable file contents. Record the // exclusion without removing the endpoint or dropping adjacent work. excludedPaths.add(next); continue; diff --git a/server/src/services/remote-workspace-transport.test.ts b/server/src/services/remote-workspace-transport.test.ts index f49487d126e..c447c04fb05 100644 --- a/server/src/services/remote-workspace-transport.test.ts +++ b/server/src/services/remote-workspace-transport.test.ts @@ -1180,19 +1180,43 @@ return result};`); }); it.skipIf(process.platform === "win32").each(["split", "one-shot"] as const)("retains a closed capture validation failure with %s output", async outputMode => { - const privateName = "SYNTHETIC_PRIVATE_FILENAME"; + const privateName = "SYNTHETIC\\PRIVATE_FILENAME"; await fs.writeFile(path.join(workspace, "saved.txt"), "retained source bytes\n"); - await exec("mkfifo", [path.join(workspace, privateName)]); + await fs.writeFile(path.join(workspace, privateName), "private bytes\n"); const { remote, execute } = target({}, outputMode), operationId = randomUUID(); await expect(captureRemoteWorkspaceArchive({ target: remote, remoteCwd: workspace, operationId })) - .rejects.toThrow(/^remote_workspace_archive_unsupported_entry$/); + .rejects.toThrow(/^remote_workspace_archive_unsupported_filename$/); expect(execute).toHaveBeenCalledTimes(2); expect(await fs.readFile(path.join(workspace, "saved.txt"), "utf8")).toBe("retained source bytes\n"); - expect((await fs.lstat(path.join(workspace, privateName))).isFIFO()).toBe(true); + expect(await fs.readFile(path.join(workspace, privateName), "utf8")).toBe("private bytes\n"); const directory = path.join(workspace, ".paperclip-runtime", "workspace-snapshots", operationId); expect(await fs.readdir(directory)).toEqual(["archive.cjs"]); }); + it.skipIf(process.platform === "win32").each(["split", "one-shot"] as const)("captures beside a named pipe through the remote helper with %s output", async outputMode => { + await fs.writeFile(path.join(workspace, "saved.txt"), "retained source bytes\n"); + await exec("mkfifo", [path.join(workspace, "pipe")]); + const { remote } = target({}, outputMode), operationId = randomUUID(); + const captured = await captureRemoteWorkspaceArchive({ target: remote, remoteCwd: workspace, operationId }); + expect((await fs.lstat(path.join(workspace, "pipe"))).isFIFO()).toBe(true); + expect(await fs.readFile(path.join(workspace, "saved.txt"), "utf8")).toBe("retained source bytes\n"); + const archive = await fs.readFile(captured.archivePath), start = Buffer.from("PCWS1\n").length; + const manifest = JSON.parse(archive.subarray(start + 4, start + 4 + archive.readUInt32BE(start)).toString()); + expect(manifest.excluded).toContain("pipe"); + const restored = path.join(scratch, `restored-${outputMode}`); + await restoreRemoteWorkspaceArchive({ archivePath: captured.archivePath, targetDir: restored, expectedManifestDigest: captured.manifestDigest }); + expect(await fs.readdir(restored)).toEqual(["saved.txt"]); + expect(await fs.readFile(path.join(restored, "saved.txt"), "utf8")).toBe("retained source bytes\n"); + }); + + it.skipIf(process.platform === "win32")("inventories beside a named pipe, excluding the pipe in both inventory modes", async () => { + await fs.writeFile(path.join(workspace, "saved.txt"), "retained source bytes\n"); + await exec("mkfifo", [path.join(workspace, "pipe")]); + const inventory = await readWorkspaceInventory(workspace); + expect(inventory.exclude).toContain("pipe"); + expect(await readWorkspaceInventory(workspace, true)).toEqual(inventory); + }); + /** * The staging shape through the sandbox command path: a `node_modules/.bin` link * inside the workspace, a Chromium profile link by absolute path into /tmp, diff --git a/server/src/services/saved-work-retry-eligibility.test.ts b/server/src/services/saved-work-retry-eligibility.test.ts index 856d6711f78..cc68c2fb23c 100644 --- a/server/src/services/saved-work-retry-eligibility.test.ts +++ b/server/src/services/saved-work-retry-eligibility.test.ts @@ -7,6 +7,7 @@ import { agents, agentWakeupRequests, companies, createDb, environmentLeases, ex import { startEmbeddedPostgresTestDatabase } from "../__tests__/helpers/embedded-postgres.js"; import { requestTaskRetry } from "./task-retry.js"; import { heartbeatService } from "./heartbeat.js"; +import { REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION } from "./remote-workspace-snapshot-archive.js"; import { getExecutionBlocker } from "./execution-blocker.js"; import { taskInterruptionPresentation } from "./task-interruption-presentation.js"; import { REMOTE_WORKSPACE_ABANDONED_EPOCH_SCHEMA } from "./remote-workspace-epoch-abandonment.js"; @@ -111,7 +112,7 @@ describe("Retry of a task whose saved work recovery settled", () => { status: "resolved", outcome: "blocked", nextAction: "Automatic recovery of saved work failed (last failure: source_unavailable). Retry to try again; the agent will not repeat its work.", evidence: { runId: preparedId, - systemRecovery: { schema: "paperclip.system-recovery.v1", policyVersion: 1, capturePolicyVersion: 2, phase: "verify_execution", + systemRecovery: { schema: "paperclip.system-recovery.v1", policyVersion: 1, capturePolicyVersion: REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION, phase: "verify_execution", state: "exhausted", failure: { code: "source_unavailable", retryClass: "use_alternative_strategy", evidenceFingerprint: "a".repeat(64) }, attempts: 1, intentId: null, revision: 1, attemptId: randomUUID(), deadlineAt: now + 600_000, retriesUsed: 0, sourceRunId: preparedId, generationId: randomUUID(), nextAttemptAt: null, firstFailureAt: now - 600_000, @@ -197,7 +198,7 @@ describe("Retry of a task whose saved work recovery settled", () => { kind: "active_run_watchdog", cause: "legacy_execution_requires_reconciliation", fingerprint: sourceId, status: "resolved", outcome: "blocked", nextAction: "Saved work recovered.", evidence: { runId: sourceId, - systemRecovery: { schema: "paperclip.system-recovery.v1", policyVersion: 1, capturePolicyVersion: 2, phase: "reconcile_effects", + systemRecovery: { schema: "paperclip.system-recovery.v1", policyVersion: 1, capturePolicyVersion: REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION, phase: "reconcile_effects", state: "complete", failure: null, attempts: 1, intentId: null, revision: 3, attemptId: randomUUID(), deadlineAt: null, retriesUsed: 0, sourceRunId: sourceId, generationId: randomUUID(), nextAttemptAt: null, firstFailureAt: null, freshAttemptRunId: null, providerCooldownAt: null, preservationOperationIds: [recovered.id] }, diff --git a/server/src/services/system-recovery-capture-policy-rearm.test.ts b/server/src/services/system-recovery-capture-policy-rearm.test.ts new file mode 100644 index 00000000000..85f323b6755 --- /dev/null +++ b/server/src/services/system-recovery-capture-policy-rearm.test.ts @@ -0,0 +1,20 @@ +import { expect, it } from "vitest"; +import { REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION } from "./remote-workspace-snapshot-archive.js"; +import { isCapturePolicyRearmable } from "./system-recovery-state.js"; + +const exhaustedSave = (capturePolicyVersion: number | undefined) => ({ + state: "exhausted" as const, phase: "preserve_files" as const, capturePolicyVersion, + failure: { code: "export_interrupted", retryClass: "retry_transient", evidenceFingerprint: "9".repeat(64) }, +}) as Parameters[0]; + +it("names pipes in capture policy 3", () => { + expect(REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION).toBeGreaterThanOrEqual(3); +}); + +it("re-arms a save exhausted under policy 2, which refused named pipes", () => { + expect(isCapturePolicyRearmable(exhaustedSave(2))).toBe(true); +}); + +it("does not re-arm a save already exhausted under the current policy", () => { + expect(isCapturePolicyRearmable(exhaustedSave(REMOTE_WORKSPACE_CAPTURE_POLICY_VERSION))).toBe(false); +});