From 27531c6eebccf14b6c940268755a2151ed4516d2 Mon Sep 17 00:00:00 2001 From: Dotta Date: Sun, 11 Oct 2026 08:26:56 -0500 Subject: [PATCH] Port typed computer instruction identity regressions Port the final four cases from 7634c65d227fb5f738c9c55a78ad3927b31c680f, including their original prerequisite fixture. The staging executor already has the matching production identity branch. No production or migration change. Co-authored-by: Codex --- .../native-session-executor.test.ts | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/server/src/services/native-runtime/native-session-executor.test.ts b/server/src/services/native-runtime/native-session-executor.test.ts index e05a1306614..877f745aa80 100644 --- a/server/src/services/native-runtime/native-session-executor.test.ts +++ b/server/src/services/native-runtime/native-session-executor.test.ts @@ -1,3 +1,4 @@ +import type { AdapterComputerExecutionTarget } from "@paperclipai/adapter-utils/execution-target"; import { createBoatTransportAdmission } from "../../modules/computers/adapters/boat.js"; import { closeWarmNativeSession, compareAndSealRetiredComputerCheckpoint, retiredComputerCheckpointIsSettled, retiredComputerCheckpointUnsettledReason, retireUnlaunchedComputerAttempt, nativeSessionBootstrapTimeoutMs } from "./native-session-executor.js"; import { prepareHeartbeatGitHubLaunchers } from "../heartbeat-github-launchers.js"; @@ -7980,6 +7981,56 @@ describe("native warm session supervision", () => { expect(secondCopy.collectStopped).toHaveBeenCalledOnce(); }); + it.each(["same", "generation", "owner", "computer"])("preserves command-transport directory identity across %s changes", async change => { + const name = `managed-computer-identity-${change}`; + const current = { ...execution, binding: { ...execution.binding, runId: `${name}-one`, executionWorkspaceId: name }, + session: { ...execution.session, normalizedSessionId: name, lifecyclePolicy: { mode: "warm", idleTimeoutMs: 60_000 } } } as NativeExecutionInputV1; + const close = vi.fn(async () => undefined); + const collectStopped = vi.fn(async () => undefined); + const retainWarm = vi.fn(async () => undefined); + const retire = vi.fn(async options => { + await options?.beforeStop?.(); + return true; + }); + const unexpectedProcessOperation = async (): Promise => { throw new Error("Identity fixture must not operate on a process"); }; + const target: AdapterComputerExecutionTarget = { kind: "remote", transport: "computer", environmentId: name, + remoteCwd: `/tmp/${name}`, listenerPort: 45001, + resourceAuthority: { kind: "computer-owner", computerId: name, ownerId: name, generation: 1 }, + fileAuthority: { kind: "remote-persistent", placementId: name, root: `/tmp/${name}`, agentHome: `/tmp/${name}/home` }, + processRunner: { execute: unexpectedProcessOperation }, launch: unexpectedProcessOperation, + inspectProcess: unexpectedProcessOperation, retainWarm, retire, + computerTool: { command: "cua-driver", args: ["mcp"] } }; + state.execute.mockReset().mockImplementationOnce(async options => { await options.onSession?.({ close }); return result; }); + await executePaperclipNativeSession({ db: leaseDb(current), execution: current, runnerInstanceId: name, + runnerExecutionTarget: target, + instructionWorkingCopy: { runId: current.binding.runId, root: `/tmp/${name}/home`, collectStopped, + checkpointWarm: async () => true, hasChanges: async () => false } }); + expect(retainWarm).toHaveBeenCalledWith(60_000); + const canReuse = vi.fn(async () => true); + const nextAuthority = { ...target.resourceAuthority, + ...(change === "generation" ? { generation: 2 } : {}), + ...(change === "owner" ? { ownerId: "different-owner" } : {}), + ...(change === "computer" ? { computerId: "different-computer" } : {}), + }; + const reservation = await reserveWarmNativeInstructionDirectory({ companyId: current.binding.companyId, + agentId: current.binding.agentId, previousRunId: current.binding.runId, runId: `${name}-two`, canReuse, + target: { ...target, resourceAuthority: nextAuthority } }); + if (change === "same" || change === "generation") { + expect(reservation?.reuseRunId).toBe(current.binding.runId); + expect(canReuse).toHaveBeenCalledOnce(); + expect(close).not.toHaveBeenCalled(); + expect(retire).not.toHaveBeenCalled(); + await reservation!.release(); + } else { + expect(reservation).toBeNull(); + expect(canReuse).not.toHaveBeenCalled(); + expect(retire).toHaveBeenCalledOnce(); + expect(close).toHaveBeenCalledOnce(); + expect(retire.mock.invocationCallOrder[0]).toBeLessThan(close.mock.invocationCallOrder[0]!); + expect(collectStopped).toHaveBeenCalledOnce(); + } + }); + it("stops before collecting when a checkpoint cannot stabilize", async () => { const f = await start("managed-fallback", false); expect(f.close).toHaveBeenCalledOnce();