fix(workspaces): exclude named pipes from workspace snapshots like sockets (#22817)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - A hosted server can move a workspace's files into a portable
snapshot archive, for example when the server moves to volume-free
storage
> - The archive already skips Unix sockets, because a socket is a
runtime IPC endpoint with no file contents, and records the skipped path
> - A named pipe (FIFO) is the same kind of runtime IPC endpoint, but
capture refused the whole workspace with
`remote_workspace_archive_unsupported_entry`
> - One leftover pipe in a workspace therefore blocked a whole server's
move, with no way to settle it
> - This pull request treats a named pipe like a socket: record it as
excluded and keep the files beside it
> - The benefit is that workspaces holding a stray pipe can be saved and
moved, with the skipped path still visible in the archive manifest

## Linked Issues or Issue Description

Follow-up to #19159, which excluded sockets and kept the existing
refusal of named pipes.

**What happened?**
An offline move of a server to volume-free storage rolled back. The
recorded refusal was `remote_workspace_archive_unsupported_entry` on one
workspace. The only entry types that still reach that refusal are named
pipes and device files.

**Expected behavior**
A named pipe has no portable contents, like a socket, so capture should
record it as excluded and save everything else.

**Steps to reproduce**
1. Create a workspace folder with a file and a named pipe (`mkfifo
pipe`).
2. Capture a snapshot archive of it.
3. See capture fail with `remote_workspace_archive_unsupported_entry`.

## What Changed

- `remote-workspace-snapshot-archive.ts`: a named pipe is recorded in
the archive's excluded paths, like a socket, instead of failing the
capture. The same function also builds the serialized remote capture
script, so both paths change together.
- `remote-workspace-readonly-inventory.ts`: the read-only inventory
excludes named pipes the same way, so its fingerprint matches what
capture saves.
- Device entries and unsafe links are still refused.
- The test that asserted pipe refusal now asserts the new behavior: the
pipe stays in place, adjacent work restores, and the archive manifest
lists the pipe as excluded.

## Verification

- Red: with the source change reverted, the new test `records a named
pipe as excluded and preserves the files beside it` fails.
- Green: `npx vitest run
src/services/remote-workspace-snapshot-archive.test.ts
src/services/remote-workspace-readonly-inventory*.test.ts` (in
`server/`): 3 files, 130 tests pass, using a real `mkfifo` pipe.

## Risks

- A pipe is not recreated on restore, exactly as for sockets. Its path
is visible in the existing exclusion manifest. A process that expected
the pipe to exist recreates it as it would after any restart.
- No new archive entry type, dependency, or background work.

## Model Used

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

## 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

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DottaandClaude Opus 5.5 authored and GitHub committed 2026-11-24 19:12:52 -06:00
1 parent f913a4f1b8
commit 535d04edb3
6 files changed
+57 -10

No files matched your search

@@ -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",
@@ -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")
@@ -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;
@@ -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,
@@ -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] },
@@ -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<typeof isCapturePolicyRearmable>[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);
});