mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 15:52:36 +01:00
fix(runner): re-prepare OpenCode launch inputs for a replaced provider session (#23050)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Native OpenCode agents run in remote sandboxes. The controller gives
each Runner launch the provider-pack paths of Node, the OpenCode proxy
and the OpenCode executable
> - When exact resume of a provider session fails, Paperclip archives
the old session and opens a replacement session on the same backend
> - The archive drops the restored provider artifacts and their launch
paths. The replacement transport reads its launch inputs when it is
built, before its Runner is staged
> - A session restored from saved artifacts never selects a pack root,
so the replacement had no OpenCode executable. The run failed as
`runner_remote_provider_artifact_incompatible` and the task stayed
blocked. Other replacements launched from the pack root while the saved
receipt named the artifact root, and the next continuation's Runner
rejected that launch
> - This pull request stages the launch inputs again before the
replacement opens, reports a missing launch input as a retryable
controller gap, and continues tasks that older releases blocked this way
> - The benefit is that a GitHub review (or any OpenCode task) that hits
a resume failure continues by itself instead of needing a Retry
## Linked Issues or Issue Description
Refs #22981 (it scoped staged provider assets per provider; it did not
cause or fix this failure)
**What happened?**
An OpenCode review run on a hosted instance failed with
`runner_remote_provider_artifact_incompatible: OpenCode executable is
missing from the provider pack`. The task stayed blocked with no later
run. The run log showed the adopted Runner first refusing `run.attach`
with "OpenCode run.prepare launch does not match the runner-owned
qualified profile". The previous run of the same session had replaced
its provider session after a failed exact resume.
**Expected behavior**
A replaced provider session launches with the same verified OpenCode
inputs as any other launch, and the task continues without a person
pressing Retry.
**Steps to reproduce**
1. Run an OpenCode agent in a remote sandbox with durable harness
storage, so the session restores its provider artifacts.
2. Make exact resume fail, so the backend opens a replacement session.
3. Build the replacement transport. It has no `opencodeCommand`, and the
transport throws "OpenCode executable is missing from the provider
pack".
**Paperclip version or commit**
master at 85ad16b47e
## What Changed
- `native-session-executor.ts`: `openReplacementSession` stages the
remote Runner launch inputs again (`prepareNativeRemoteRunner`) after
the continuity archive and before the replacement session opens. The
replacement now launches from the same verified artifact root that its
saved receipt names.
- `runnerd-codex-transport.ts`: a controller launch that omits
provider-pack inputs (OpenCode executable, proxy, provider Node, ACPX
sidecar, or verified digests) now fails as
`runner_remote_provider_launch_unprepared`. The pack itself was never
judged, so this is not a pack incompatibility.
- `native-session-executor.ts`:
`runner_remote_provider_launch_unprepared` is classified by name and is
not permanent. The run retries with a fresh backend (bounded to three
attempts, 30 s apart), which prepares the inputs again.
- `continuation-cause.ts`, `native-interruption-continuation.ts`: an
active hold left by an older release with cause
`runner_remote_provider_artifact_incompatible` and the exact legacy
"OpenCode executable is missing from the provider pack" error now goes
through the native interruption lane. That lane starts one fresh
continuation, with the existing pacing. Genuine pack incompatibilities
stay held.
Previous-release story (upgrade-safe run state): no persisted shape
changes. A session saved by the previous release with a replacement
launched from the pack root is not resumed in place. The fresh
continuation archives it and launches a new provider session from
verified inputs.
## Verification
- Red/green: `native-session-executor.test.ts` variant
`opencode-continuation-prior-receipt-replacement`. Without the fix, the
replacement transport options have no `opencodeCommand` or
`providerNodeCommand` (the staging failure). With the fix, they name the
artifact root.
- `fresh-continuation-fallback.test.ts`: a task held by the legacy
failure gets exactly one fresh successor. A task held by a real manifest
digest mismatch stays blocked.
- `native-session-executor.test.ts`: the new code is retried in the same
run and exhausts at the third attempt.
- Commands:
- `cd server && npx vitest run
src/services/native-runtime/native-session-executor.test.ts
src/services/fresh-continuation-fallback.test.ts`
- `cd packages/paperclip-runner && npx vitest run
src/live/runnerd-codex-transport.test.ts`
- `npx tsc --noEmit` in `server` and `packages/paperclip-runner`
- Not verified locally: a live remote sandbox replacement. Staging
verification follows the deploy.
## Risks
- A replacement session now stages the remote Runner and provider pack
again. This adds the normal preparation time only on the replacement
path, which already starts a new provider session.
- If the controller keeps omitting launch inputs for another reason, the
run retries at most three times and then blocks as
`native_session_retry_exhausted`. No retry storm is possible.
- The legacy match is exact on the error text, so other
`runner_remote_provider_artifact_incompatible` failures keep their
current behavior.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use (shell,
code search, test 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
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
50633695e7
commit
4ea6fa61d5
8 files changed
+162
-24
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<boolean> {
|
||||
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 });
|
||||
|
||||
@@ -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<string, unknown> | 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<string, unknown>;
|
||||
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(
|
||||
|
||||
@@ -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<typeof nativeSessionFailureSourceCode>
|
||||
>([
|
||||
"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);
|
||||
|
||||
Reference in new issue
Block a user