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 41b17005b98..6aafeb14e28 100644 --- a/packages/paperclip-runner/src/live/runnerd-codex-transport.test.ts +++ b/packages/paperclip-runner/src/live/runnerd-codex-transport.test.ts @@ -2746,7 +2746,7 @@ it.each(["acpx-runtime-sidecar.cjs", "opencode-app-server-proxy.cjs"] as const)( it("requires a remote OpenCode executable before resolving controller dependencies", () => { expect(() => runnerdLaunchProfileInternals.resolveRunnerOpenCodeExecutable({ runnerFilesystemRoot: "/provider-pack", - })).toThrow("OpenCode executable is missing from the provider pack"); + })).toThrow("runner_remote_provider_launch_unprepared: OpenCode executable is missing from the provider pack launch inputs"); expect(runnerdLaunchProfileInternals.resolveRunnerOpenCodeExecutable({ runnerFilesystemRoot: "/provider-pack", opencodeCommand: "/provider-pack/opencode", })).toBe("/provider-pack/opencode"); @@ -3810,7 +3810,7 @@ it("rejects remote OpenCode before spawn when provider-pack paths are absent", a baseInstructions: "Complete the task.", dynamicTools: [], }), - ).rejects.toThrow("runner_remote_provider_artifact_incompatible"); + ).rejects.toThrow("runner_remote_provider_launch_unprepared"); } finally { await transport.close(); await rm(root, { recursive: true, force: true }); diff --git a/packages/paperclip-runner/src/live/runnerd-codex-transport.ts b/packages/paperclip-runner/src/live/runnerd-codex-transport.ts index 27cf5cbfd35..312a063efb4 100644 --- a/packages/paperclip-runner/src/live/runnerd-codex-transport.ts +++ b/packages/paperclip-runner/src/live/runnerd-codex-transport.ts @@ -3765,7 +3765,7 @@ function acpxRunnerLaunchProfile( const authorityDigest = options.providerPackAuthorityDigest; if (!commandSha256 || !sidecarScriptSha256 || !authorityDigest) { throw new Error( - "runner_remote_provider_artifact_incompatible: ACPX launch profile omitted its provider-pack authority or verified artifact digests", + "runner_remote_provider_launch_unprepared: ACPX launch profile omitted its provider-pack authority or verified artifact digests", ); } return { @@ -3809,7 +3809,7 @@ function opencodeRunnerLaunchProfile( (usesLocalBuildOwnedDefaults ? localDigest(executable) : null); if (!commandSha256 || !proxyScriptSha256 || !executableSha256) { throw new Error( - "runner_remote_provider_artifact_incompatible: OpenCode launch profile omitted verified artifact digests", + "runner_remote_provider_launch_unprepared: OpenCode launch profile omitted verified artifact digests", ); } return { @@ -3825,7 +3825,9 @@ function opencodeRunnerLaunchProfile( function resolveRunnerOpenCodeExecutable(options: RunnerdCodexTransportOptions): string { if (options.opencodeCommand !== undefined) return options.opencodeCommand; if (options.runnerFilesystemRoot) { - throw new Error("runner_remote_provider_artifact_incompatible: OpenCode executable is missing from the provider pack"); + // The controller did not pass the prepared pack's launch inputs. The pack + // itself was not judged, so the controller prepares again and retries. + throw new Error("runner_remote_provider_launch_unprepared: OpenCode executable is missing from the provider pack launch inputs"); } return resolvePinnedOpenCodeCommand(); } @@ -6450,17 +6452,17 @@ class DurablePrpCodexTransport implements CodexAppServerTransport { } if (!this.options.providerNodeCommand) { throw new Error( - "runner_remote_provider_artifact_incompatible: remote JS provider omitted its provider-pack Node executable", + "runner_remote_provider_launch_unprepared: remote JS provider omitted its provider-pack Node executable", ); } if (provider === "opencode" && !this.options.opencodeProxyPath) { throw new Error( - "runner_remote_provider_artifact_incompatible: remote OpenCode omitted its packaged proxy", + "runner_remote_provider_launch_unprepared: remote OpenCode omitted its packaged proxy", ); } if (provider === "acpx" && !this.options.acpxSidecarPath) { throw new Error( - "runner_remote_provider_artifact_incompatible: remote ACPX omitted its packaged sidecar", + "runner_remote_provider_launch_unprepared: remote ACPX omitted its packaged sidecar", ); } } diff --git a/server/src/services/continuation-cause.ts b/server/src/services/continuation-cause.ts index 4a66e9ecf9a..93450428c50 100644 --- a/server/src/services/continuation-cause.ts +++ b/server/src/services/continuation-cause.ts @@ -50,6 +50,25 @@ export const RESTART_CLASS_FAILURE_CODES = [ "runner_remote_process_identity_unavailable", "continuation_user_authorization_missing", ] as const; +/** + * Older releases recorded this as an incompatible provider pack and blocked + * the task. The pack was fine: the controller built a replacement Runner + * launch without its OpenCode inputs. A fresh run prepares them again. + * Releases since then report it as `runner_remote_provider_launch_unprepared` + * and retry it within the run. + */ +export const LEGACY_LAUNCH_UNPREPARED_FAILURE = { + code: "runner_remote_provider_artifact_incompatible", + /** The stable part of the message. The stored error may carry a prefix, a + * suffix or redaction, so match it anywhere, together with the code. */ + marker: "OpenCode executable is missing from the provider pack", +} as const; + +export function isLegacyLaunchUnpreparedFailure(cause: string | null | undefined, run: { error?: string | null }): boolean { + return cause === LEGACY_LAUNCH_UNPREPARED_FAILURE.code + && typeof run.error === "string" && run.error.includes(LEGACY_LAUNCH_UNPREPARED_FAILURE.marker); +} + const REUSABLE_SANDBOX_RESUME_FAILED = "reusable_sandbox_resume_failed"; const TRANSIENT_SANDBOX_CAUSES = ["transport_timeout", "transport_closed", "sandbox_state_transition", "provider_rate_limited", "provider_unavailable"] as const; diff --git a/server/src/services/fresh-continuation-fallback.test.ts b/server/src/services/fresh-continuation-fallback.test.ts index b019619dca0..99361072570 100644 --- a/server/src/services/fresh-continuation-fallback.test.ts +++ b/server/src/services/fresh-continuation-fallback.test.ts @@ -43,6 +43,8 @@ type Seed = { /** How today's code leaves the run: an active hold (before disposition) or a settled-but-blocked hold (older releases). */ hold?: "active" | "settled_blocked" | "none"; coordinatorState?: string; + /** The hold's cause, when the run's own failure code blocked the task directly. */ + holdCause?: string; }; suite("fresh-continuation fallback", () => { @@ -90,7 +92,7 @@ suite("fresh-continuation fallback", () => { : { runnerProfileJson: { adapterDispatch: { adapterType: "paperclip_runner" } } }) }); if (seed.runtime === "native") { await db.insert(nativeRunFinalizations).values({ runId, companyId, issueId, phase: "terminal_failure", - recoveryState: seed.coordinatorState ?? "blocked", failureCode: "native_continuation_requires_reconciliation", leaseOwner: null }); + recoveryState: seed.coordinatorState ?? "blocked", failureCode: seed.holdCause ?? "native_continuation_requires_reconciliation", leaseOwner: null }); } let actionId: string | null = null; if ((seed.hold ?? "active") !== "none") { @@ -99,7 +101,7 @@ suite("fresh-continuation fallback", () => { const [action] = await db.insert(issueRecoveryActions).values({ companyId, sourceIssueId: issueId, kind: "active_run_watchdog", status: settled ? "resolved" : "active", outcome: settled ? "blocked" : null, resolvedAt: settled ? finishedAt : null, ownerType: "board", returnOwnerAgentId: agentId, - cause: native ? "native_continuation_requires_reconciliation" : "legacy_execution_requires_reconciliation", + cause: seed.holdCause ?? (native ? "native_continuation_requires_reconciliation" : "legacy_execution_requires_reconciliation"), fingerprint: native ? `native-continuation:${runId}` : `legacy-execution:${runId}`, nextAction: "Inspect the original failure and reconcile the previous execution before continuing. Automatic recovery cannot start another incident.", maxAttempts: 3, createdAt: finishedAt, @@ -124,6 +126,15 @@ suite("fresh-continuation fallback", () => { await deliverReconciledExecutions(db, heartbeat.wakeup); } + async function deliverOneSuccessor(f: { issueId: string; runId: string }) { + expect(await getExecutionBlocker(db, companyId, f.issueId)).toBeNull(); + await occupySlot(); + await deliver(); + const next = await successors(f.runId); + expect(next).toHaveLength(1); + return next[0]!; + } + async function expectOneFreshSuccessor(f: { issueId: string; runId: string }) { expect(await getExecutionBlocker(db, companyId, f.issueId)).toBeNull(); expect(await issue(f.issueId)).toMatchObject({ status: "todo" }); @@ -177,6 +188,41 @@ suite("fresh-continuation fallback", () => { await expectOneFreshSuccessor(f); }, 60_000); + // paperclip.staging, 2026-11-25: a replaced OpenCode session was built + // without its launch inputs, and the run failed as an incompatible provider + // pack. The pack was fine; a fresh run prepares those inputs again, so the + // task held by an older release continues without a Retry. + it.each([ + "runner_remote_provider_artifact_incompatible: OpenCode executable is missing from the provider pack", + // As a wrapping layer records it, with a prefix and trailing detail. + "runner_ingress_unavailable: runnerd process failed: runner_remote_provider_artifact_incompatible: " + + "OpenCode executable is missing from the provider pack (attempt=2)", + ])("continues a task blocked because the controller left out the OpenCode launch inputs (%s)", async error => { + const f = await unfinishedRun({ runtime: "native", errorCode: "runner_remote_provider_artifact_incompatible", + error, holdCause: "runner_remote_provider_artifact_incompatible" }); + await settleUnrecoverableExecutions(db); + // The continuation settles the hold it started from, so a second pass + // neither selects it again nor starts another run. + expect(await evidenceOf(f.actionId!)).toMatchObject({ status: "resolved" }); + await settleUnrecoverableExecutions(db); + const next = await deliverOneSuccessor(f); + expect(next.contextSnapshot).toMatchObject({ issueId: f.issueId, previousRunId: f.runId, forceFreshSession: true }); + await settleUnrecoverableExecutions(db); + await deliver(); + expect(await successors(f.runId)).toHaveLength(1); + expect(await evidenceOf(f.actionId!)).toMatchObject({ status: "resolved" }); + }, 60_000); + + it("leaves a task blocked by a genuinely incompatible provider pack for a person", async () => { + const f = await unfinishedRun({ runtime: "native", errorCode: "runner_remote_provider_artifact_incompatible", + error: "runner_remote_provider_artifact_incompatible: provider pack manifest digest mismatch", + holdCause: "runner_remote_provider_artifact_incompatible" }); + await settleUnrecoverableExecutions(db); + await deliver(); + expect(await successors(f.runId)).toHaveLength(0); + expect(await issue(f.issueId)).toMatchObject({ status: "blocked" }); + }, 60_000); + // Staging: the person had already pressed Retry, and the automatic successor // could not carry that authorization forward. That is the system's failure, // not the person's: the task continues under its responsible user. diff --git a/server/src/services/fresh-continuation-fallback.ts b/server/src/services/fresh-continuation-fallback.ts index e0cfc89c177..98f98168525 100644 --- a/server/src/services/fresh-continuation-fallback.ts +++ b/server/src/services/fresh-continuation-fallback.ts @@ -30,7 +30,8 @@ import { readRunCancellation } from "./run-cancellation.js"; import { activeIssueInteractionCondition } from "./issue-question-context.js"; import { readSystemRecovery } from "./system-recovery-state.js"; import { readWorkspaceProviderFailure } from "./workspace-provider-failure.js"; -import { RESTART_CLASS_FAILURE_CODES, continuationCauseIsSystemOwned, isPersonOwnedFailureCode } from "./continuation-cause.js"; +import { RESTART_CLASS_FAILURE_CODES, continuationCauseIsSystemOwned, isLegacyLaunchUnpreparedFailure, isPersonOwnedFailureCode } + from "./continuation-cause.js"; import { sharedContinuationAttempts } from "./recovery/continuation-ledger.js"; import { BACKLOG_CONTINUATION_MAX_AGE_MS, failureOwnsBlock, heldExecutionWhere, heldRunIdSql, interruptionEligibility, liveDispositionHoldSql, recentInterruptionSourceSql, sourceRunKey } from "./fresh-continuation-eligibility.js"; @@ -306,9 +307,11 @@ const blocksExecution = (hold: typeof issueRecoveryActions.$inferSelect) => ["active", "escalated"].includes(hold.status) || object(hold.evidence.automaticRecovery).replay === "blocked"; /** A reconciliation hold that blocks the task and that this decision settles. */ -function isOwnedReconciliationHold(hold: typeof issueRecoveryActions.$inferSelect) { +function isOwnedReconciliationHold(hold: typeof issueRecoveryActions.$inferSelect, run: { error?: string | null }) { if (hold.kind === "stranded_assigned_issue") return false; - const interruption = hold.kind === "active_run_watchdog" && (RESTART_CLASS_FAILURE_CODES as readonly string[]).includes(hold.cause); + const interruption = hold.kind === "active_run_watchdog" && ((RESTART_CLASS_FAILURE_CODES as readonly string[]).includes(hold.cause) + // An older release held this controller launch gap as a pack incompatibility. + || isLegacyLaunchUnpreparedFailure(hold.cause, run)); if ((!(EXECUTION_RECONCILIATION_CAUSES as readonly string[]).includes(hold.cause) && !interruption) || !blocksExecution(hold)) return false; if (isHumanGate(hold)) return false; // A restore hold is owned only once its saved-work recovery completed. @@ -414,13 +417,13 @@ export async function continueFreshInTransaction(tx: Db, input: Input): Promise< .orderBy(asc(issueRecoveryActions.createdAt), asc(issueRecoveryActions.id)).for("update"); const prior = holds.find(hold => object(hold.evidence.freshContinuation).sourceRunId === run.id); if (prior) { - await settleLateHolds(tx, { companyId, issue, run, prior, holds: holds.filter(isOwnedReconciliationHold), now }); + await settleLateHolds(tx, { companyId, issue, run, prior, holds: holds.filter(hold => isOwnedReconciliationHold(hold, run)), now }); return { kind: "already_continued", recoveryActionId: prior.id }; } // The holds this decision owns: reconciliation holds that still block the // task. Workspace restore/repair holds stay with workspace recovery, and // resolved history is never rewritten. - const ownedHolds = holds.filter(isOwnedReconciliationHold); + const ownedHolds = holds.filter(hold => isOwnedReconciliationHold(hold, run)); const [refused] = await tx.select({ id: heartbeatRuns.id }).from(heartbeatRuns).where(and( eq(heartbeatRuns.companyId, companyId), sql`${heartbeatRuns.id} <> ${run.id}`, @@ -510,7 +513,7 @@ export async function continueFreshInTransaction(tx: Db, input: Input): Promise< if (recovery && EXACT_RECOVERY_STATES.includes(recovery.state)) waits.push(pending("saved_work_recovery_running", new Date(Math.max(recheck.getTime(), recovery.nextAttemptAt ?? 0)))); - if (!isOwnedReconciliationHold(hold) && isRestoreHold(hold) && blocksExecution(hold) && recovery?.state !== "complete") + if (!isOwnedReconciliationHold(hold, run) && isRestoreHold(hold) && blocksExecution(hold) && recovery?.state !== "complete") waits.push(pending("workspace_recovery_owns_restore", recheck)); const retainedCheck = object(hold.evidence.retainedSourceFallbackCheck); if (recovery?.state === "exhausted" && typeof retainedCheck.nextCheckAt === "number" && retainedCheck.nextCheckAt > now.getTime()) @@ -520,7 +523,7 @@ export async function continueFreshInTransaction(tx: Db, input: Input): Promise< if (firstWait) return firstWait; // Past the bound, a hold that workspace recovery still owns is settled too: // the continuation never uses that workspace (isolation below). - const owned = pastBound() ? holds.filter(hold => isOwnedReconciliationHold(hold) + const owned = pastBound() ? holds.filter(hold => isOwnedReconciliationHold(hold, run) || (isRestoreHold(hold) && blocksExecution(hold) && !isHumanGate(hold))) : ownedHolds; // (b) Causes that are the person's. diff --git a/server/src/services/native-interruption-continuation.ts b/server/src/services/native-interruption-continuation.ts index fedea0357a9..5ce72cd4e19 100644 --- a/server/src/services/native-interruption-continuation.ts +++ b/server/src/services/native-interruption-continuation.ts @@ -1,13 +1,16 @@ -import { and, eq, inArray, isNull, not, sql } from "drizzle-orm"; +import { and, eq, inArray, isNull, not, or, sql } from "drizzle-orm"; import { heartbeatRuns, issueRecoveryActions, nativeRunFinalizations, type Db } from "@paperclipai/db"; -import { RESTART_CLASS_FAILURE_CODES, isRestartClassFailureCode } from "./continuation-cause.js"; +import { LEGACY_LAUNCH_UNPREPARED_FAILURE, RESTART_CLASS_FAILURE_CODES, isLegacyLaunchUnpreparedFailure, + isRestartClassFailureCode } from "./continuation-cause.js"; import { canonicalExecutionUuid } from "./execution-identity.js"; import { continueFreshInTransaction, recordFreshContinuationCheck } from "./fresh-continuation-fallback.js"; import { nativeReplacementPending } from "./native-runtime/native-safe-replacement.js"; export function nativeInterruptionHold() { return and( - inArray(issueRecoveryActions.cause, [...RESTART_CLASS_FAILURE_CODES]), + or(inArray(issueRecoveryActions.cause, [...RESTART_CLASS_FAILURE_CODES]), + and(eq(issueRecoveryActions.cause, LEGACY_LAUNCH_UNPREPARED_FAILURE.code), + sql`strpos(coalesce(${heartbeatRuns.error}, ''), ${LEGACY_LAUNCH_UNPREPARED_FAILURE.marker}) > 0`)), eq(heartbeatRuns.runtimeMode, "native"), eq(heartbeatRuns.nativePhase, "terminal_failure"), eq(nativeRunFinalizations.phase, "terminal_failure"), isNull(nativeRunFinalizations.nextAttemptAt), not(nativeReplacementPending()!), @@ -21,7 +24,7 @@ export async function continueNativeInterruption(tx: Db, input: { now: Date; }): Promise { const { action, run, coordinator, now } = input; - if (!isRestartClassFailureCode(action.cause) || run.runtimeMode !== "native" || run.nativePhase !== "terminal_failure" + if ((!isRestartClassFailureCode(action.cause) && !isLegacyLaunchUnpreparedFailure(action.cause, run)) || run.runtimeMode !== "native" || run.nativePhase !== "terminal_failure" || coordinator?.phase !== "terminal_failure" || coordinator.nextAttemptAt || coordinator.leaseOwner || coordinator.resultId) return false; const fresh = await continueFreshInTransaction(tx, { companyId: action.companyId, runId: run.id, trigger: "recovery_refused", now }); 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 0c5a8d5864e..03e8819f295 100644 --- a/server/src/services/native-runtime/native-session-executor.test.ts +++ b/server/src/services/native-runtime/native-session-executor.test.ts @@ -2968,7 +2968,7 @@ describe("remote provider pack manifest", () => { return JSON.stringify(value); }; - it.each(["opencode", "opencode-new-durable", "opencode-new-durable-reset", "opencode-new-durable-inspect-reset", "opencode-new-durable-provider-reset", "opencode-new-durable-store-failed", "opencode-new-durable-publish-failed", "opencode-new-durable-slow-capture", "opencode-new-durable-ready", "opencode-continuation", "opencode-continuation-missing", "opencode-continuation-no-receipt", "opencode-continuation-replacement", "opencode-continuation-cold", "opencode-continuation-legacy-durable", "opencode-continuation-prior-receipt", "opencode-dirty", "opencode-diagnostics", "opencode-diagnostics-stale", "cursor", "claude-x64", "claude-arm64"] as const)("uses the bundled Linux image authority for remote %s without controller overrides", async provider => { + it.each(["opencode", "opencode-new-durable", "opencode-new-durable-reset", "opencode-new-durable-inspect-reset", "opencode-new-durable-provider-reset", "opencode-new-durable-store-failed", "opencode-new-durable-publish-failed", "opencode-new-durable-slow-capture", "opencode-new-durable-ready", "opencode-continuation", "opencode-continuation-missing", "opencode-continuation-no-receipt", "opencode-continuation-replacement", "opencode-continuation-cold", "opencode-continuation-legacy-durable", "opencode-continuation-prior-receipt", "opencode-continuation-prior-receipt-replacement", "opencode-dirty", "opencode-diagnostics", "opencode-diagnostics-stale", "cursor", "claude-x64", "claude-arm64"] as const)("uses the bundled Linux image authority for remote %s without controller overrides", async provider => { const firstDurable = provider.startsWith("opencode-new-durable"); // A sandbox connection drops once while the settled state is read out. let checkpointReadResets = provider === "opencode-new-durable-reset" ? 1 : 0; @@ -3242,7 +3242,8 @@ describe("remote provider pack manifest", () => { if (provider === "opencode-continuation-no-receipt") await rm(receiptPath); const cold = provider === "opencode-continuation-cold"; const legacyDurable = provider === "opencode-continuation-legacy-durable"; - const priorReceipt = provider === "opencode-continuation-prior-receipt"; + const priorReceiptReplacement = provider === "opencode-continuation-prior-receipt-replacement"; + const priorReceipt = provider === "opencode-continuation-prior-receipt" || priorReceiptReplacement; const launchRoot = `/home/runtime-account/.paperclip-runtime/paperclip-runner/provider-artifacts/${installed.digest.slice(7)}`; const artifactReceipt = { schema: "paperclip.native-provider-artifacts.v1" as const, artifactId: randomUUID(), closureDigest: "sha256:" + "9".repeat(64), providerPackDigest: installed.digest, manifest: installed, launchRoot, accountUid: 1000 }; @@ -3276,7 +3277,7 @@ describe("remote provider pack manifest", () => { ...(cold ? { controllerPersistence: { bootId: randomUUID() }, providerPackAdmissionSource: { runId: remoteExecution.binding.runId, receipt: coldAdmission, state: { schema: "paperclip.native-provider-pack-admission-state.v1", state: "verified", admissionEpoch: randomUUID() }, artifacts: artifactReceipt } } : {}), - runnerEnvironment: configuredEnvironmentProjection(provider === "opencode-continuation-replacement" ? {} : { PAPERCLIP_OPENCODE_PERFORMANCE_DIAGNOSTICS: "1" }), + runnerEnvironment: configuredEnvironmentProjection(provider === "opencode-continuation-replacement" || priorReceiptReplacement ? {} : { PAPERCLIP_OPENCODE_PERFORMANCE_DIAGNOSTICS: "1" }), runnerExecutionTarget: { kind: "remote", transport: "sandbox", remoteCwd: cold ? "/workspace-new-allocation-lease" : "/workspace", environmentId: "environment", leaseId: "lease", providerKey: "daytona", effectiveCapabilities: { runnerWebSocketIngress: true }, runner: { execute: selectedExecute, syncIn, @@ -3328,6 +3329,35 @@ describe("remote provider pack manifest", () => { state.createBackend.mock.calls.at(-1)![1].codexTransportFactory!(); expect(state.createTransport.mock.calls.at(-1)![0]).toMatchObject({ providerPackAuthorityDigest: installed.digest }); } + if (priorReceiptReplacement) { + // A provider session restored from saved artifacts launches from the + // artifact root and never selects a pack root. When exact resume fails + // and the session is replaced, the replacement transport is built + // before its Runner is staged, so it must already carry the OpenCode + // launch inputs (staging, 2026-11-25: "OpenCode executable is missing + // from the provider pack"). + const backend = state.createBackend.mock.results.at(-1)!.value; + const factory = state.createBackend.mock.calls.at(-1)![1].codexTransportFactory!; + let replacementOptions: Record | undefined; + const preparationsBefore = prepareRemote.mock.calls.length; + Object.assign(backend, { openSession: async () => { + // The replacement stages its launch inputs itself, before its transport is built. + expect(prepareRemote.mock.calls.length).toBe(preparationsBefore + 1); + factory(); + replacementOptions = state.createTransport.mock.calls.at(-1)![0] as Record; + return { identity: () => ({ ...remoteExecution.binding, sessionId: remoteExecution.session.normalizedSessionId! }) }; + } }); + const priorIdentity = { ...remoteExecution.binding, sessionId: remoteExecution.session.normalizedSessionId! }; + await continued.openReplacementSession!({ identity: priorIdentity }, { + backendKind: "runner", identity: priorIdentity, sessionId: priorIdentity.sessionId, + providerSessionId: "prior-provider-session", activeTurnId: null, terminal: null, + }); + expect(replacementOptions).toMatchObject({ + providerNodeCommand: `${launchRoot}/${installed.payload.artifacts.nodeCommand.path}`, + opencodeCommand: `${launchRoot}/${installed.payload.artifacts.opencodeExecutable.path}`, + opencodeProxyPath: `${launchRoot}/${installed.payload.artifacts.opencodeProxy.path}`, + }); + } } if (provider === "claude-x64" || provider === "opencode") { const admitted = opencode ? installed : manifest; @@ -17206,6 +17236,19 @@ describe("native session bounded recovery", () => { })).toMatchObject({ issueStatus: "blocked", recoveryOwner: { kind: "board" } }); }); + it("retries a launch that the controller left without its OpenCode inputs instead of blocking the task", () => { + const now = new Date("2026-11-25T20:42:23.000Z"); + const code = nativeSessionFailureSourceCode(new Error( + "runner_remote_provider_launch_unprepared: OpenCode executable is missing from the provider pack launch inputs")); + expect(code).toBe("runner_remote_provider_launch_unprepared"); + expect(nativeSessionFailureDisposition(1, now, code)).toEqual({ + phase: "retryable_failure", failureCode: "native_session_interrupted", + nextAttemptAt: new Date("2026-11-25T20:42:53.000Z"), + }); + expect(nativeSessionFailureDisposition(3, now, code)).toMatchObject({ + phase: "terminal_failure", failureCode: "native_session_retry_exhausted" }); + }); + it("retries the same run twice and stops at the third failed attempt", () => { const now = new Date("2026-08-09T00:00:00.000Z"); expect( diff --git a/server/src/services/native-runtime/native-session-executor.ts b/server/src/services/native-runtime/native-session-executor.ts index 910f5e9e09b..6a010df0d3c 100644 --- a/server/src/services/native-runtime/native-session-executor.ts +++ b/server/src/services/native-runtime/native-session-executor.ts @@ -9339,6 +9339,7 @@ function classifyNativeSessionFailure( | "native_session_cleanup_quarantined" | "native_adopted_runner_authentication_timeout" | "runner_remote_provider_artifact_incompatible" + | "runner_remote_provider_launch_unprepared" | "runner_remote_provider_verification_unavailable" | "provider_process_exited" | "provider_stdout_closed" @@ -9426,6 +9427,9 @@ function classifyNativeSessionFailure( if (/native_adopted_runner_authentication_timeout/i.test(message)) { return "native_adopted_runner_authentication_timeout"; } + if (/runner_remote_provider_launch_unprepared/i.test(message)) { + return "runner_remote_provider_launch_unprepared"; + } if (/runner_remote_provider_artifact_incompatible/i.test(message)) { return "runner_remote_provider_artifact_incompatible"; } @@ -9650,6 +9654,7 @@ export async function nativeProviderRecoveryEvidence(input: { ReturnType >([ "runner_remote_provider_artifact_incompatible", + "runner_remote_provider_launch_unprepared", "provider_process_exited", "provider_stdout_closed", "provider_process_output_closed", @@ -19557,6 +19562,23 @@ async function createRunnerdBackendWithinSessionClaim( replacementBackend = fresh; return fresh.openSession(sessionInput); } + // The archive dropped the restored provider artifacts and their launch + // paths. The replacement transport reads its launch inputs when it is + // built, before its Runner is staged, so stage them again first. Without + // this a session restored from saved artifacts (which never selects a + // pack root) replaces itself with no OpenCode executable, and any other + // session launches from the pack root while its saved receipt names the + // artifact root, which the next continuation's Runner rejects. + if (requiresRemoteProviderPack) { + // Force a full preparation here rather than relying on the archive + // having cleared it: a prepared flag or cached launch inputs left over + // from the archived session would make this a silent no-op. + remotePrepared = false; + openCodeLaunchArtifacts = undefined; + await prepareNativeRemoteRunner({ target, runnerIngressAuthorized: input.runnerIngressAuthorized === true, + runnerPublicUrl: input.runnerPublicUrl, runnerCaBundlePath: input.runnerCaBundlePath, + runId: input.execution.binding.runId, prepareRemote: prepareRemoteRunner }); + } cursorCloudRuntime?.register(); try { const session = await backend.openSession(sessionInput);