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 <noreply@paperclip.ing>
This commit is contained in:
Devin FoleyandPaperclip committed 2026-11-20 23:12:08 -08:00
1 parent 3f7cd590aa
commit d3d43291e4
2 files changed
+9 -6

No files matched your search

@@ -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<string, unknown> | 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));
}
@@ -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 &&