Keep SSH workspace paths off the controller filesystem

Claude CLI and shared ACP startup still treated an in-place SSH task
path as a local directory. A remote home path could fail before launch
when the controller could not create that path.

Skip local workspace materialization for these runs. Keep ACP project
settings on the SSH computer and start its local relay from the existing
controller state directory. Preserve copied and local workspace behavior.

Extend the existing account and lifecycle tables with an inaccessible
remote path and a real local relay spawn check. All 323 focused adapter
checks and 4 real SSH integration checks pass. Adapter-utils and Claude
adapter typechecks pass. Broad CI remains required by pnpm verify.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Devin FoleyandPaperclip committed 2026-11-17 13:33:57 -08:00
1 parent b56f240f45
commit b287462dbb
5 files changed
+52 -21

No files matched your search

+4
View File
@@ -71,6 +71,10 @@ also supports this directory. ACP requires its server command, such as
`claude-agent-acp`, on the SSH login PATH. Selecting SSH does not change the
agent's engine or permission settings.
An in-place SSH workspace exists on the SSH computer. Neither engine creates
that workspace path on the controller. ACP keeps its local relay and state files
in the controller's state directory and leaves remote project settings in place.
The SSH account supplies the installed harness; the agent's Paperclip AI account
supplies authentication unless the remote authentication option is enabled.
Host authentication remains supported by the CLI engine.
@@ -4559,9 +4559,12 @@ describe("ACPX engine remote managed-home seam (PR 2: per-adapter home seed)", (
return { root, stateDir, localCwd, remoteCwd, executionTarget };
}
it.each(["turn", "bridge"].flatMap(failure => [false, true].map(inPlace => ({ failure, inPlace }))))(
"stages the configured SSH account and restores credentials after $failure failure (inPlace=$inPlace)", async ({ failure, inPlace }) => {
const { root, stateDir, localCwd, remoteCwd } = await setupRemoteSandbox();
it.each(["custom", "claude"].flatMap(agent => ["turn", "bridge"].flatMap(failure => [false, true].map(inPlace => ({ agent, failure, inPlace })))))(
"stages the configured SSH account and restores credentials after $failure failure (agent=$agent, inPlace=$inPlace)", async ({ agent, failure, inPlace }) => {
const { root, stateDir, localCwd, remoteCwd: copyRemoteCwd } = await setupRemoteSandbox();
const remoteMount = path.join(root, "remote-filesystem");
await fs.writeFile(remoteMount, "This path is not a directory on the controller.");
const remoteCwd = inPlace ? path.join(remoteMount, "workspace") : copyRemoteCwd;
const homes = await Promise.all(["first", "second", "third"].map(async name => {
const home = path.join(root, `selected-account-${name}`);
await fs.mkdir(path.join(home, "provider"), { recursive: true });
@@ -4591,7 +4594,7 @@ describe("ACPX engine remote managed-home seam (PR 2: per-adapter home seed)", (
vi.mocked(startAdapterExecutionTargetPaperclipBridge).mockResolvedValue({ env: { PAPERCLIP_API_URL: "http://127.0.0.1:3210", PAPERCLIP_API_KEY: "bridge-fixture" }, stop: stopControl });
vi.mocked(startAdapterExecutionTargetProcessSessionBridge).mockResolvedValue({ agentCommand: "/fixture/agent-proxy.cjs", stop: stopProcess });
try {
const configForTurn = (turn: number) => ({ agent: "custom", agentCommand: "fixture-acp-client", stateDir, cwd: localCwd,
const configForTurn = (turn: number) => ({ agent, agentCommand: "fixture-acp-client", stateDir, cwd: inPlace ? remoteCwd : localCwd,
managedAiConnection: { identity: `credential-revision-${turn}`, sessionIdentity: "selected-agent-account" },
env: { CODEX_HOME: path.join(homes[turn]!, "provider"), HOME: homes[turn]!, XDG_CONFIG_HOME: path.join(homes[turn]!, "config"),
XDG_DATA_HOME: path.join(homes[turn]!, "data"), OPENAI_API_KEY: `fixture-token-${turn}`, USER_OPTION: "kept" }, mode: "persistent" });
@@ -4604,6 +4607,14 @@ describe("ACPX engine remote managed-home seam (PR 2: per-adapter home seed)", (
expect(seam.mock.calls[0]![0].executionTarget).toMatchObject({ kind: "remote", transport: "ssh" });
if (inPlace) {
expect(result.sessionInputs[0]?.cwd).toBe(remoteCwd);
const hostSpawnCwd = result.runtimeOptions[0]!.spawnCwd as string;
expect(hostSpawnCwd).not.toBe(remoteCwd);
const hostProcess = await runChildProcess("ssh-acp-host-cwd", process.execPath, ["-e", "process.stdout.write(process.cwd())"], {
cwd: hostSpawnCwd, env: {}, timeoutSec: 10, graceSec: 1, onLog: async () => {},
});
expect(hostProcess.exitCode).toBe(0);
expect(hostProcess.stdout).toBe(await fs.realpath(hostSpawnCwd));
await expect(fs.readFile(remoteMount, "utf8")).resolves.toBe("This path is not a directory on the controller.");
expect(vi.mocked(prepareAdapterExecutionTargetRuntime).mock.calls[0]![0]).toMatchObject({
syncWorkspace: false, workspaceRemoteDir: remoteCwd, privateRuntime: true, retainRuntime: true,
});
@@ -1970,6 +1970,8 @@ async function buildRuntime(input: {
executionTarget: input.ctx.executionTarget,
legacyRemoteExecution: input.ctx.executionTransport?.remoteExecution,
});
const sshWorkspaceInPlace = executionTarget?.kind === "remote" &&
executionTarget.transport === "ssh" && executionTarget.workspaceRealization?.mode === "in_place";
const remoteExecutionIdentity = adapterExecutionTargetSessionIdentity(executionTarget);
const effectiveExecutionCwd =
remoteExecutionIdentity && typeof remoteExecutionIdentity.remoteCwd === "string"
@@ -1998,8 +2000,9 @@ async function buildRuntime(input: {
});
// Step 1 — workspace.resolve: the workspace resolution/fallback chain closes
// here on the awaited directory materialization.
await measureStartupStep(input.ctx, nowMs, "workspace.resolve", () =>
ensureAbsoluteDirectory(cwd, { createIfMissing: true }),
await measureStartupStep(input.ctx, nowMs, "workspace.resolve", async () => {
if (!sshWorkspaceInPlace) await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
},
stepMetrics,
);
@@ -2035,6 +2038,7 @@ async function buildRuntime(input: {
const timeoutSec = timeoutResolution.timeoutSec;
const stateDir = path.resolve(asString(config.stateDir, "") || defaultStateDir(agent.companyId, agent.id));
await fs.mkdir(stateDir, { recursive: true });
const hostSpawnCwd = sshWorkspaceInPlace ? stateDir : cwd;
const envConfig = parseObject(config.env);
const env: Record<string, string> = { ...buildPaperclipEnv(agent, input.ctx.agentIdentity), PAPERCLIP_RUN_ID: runId };
@@ -2174,7 +2178,7 @@ async function buildRuntime(input: {
skillsIdentity = preparedSkills.identity;
skillCommandNotes.push(...preparedSkills.commandNotes);
claudeSkillsBundleDir = preparedSkills.bundleDir;
paperclipClaudeSettings = await writePaperclipClaudeSettings({
paperclipClaudeSettings = sshWorkspaceInPlace ? null : await writePaperclipClaudeSettings({
cwd,
stateDir,
// A run's writable AGENT_HOME moves, but the existing permission root
@@ -2184,7 +2188,7 @@ async function buildRuntime(input: {
agentHome: asString(workspaceContext.agentHomeForPermissions, agentHome),
companyId: agent.companyId,
});
skillCommandNotes.push(
if (paperclipClaudeSettings) skillCommandNotes.push(
`Wrote Paperclip-managed Claude settings to ${paperclipClaudeSettings.filePath} (defaultMode=${paperclipClaudeSettings.defaultMode}${
paperclipClaudeSettings.overrodeDontAsk ? "; overrode user dontAsk" : ""
}, +${paperclipClaudeSettings.additionalDirectories.length} read root(s), +${paperclipClaudeSettings.allow.length} allow rule(s)).`,
@@ -2433,7 +2437,7 @@ async function buildRuntime(input: {
now: nowMs,
idleMs: input.stagedIdleMs,
sessionCwd,
spawnCwd: cwd,
spawnCwd: hostSpawnCwd,
target: remoteTarget,
env,
managedHomeRunBinding: { env: { ...env }, onLog: input.ctx.onLog },
@@ -2742,11 +2746,7 @@ async function buildRuntime(input: {
// → the HOST cwd (`sessionCwd` resolves both). Every cwd-keyed session site
// reads `prepared.cwd`, so binding it once here keeps them consistent.
cwd: sessionCwd,
// Only the remote process-session lane needs the host proxy's `spawn()`
// `chdir` redirected off the in-sandbox `sessionCwd` and onto the host
// `cwd` (which is where the workspace was staged FROM, so it is host-valid).
// Every other lane leaves it `undefined` → acpx falls back to `cwd`.
hostSpawnCwd: useRemoteProcessSession ? cwd : undefined,
hostSpawnCwd: useRemoteProcessSession ? hostSpawnCwd : undefined,
workspaceId,
workspaceRepoUrl,
workspaceRepoRef,
@@ -269,12 +269,16 @@ describe("claude remote execution", () => {
}
});
it("uses the agent's subscription in a private SSH home without reading the SSH user's Claude login", async () => {
it.each(["copy", "in_place"] as const)("uses the agent's subscription in a private SSH home without reading the SSH user's Claude login (workspace=%s)", async mode => {
const rootDir = await mkdtemp(path.join(os.tmpdir(), "paperclip-claude-selected-ssh-"));
cleanupDirs.push(rootDir);
const workspaceDir = path.join(rootDir, "workspace");
const remoteMount = path.join(rootDir, "remote-filesystem");
const workspaceDir = mode === "in_place" ? path.join(remoteMount, "workspace") : path.join(rootDir, "workspace");
const providerHome = path.join(rootDir, "selected-provider");
await mkdir(workspaceDir);await mkdir(providerHome);
if (mode === "in_place") await writeFile(remoteMount, "The SSH workspace is not a local directory.");
else await mkdir(workspaceDir);
await mkdir(providerHome);
const remoteCwd = mode === "in_place" ? workspaceDir : "/remote/workspace";
const logs: string[] = [];
await execute({
runId: "selected-subscription", agent: { id: "agent-1", companyId: "company-1", name: "Configured agent", adapterType: "claude_local", adapterConfig: {} },
@@ -282,16 +286,26 @@ describe("claude remote execution", () => {
config: { engine: "cli", command: "claude", managedAiConnection: { provider: "anthropic", method: "subscription", identity: "selected-account" },
env: { HOME: rootDir, CLAUDE_CONFIG_DIR: providerHome, CLAUDE_CODE_OAUTH_TOKEN: "selected-agent-token", ANTHROPIC_API_KEY: "" } },
context: { paperclipWorkspace: { cwd: workspaceDir, source: "project_primary" } },
executionTransport: { remoteExecution: { useHostAuth: false, host: "127.0.0.1", port: 2222, username: "fixture", remoteWorkspacePath: "/remote/workspace", remoteCwd: "/remote/workspace", privateKey: null, knownHosts: null, strictHostKeyChecking: false } },
executionTarget: { kind: "remote", transport: "ssh", remoteCwd,
spec: { useHostAuth: false, host: "127.0.0.1", port: 2222, username: "fixture", remoteWorkspacePath: remoteCwd, remoteCwd, privateKey: null, knownHosts: null, strictHostKeyChecking: false },
workspaceRealization: { mode, authoritativeRoot: remoteCwd, pathAliases: [], outboundRestorePaths: [] } },
onLog: async (_stream, chunk) => { logs.push(chunk); },
});
expect(syncDirectoryToSsh).toHaveBeenCalledWith(expect.objectContaining({ localDir: providerHome, remoteDir: "/tmp/paperclip-ssh-runtime.claude/config-seed" }));
const providerCall = runChildProcess.mock.calls.find(call => call[2].includes("--print")) as unknown as [string, string, string[], { env: Record<string, string> }];
expect(providerCall[3].env).toMatchObject({ CLAUDE_CODE_OAUTH_TOKEN: "selected-agent-token", CLAUDE_CONFIG_DIR: "/tmp/paperclip-ssh-runtime.claude/config", HOME: "/tmp/paperclip-ssh-runtime.claude", ANTHROPIC_API_KEY: "" });
const providerCall = runChildProcess.mock.calls.find(call => call[2].includes("--print")) as unknown as [string, string, string[], { env: Record<string, string>; cwd: string }];
expect(providerCall[3].env).toMatchObject({ CLAUDE_CODE_OAUTH_TOKEN: "selected-agent-token", HOME: "/tmp/paperclip-ssh-runtime.claude", ANTHROPIC_API_KEY: "" });
if (mode === "copy") expect(providerCall[3].env.CLAUDE_CONFIG_DIR).toBe("/tmp/paperclip-ssh-runtime.claude/config");
else expect(path.posix.relative(remoteCwd, providerCall[3].env.CLAUDE_CONFIG_DIR!)).toMatch(/^\.paperclip-runtime\/claude\/conversations\/[a-f0-9]+\/[a-f0-9]+$/);
const materialize = runSshCommand.mock.calls.find(call => call[1].includes("config-seed"));
expect(materialize?.[1]).not.toContain(".claude/\u0024{file}");
expect(runSshCommand).toHaveBeenCalledWith(expect.anything(), "rm -rf -- '/tmp/paperclip-ssh-runtime.claude'", expect.anything());
expect(logs.join("")).not.toContain("selected-agent-token");
if (mode === "in_place") {
expect(providerCall[3].cwd).toBe(remoteCwd);
expect(prepareWorkspaceForSshExecution).not.toHaveBeenCalled();
expect(restoreWorkspaceFromSshExecution).not.toHaveBeenCalled();
expect(await readFile(remoteMount, "utf8")).toBe("The SSH workspace is not a local directory.");
}
});
it("removes the selected account's SSH home when Claude setup fails before launch", async () => {
@@ -222,7 +222,9 @@ async function buildClaudeRuntimeConfig(input: ClaudeExecutionInput): Promise<Cl
executionTargetIsRemote,
executionCwd: effectiveExecutionCwd,
});
await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
if (!executionTargetIsRemote || executionTarget?.workspaceRealization?.mode !== "in_place") {
await ensureAbsoluteDirectory(cwd, { createIfMissing: true });
}
const envConfig = parseObject(config.env);
const env: Record<string, string> = { ...buildPaperclipEnv(agent, input.agentIdentity) };