From d3d43291e405ab64ae42d2fcbe295677c2b57e03 Mon Sep 17 00:00:00 2001 From: Devin Foley Date: Fri, 20 Nov 2026 18:17:44 -0800 Subject: [PATCH] fix: scope legacy preparation proof to the retry source The shared preparation classifier also runs on older recovery holds. Making it accept historical adapter failures skipped the ancestry checks for those holds. CI exposed eight refusal cases that admitted an unwanted successor. Restore the shared classifier. Accept the existing full historical proof only for the exact adapter_failed source named by the person's Retry. Older holds still pass the original ancestry and current recovery proof checks. The full preparation recovery and saved-work Retry suites pass all 96 tests, including the 39 ancestry controls and the new direct-source cases. Server typecheck also passes. Keep the existing refusal assertions unchanged. Co-Authored-By: Paperclip --- server/src/services/cancelled-native-startup.ts | 7 +++---- server/src/services/explicit-native-continuation.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) 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 &&