fix(native): retry a fresh launch whose provider pack could not be verified (#22106)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Before a remote native run starts its provider, the controller
selects a provider pack and verifies it in the sandbox
> - The verification command retries once. If both reads fail without a
result (a timeout, a signal, or a transport error such as HTTP 502), the
run fails with `runner_remote_provider_verification_unavailable`
> - That code holds the run for a person in every case. The hold exists
for reattachment, which does not spend a new provider attempt and could
loop
> - On a fresh launch the code is also not on the list of failures that
prove no provider session started. So the run is classified as
"ambiguous state", and the task waits behind a Board-owned Retry
> - This pull request retries a fresh launch's unverified pack on the
same run, within the provider attempt budget, and keeps the hold for
every other attempt
> - The benefit is that a short sandbox outage during startup no longer
stops a chat or task until a person clicks Retry

## Linked Issues or Issue Description

**What happened?**
A chat message started a fresh native run on a new sandbox. The
preinstalled provider pack did not match, so the controller uploaded the
pack. Both reads that verified the uploaded pack failed with "Request
failed with status code 502". No provider process started. The run
failed with `runner_remote_provider_verification_unavailable`, the
recovery mode was `ambiguous_state`, and the chat showed a Retry button.
A manual Retry then succeeded.

**Steps to reproduce**
1. Start a fresh remote native run.
2. Make both provider-pack verification reads fail without a result, for
example with a 502 from the sandbox command API.

**Expected behavior**
The run retries its startup on the same run, with backoff, because no
provider session started.

**Actual behavior**
The run is held for a person with "Inspect the original provider failure
and explicitly resolve the ambiguous session state".

## What Changed

- `native-session-executor.ts`:
- `nativeProviderRecoveryEvidence` treats
`runner_remote_provider_verification_unavailable` as definitely
pre-session when the attempt is a fresh bootstrap (the caller passes
`bootstrap`). As for every pre-session code, this applies only when the
run has no checkpoint and no provider event.
- `nativeSessionFailureDisposition` takes an optional `freshBootstrap`
flag. With it, `runner_remote_provider_verification_unavailable` is
retryable instead of permanent, so the existing same-run startup retry
and its three-attempt budget apply. The executor passes the same
fresh-bootstrap condition it already uses for `bootstrap`.
- Reattachment, warm session recovery and retained transitions do not
pass `bootstrap`, so they keep the hold.
- `doc/native-workspace-finalization-recovery.md`: describe the
fresh-launch retry.
- Tests: the disposition retries attempts 1 and 2 of a fresh launch and
stops at attempt 3, and the existing reattachment hold test is
unchanged. An integration test shows `bootstrap_retry` for a fresh
launch with no checkpoint, and `ambiguous_state` without `bootstrap`.

## Verification

- `npx vitest run` on the new cases: pass. Both fail without the source
change.
- `npx vitest run` on the native session executor, controller recovery,
remote provider pack, online source, status arbiter corpus, continuation
and startup/retry suites: 2203 pass, 8 skipped.
- `npx tsc --noEmit` passes for the server.

## Risks

- Low. Only a fresh launch with no checkpoint and no provider event
changes. A deterministic verification outage now costs up to two more
startup attempts, with backoff, before the run is held.
- A completed verification that fails
(`runner_remote_provider_artifact_incompatible`) is unchanged.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), with tool use and code execution
in Claude Code.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Devin FoleyandPaperclip authored and GitHub committed 2026-11-18 10:40:31 -08:00
1 parent 8282d386da
commit 8285a81280
4 files changed
+36 -5

No files matched your search

@@ -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;
@@ -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
@@ -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(
@@ -9040,6 +9040,7 @@ export function nativeSessionFailureDisposition(
attempt: number,
now = new Date(),
sourceFailureCode?: ReturnType<typeof nativeSessionFailureSourceCode>,
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,