diff --git a/server/src/services/cancelled-native-startup.ts b/server/src/services/cancelled-native-startup.ts index d4775d8917d..9358bc973c9 100644 --- a/server/src/services/cancelled-native-startup.ts +++ b/server/src/services/cancelled-native-startup.ts @@ -48,8 +48,7 @@ export async function isFailedNativePreparationRetryAncestor(db: Db, run: Run, c async function failedNativePreparation(db: Db, run: Run, coordinator: Coordinator | undefined, historicalRetryAncestor: boolean) { if (!historicalRetryAncestor && !coordinator && await isInterruptedNativePreparation(db, run)) return true; const recovery = run.resultJson?.executionRecovery as Record | undefined; - const historicalEvidence = historicalRetryAncestor || run.errorCode === "adapter_failed"; - const preparationFailure = run.errorCode === "setup_failed" || run.errorCode === "adapter_failed"; + const preparationFailure = run.errorCode === "setup_failed" || historicalRetryAncestor && run.errorCode === "adapter_failed"; if (run.status !== "failed" || !run.finishedAt || run.runtimeMode !== "legacy" || run.runtimeModeResolvedAt || !preparationFailure || run.executionStage !== "preparing" || claimedAdapterType(run) !== "paperclip_runner" || coordinator @@ -65,11 +64,11 @@ async function failedNativePreparation(db: Db, run: Run, coordinator: Coordinato eq(nativeRunResults.companyId, run.companyId), eq(nativeRunResults.runId, run.id), )).limit(1); if (result || await nativeStartupHasExecutionEvidence(db, run)) return false; - if (!leases.length && run.runnerProfileJson?.remoteWorkspace == null) return !historicalEvidence; + if (!leases.length && run.runnerProfileJson?.remoteWorkspace == null) return !historicalRetryAncestor; const issueId = run.nativeIssueId ?? run.issueId ?? run.contextSnapshot?.issueId; return typeof issueId === "string" && leases.length > 0 && leases.every(lease => lease.issueId === issueId && lease.metadata?.pendingCleanupInFlight !== true && hasRemoteTerminationReceipt(lease)) - && await hasSettledFailedPreparationEvidence(db, run, historicalEvidence) + && await hasSettledFailedPreparationEvidence(db, run, historicalRetryAncestor) && (!holdsPreparedFiles(run) || await hasVerifiedWorkspaceRepair(db, run)); } diff --git a/server/src/services/explicit-native-continuation.ts b/server/src/services/explicit-native-continuation.ts index dd5ae58a64f..e5be7ec17a1 100644 --- a/server/src/services/explicit-native-continuation.ts +++ b/server/src/services/explicit-native-continuation.ts @@ -353,7 +353,9 @@ export async function admitExplicitNativeContinuation(input: { )).for("update"); if (!source || (source.nativeIssueId ?? source.issueId ?? source.contextSnapshot?.issueId) !== issueId || adapterExecutionControls.has(source.id) || - !(await isFailedNativePreparation(db, source, coordinator) || await isPreDispatchExecutionWaitVerified(db, source))) return refused("previous_execution_unverified", PREVIOUS_EXECUTION_UNVERIFIED); + !(await isFailedNativePreparation(db, source, coordinator) + || source.errorCode === "adapter_failed" && await isFailedNativePreparationRetryAncestor(db, source, coordinator) + || await isPreDispatchExecutionWaitVerified(db, source))) return refused("previous_execution_unverified", PREVIOUS_EXECUTION_UNVERIFIED); sourceChecks.push({ cause: "legacy_execution_requires_reconciliation", evidence: { runId: source.id } }); } if (!sourceChecks.length && !nativeQueuedSend) return null; @@ -394,7 +396,9 @@ export async function admitExplicitNativeContinuation(input: { // A user's message written after their Stop request is new direction even // when the stopped native run settled later. const stoppedAt = userStopBoundaryAt(run)!; - const failedPreparation = await isFailedNativePreparation(db, run, coordinator); + const failedPreparation = await isFailedNativePreparation(db, run, coordinator) + || taskRetry?.sourceRunId === run.id && run.errorCode === "adapter_failed" + && await isFailedNativePreparationRetryAncestor(db, run, coordinator); const unusedAdmission = run.status === "cancelled" && !run.startedAt && run.errorCode === "execution_reconciliation_required" && !run.processPid && !run.processGroupId && !run.nativeSessionId &&