diff --git a/doc/native-workspace-finalization-recovery.md b/doc/native-workspace-finalization-recovery.md index 8796e38ef0e..5746d8b8da5 100644 --- a/doc/native-workspace-finalization-recovery.md +++ b/doc/native-workspace-finalization-recovery.md @@ -579,9 +579,12 @@ Remote provider-pack verification retries an interrupted read at most once. The retry waits one second so a fast gateway failure has time to recover. Each command retains its 30-second transport timeout. A timeout, signal, absent exit status, or transport exception does not prove artifact incompatibility. -Two inconclusive attempts hold the original run with -`runner_remote_provider_verification_unavailable`. Reattachment does not spend -a new provider attempt, so it cannot renew this exhausted read budget. A +Two inconclusive attempts on a fresh launch prove that no provider session +started, so the same run retries its startup with backoff within its provider +attempt budget. On any other attempt, two inconclusive attempts hold the +original run with `runner_remote_provider_verification_unavailable`. +Reattachment does not spend a new provider attempt, so it cannot renew this +exhausted read budget. A completed nonzero verification, digest mismatch, or wrong OpenCode version remains incompatible and cannot authorize a new provider turn. Recovery retains the exact source workspace and existing ownership gates; diff --git a/server/src/services/native-runtime/native-controller-recovery.integration.test.ts b/server/src/services/native-runtime/native-controller-recovery.integration.test.ts index 71024185b23..96ce858744c 100644 --- a/server/src/services/native-runtime/native-controller-recovery.integration.test.ts +++ b/server/src/services/native-runtime/native-controller-recovery.integration.test.ts @@ -201,6 +201,20 @@ describe.skipIf(!recoveryPostgresSupport.supported)("native controller durable d executionTargetKind: "local" })).toMatchObject({ recoveryMode: "exact_checkpoint_resume", providerSessionEstablished: true }); }); + it("retries a fresh launch whose provider pack could not be verified, and holds a reattachment", async () => { + const fixture = await seed(), runId = randomUUID(), runnerInstanceId = randomUUID(); + await db.insert(heartbeatRuns).values({ id: runId, companyId, agentId, nativeIssueId: fixture.scope.issueId, + nativeSessionId: fixture.scope.normalizedSessionId, runnerInstanceId, status: "running", runtimeMode: "native" }); + const bootstrap = { binding: { companyId, issueId: fixture.scope.issueId, runId }, transientIngressFailure: false, + identity: { runId, normalizedSessionId: fixture.scope.normalizedSessionId, runnerInstanceId, + environmentLeaseId: fixture.native.environmentLeaseId, turnId: `turn-${runId}`, itemId: `item-${runId}` } }; + const evidence = (fresh: boolean) => nativeProviderRecoveryEvidence({ db, runId, executionTargetKind: "remote", + sourceFailureCode: "runner_remote_provider_verification_unavailable", ...(fresh ? { bootstrap } : {}) }); + expect(await evidence(true)).toMatchObject({ recoveryMode: "bootstrap_retry", providerSessionEstablished: false, + providerEventsExist: false, checkpointExists: false }); + expect((await evidence(false)).recoveryMode).toBe("ambiguous_state"); + }); + it("retries a remote follow-up whose own server stopped serving before its runner, carrying only the predecessor session", async () => { // Daytona wave s9203: a graceful drain closed the runtime API listener while // a follow-up was still preparing. Its only checkpoint was the settled 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 cd8fcb9be11..392b0162d98 100644 --- a/server/src/services/native-runtime/native-session-executor.test.ts +++ b/server/src/services/native-runtime/native-session-executor.test.ts @@ -16385,6 +16385,16 @@ describe("native session bounded recovery", () => { } }); + it("retries exhausted verification of a fresh launch within the provider attempt budget", () => { + const now = new Date("2026-11-17T23:34:42.000Z"); + for (const attempt of [1, 2]) { + expect(nativeSessionFailureDisposition(attempt, now, "runner_remote_provider_verification_unavailable", { freshBootstrap: true })) + .toEqual({ phase: "retryable_failure", failureCode: "native_session_interrupted", nextAttemptAt: new Date(now.getTime() + 30_000) }); + } + expect(nativeSessionFailureDisposition(3, now, "runner_remote_provider_verification_unavailable", { freshBootstrap: true })) + .toEqual({ phase: "terminal_failure", failureCode: "native_session_retry_exhausted", nextAttemptAt: null }); + }); + it("preserves stable provider and runner failure causes", () => { expect( nativeSessionFailureSourceCode( diff --git a/server/src/services/native-runtime/native-session-executor.ts b/server/src/services/native-runtime/native-session-executor.ts index fee231ca370..86eb62b791d 100644 --- a/server/src/services/native-runtime/native-session-executor.ts +++ b/server/src/services/native-runtime/native-session-executor.ts @@ -9040,6 +9040,7 @@ export function nativeSessionFailureDisposition( attempt: number, now = new Date(), sourceFailureCode?: ReturnType, + options: { freshBootstrap?: boolean } = {}, ) { const permanentFailure = // A same-run retry would meet the same unretired owner on the same sandbox; @@ -9052,7 +9053,7 @@ export function nativeSessionFailureDisposition( sourceFailureCode === "native_provider_approval_required" || sourceFailureCode === "native_event_replay_conflict" || sourceFailureCode === "runner_remote_provider_artifact_incompatible" || - sourceFailureCode === "runner_remote_provider_verification_unavailable" || + sourceFailureCode === "runner_remote_provider_verification_unavailable" && !options.freshBootstrap || sourceFailureCode === "native_provider_terminal_failed" || sourceFailureCode === NATIVE_PROVIDER_STATE_INCOMPATIBLE || sourceFailureCode === NATIVE_PROVIDER_SIDE_EFFECT_PENDING || @@ -9563,7 +9564,9 @@ export async function nativeProviderRecoveryEvidence(input: { NATIVE_PROVIDER_STARTUP_REJECTED, "provider_session_open_timeout", "local_runtime_api_listener_unavailable", - ]).has(input.sourceFailureCode) || (input.sourceFailureCode === "runner_ingress_startup_failed" + ]).has(input.sourceFailureCode) + || input.sourceFailureCode === "runner_remote_provider_verification_unavailable" && !!input.bootstrap + || (input.sourceFailureCode === "runner_ingress_startup_failed" && !checkpointExists && !providerEventsExist && !!run?.nativeIssueId && !!run.nativeSessionId && !!run.runnerInstanceId && await nativeRunnerNeverAuthenticated(input.db, { companyId: run.companyId, issueId: run.nativeIssueId, runId: run.id }, { runId: run.id, normalizedSessionId: run.nativeSessionId, runnerInstanceId: run.runnerInstanceId })); @@ -13327,6 +13330,7 @@ async function executePaperclipNativeSessionAttempt( attempt, now, sourceFailureCode, + { freshBootstrap: bootstrap !== undefined }, ), { attempt, now, adoptedRunnerUnanswered, replacing: input.restartRecovery?.kind === "reattach_remote_runner" && input.restartRecovery.replaceUnansweredRunner === true,