From 66028796f39cca64936610ce3b8c55b834fc7ab7 Mon Sep 17 00:00:00 2001 From: Dotta Date: Sat, 10 Oct 2026 12:22:22 -0500 Subject: [PATCH] fix: explain detached dev servers on persistent computers Co-Authored-By: Paperclip --- .../src/live/runnerd-codex-transport.test.ts | 26 +++++++++++++++++++ .../src/live/runnerd-codex-transport.ts | 11 +++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/packages/paperclip-runner/src/live/runnerd-codex-transport.test.ts b/packages/paperclip-runner/src/live/runnerd-codex-transport.test.ts index debd0c6e3fe..99c26734f8e 100644 --- a/packages/paperclip-runner/src/live/runnerd-codex-transport.test.ts +++ b/packages/paperclip-runner/src/live/runnerd-codex-transport.test.ts @@ -2158,6 +2158,32 @@ it.each(["installed", "explicit"] as const)("records the selected %s Codex comma } }); +it.each([false, true])("binds detached-process guidance only for a trusted persistent computer (%s)", async (computer) => { + const root = await mkdtemp(join(tmpdir(), "paperclip-computer-process-guidance-")); + const runnerBinary = join(root, "runnerd"); + await writeFile(runnerBinary, "unexecuted fixture artifact", { mode: 0o700 }); + let instructions = ""; + const { transport } = createCapabilityRunnerdCodexTransport({ + provider: "codex", runnerBinary, stateDirectory: root, sourceCodexHome: "", + codexCommand: "/qualified/codex", persistentAgentHome: computer ? "/agent/home" : undefined, + controlPlaneRegistration: async (authority) => { + instructions = String((authority.store.state.runAttachTemplate!.provider as { instructions: string }).instructions); + throw new Error("fixture_stop_before_runner_launch"); + }, + runnerProcessLauncher: () => { throw new Error("must not launch"); }, + }); + try { + await expect(transport.request("thread/start", { cwd: root, model: "gpt-6.1-sol", dynamicTools: [], + developerInstructions: "Preserve the task instructions." })).rejects.toThrow("fixture_stop_before_runner_launch"); + expect(instructions).toContain("Preserve the task instructions."); + expect(instructions.includes("nohup setsid")).toBe(computer); + if (computer) { + expect(instructions).toContain("stop when its warm timeout expires"); + expect(instructions).toContain("Do not create services or change runner ownership"); + } + } finally { await transport.close(); await rm(root, { recursive: true, force: true }); } +}); + it("rejects remote Codex without a guest executable before resolving controller dependencies", async () => { const root = await mkdtemp(join(tmpdir(), "paperclip-runner-remote-codex-command-")); const runnerBinary = join(root, "runnerd"); diff --git a/packages/paperclip-runner/src/live/runnerd-codex-transport.ts b/packages/paperclip-runner/src/live/runnerd-codex-transport.ts index ae90a54fb41..14894434b80 100644 --- a/packages/paperclip-runner/src/live/runnerd-codex-transport.ts +++ b/packages/paperclip-runner/src/live/runnerd-codex-transport.ts @@ -3443,6 +3443,11 @@ export function trustedRuntimeReadOnlyRoots( return [...roots]; } +function withComputerProcessInstructions(instructions: string, persistentAgentHome?: string): string { + if (!persistentAgentHome) return instructions; + return `${instructions}\n\nComputer runtime: files in AGENT_HOME persist across turns. A dev server needed between warm turns must survive the shell tool's process-group cleanup: use a detached session, for example \`nohup setsid dev-server.log 2>&1 &\`, and verify its listener from a separate command after the launching command returns. Detached processes still belong to this runner and stop when its warm timeout expires. Do not create services or change runner ownership to keep them alive.`; +} + export function createRunnerdCodexAppServerArgs(input: { environment: NodeJS.ProcessEnv | undefined; codexHome: string; @@ -4826,9 +4831,9 @@ class DurablePrpCodexTransport implements CodexAppServerTransport { const includeCodexCollaborationInstructions = provider === "codex" && record(params.config).include_collaboration_mode_instructions !== false; - const unboundBaseInstructions = String( + const unboundBaseInstructions = withComputerProcessInstructions(String( params.developerInstructions ?? params.baseInstructions ?? "You are a Paperclip agent.", - ); + ), this.options.persistentAgentHome); const baseInstructions = sourceRuntimeContext && runtimeContext ? unboundBaseInstructions.replaceAll( @@ -5445,7 +5450,7 @@ class DurablePrpCodexTransport implements CodexAppServerTransport { runtimeContext, this.options.baseInstructions === undefined ? undefined - : { text: this.options.baseInstructions, context: sourceRuntimeContext }, + : { text: withComputerProcessInstructions(this.options.baseInstructions, this.options.persistentAgentHome), context: sourceRuntimeContext }, ); if (provider === "codex") { // These controller-owned, token-free paths belong to the new run.