From 440482b39648655e832750450b78fdd5213a1c2e Mon Sep 17 00:00:00 2001 From: Dotta Date: Sat, 10 Oct 2026 09:08:35 -0500 Subject: [PATCH] Recognize remote computer state during exact warm handoff --- .../native-session-executor.test.ts | 22 +++++++++++++++++++ .../native-runtime/native-session-executor.ts | 9 ++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) 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 79e82b1fa38..84e36a6a62f 100644 --- a/server/src/services/native-runtime/native-session-executor.test.ts +++ b/server/src/services/native-runtime/native-session-executor.test.ts @@ -332,6 +332,7 @@ import { nativeProviderUsageLimitFromEvent, nativeSessionFailureSourceCode, nativeProviderRecoveryEvidence, + verifyPriorRunnerdStateForSessionScope, nativeSessionRecoveryProjection, nativeGovernedWaitResult, nativeConversationReplyResult, @@ -13171,6 +13172,27 @@ describe("runnerd provider runtime wiring", () => { } }); + it.each([ + { owner: true, status: "succeeded", expected: "retained_warm_runner" }, + { owner: false, status: "succeeded", expected: "terminal_state_indeterminate" }, + { owner: true, status: "running", expected: "active" }, + ])("requires exact idle ownership for remote computer state ($owner, $status)", async ({ owner, status, expected }) => { + const root = await mkdtemp(join(tmpdir(), "paperclip-remote-warm-state-")); + const prior = execution; + const current = { ...execution, binding: { ...execution.binding, runId: "next-computer-run" } }; + const db = { select: () => ({ from: () => ({ where: () => ({ limit: async () => [ + { status, runnerProfileJson: { nativeExecutionInput: prior } }, + ] }) }) }) } as unknown as Db; + try { + expect(await verifyPriorRunnerdStateForSessionScope({ + db, root, execution: current, + identity: { runId: prior.binding.runId, normalizedSessionId: prior.session.normalizedSessionId, + runnerInstanceId: "computer-runner", environmentLeaseId: "computer-lease" }, + allowVerifiedBackup: false, remoteRunnerState: true, allowRetainedWarmRunner: owner, + })).toBe(expected); + } finally { await rm(root, { recursive: true, force: true }); } + }); + it.each([ { override: undefined, expected: "@openai/codex@0.160.0" }, { override: "@openai/codex@0.159.0", expected: "@openai/codex@0.159.0" }, diff --git a/server/src/services/native-runtime/native-session-executor.ts b/server/src/services/native-runtime/native-session-executor.ts index fd390ea518c..407bfa9ee92 100644 --- a/server/src/services/native-runtime/native-session-executor.ts +++ b/server/src/services/native-runtime/native-session-executor.ts @@ -4275,13 +4275,14 @@ export function nativePreProviderRetryAfterCleanupStateIsSafe(input: { } } -async function verifyPriorRunnerdStateForSessionScope(input: { +export async function verifyPriorRunnerdStateForSessionScope(input: { db: Db; root: string; identity: RunnerdDurableIdentity; execution: NativeExecutionInput; allowVerifiedBackup: boolean; allowRetainedWarmRunner: boolean; + remoteRunnerState?: boolean; }): Promise { let priorRun: { status: string; @@ -4335,7 +4336,7 @@ async function verifyPriorRunnerdStateForSessionScope(input: { // there is intentionally no suspended failover backup yet. The exact // idle in-memory session owner is the authority for this one case; // after a restart that owner is absent and this remains fail-closed. - (input.allowVerifiedBackup && directLifecycle === "absent")) + ((input.allowVerifiedBackup || input.remoteRunnerState) && directLifecycle === "absent")) ) { return "retained_warm_runner"; } @@ -4881,6 +4882,8 @@ async function migrateRunnerdStateRootForExecution(input: { execution: input.execution, allowVerifiedBackup: input.allowVerifiedBackup, allowRetainedWarmRunner: input.allowRetainedWarmRunner, + remoteRunnerState: input.runnerExecutionTarget?.kind === "remote" && + input.runnerExecutionTarget.transport === "computer", }); if ( verification !== "verified" && @@ -4923,6 +4926,8 @@ async function migrateRunnerdStateRootForExecution(input: { execution: input.execution, allowVerifiedBackup: input.allowVerifiedBackup, allowRetainedWarmRunner: input.allowRetainedWarmRunner, + remoteRunnerState: input.runnerExecutionTarget?.kind === "remote" && + input.runnerExecutionTarget.transport === "computer", }); if ( verification !== "verified" &&