Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/code/src/lib/agent/run-harness-finalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,12 @@ async function reportPipelineHalt(
reason: string,
options: { countAttempt?: boolean } = {},
): Promise<void> {
// The shutdown handler already reported the interruption; a second comment
// and a retry-gate entry would contradict it.
// The shutdown handler already reported this; a second report would contradict it.
if (isShuttingDown()) {
console.log(`⚠️ Pipeline halted during shutdown: ${reason}`);
return;
}
if (runContext.activeTaskContext) runContext.activeTaskContext.deliveryHalt = reason; // survives a failed file write
const ctx = state.context;
const { taskKey, tracker, task } = ctx;
const report = `Pipeline stopped: ${reason}\n\n${state.output}`;
Expand Down
6 changes: 6 additions & 0 deletions packages/code/src/lib/cli/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export interface ActiveTaskContext {
* with.
*/
noopDeliveryReason?: string;
/**
* Set when the delivery pipeline halted after the agent finished (verify,
* repair, or a plugin step): the halt reason. Kept in memory so the run
* escalates even when the incomplete-summary file cannot be written.
*/
deliveryHalt?: string;
}

/** A PR that was requested after a successful push but could not be created. */
Expand Down
11 changes: 9 additions & 2 deletions packages/code/src/lib/task/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ export async function settleImplementationRun(input: {
outcome: ReturnType<typeof readImplementationReport>["outcome"];
}): Promise<void> {
const { tracker, task, workflowKey, taskDir, outcome } = input;
const implementationIncomplete = input.incomplete;
// The in-memory halt flag backs up the incomplete-summary file, which may
// have failed to write.
const implementationIncomplete =
input.incomplete || runContext.activeTaskContext?.deliveryHalt !== undefined;
// The agent's own outcome marker decides between success and escalation
// for a clean run, and a requested PR that failed after the push turns it
// into a failure. Resolve it before any tracker transition so a blocked or
Expand All @@ -323,7 +326,11 @@ export async function settleImplementationRun(input: {
: { status: "succeeded", reason: noopDeliveryReason },
runContext.activeTaskContext?.prDeliveryFailure?.message,
);
if (isMarkdownTaskTracker(tracker) && disposition.status === "succeeded") {
if (
isMarkdownTaskTracker(tracker) &&
disposition.status === "succeeded" &&
!implementationIncomplete
) {
await tracker.markDoneIfSuccessful(workflowKey, taskDir);
}
// A closed stacked base escalates even without the incomplete summary (skipped during shutdown).
Expand Down
77 changes: 76 additions & 1 deletion packages/code/tests/pipeline-pr-delivery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import { runContext } from "../src/lib/cli/context";
import type { PrDeliveryFailure } from "../src/lib/cli/context";
import { RUN_ORIGIN_ENV } from "../src/lib/observability/analytics";
import { getRetryState, recordIncompleteAttempt } from "../src/lib/state/retry-state";
import { RunStore, beginRun, getActiveRunContext } from "../src/lib/state/run-recorder";
import {
RunStore,
beginRun,
getActiveRunContext,
noteRunFailure,
} from "../src/lib/state/run-recorder";
import { WorkerState } from "../src/lib/state/worker-state";
import { prDeliveryFailuresKey } from "../src/lib/task/actioned-without-pr";
import { settleImplementationRun } from "../src/lib/task/pipeline";
Expand Down Expand Up @@ -258,6 +263,76 @@ describe("settleImplementationRun for a stacked run whose base closed", () => {
});
});

describe("settleImplementationRun for a delivery halt", () => {
function startHalted(taskKey: string, deliveryHalt: string | undefined): number {
beginRun({ origin: "task", taskKey });
const runId = getActiveRunContext()!.id;
runContext.activeTaskContext = {
taskKey,
tracker: trackerStub(),
projectKey: "PROJ",
movedToInProgress: true,
...(deliveryHalt === undefined ? {} : { deliveryHalt }),
};
return runId;
}

test("escalates and keeps a markdown task out of Done when the summary file is missing", async () => {
const doneCalls: string[] = [];
const runId = startHalted("PROJ-HALT", "Verification failed twice: ENOSPC");

await settleImplementationRun({
tracker: markdownTrackerStub(doneCalls),
task: task as never,
workflowKey: "PROJ-HALT",
taskDir: workDir,
incomplete: false,
outcome: undefined,
});

const run = readRun(runId);
expect(run?.status).toBe("escalated");
expect(run?.outcomeReason).toBe("implementation incomplete; handed back to a human");
expect(doneCalls).toEqual([]);
});

test("a failure noted at the verify stage still wins over the default class", async () => {
const runId = startHalted("PROJ-HALT2", "Verification failed twice");
noteRunFailure({ outcomeClass: "internal", stage: "verify", cause: "ENOSPC" });

await settleImplementationRun({
tracker: trackerStub(),
task: task as never,
workflowKey: "PROJ-HALT2",
taskDir: workDir,
incomplete: true,
outcome: undefined,
});

const run = readRun(runId);
expect(run?.status).toBe("escalated");
expect(run?.outcomeClass).toBe("internal");
expect(run?.outcomeReason).toBe("verify: ENOSPC");
});

test("without a halt a clean run still succeeds and marks the markdown task Done", async () => {
const doneCalls: string[] = [];
const runId = startHalted("PROJ-OK", undefined);

await settleImplementationRun({
tracker: markdownTrackerStub(doneCalls),
task: task as never,
workflowKey: "PROJ-OK",
taskDir: workDir,
incomplete: false,
outcome: undefined,
});

expect(readRun(runId)?.status).toBe("succeeded");
expect(doneCalls).toEqual(["PROJ-OK"]);
});
});

describe("settleImplementationRun for a no-change run accepted on a noop marker", () => {
test("records a succeeded run whose reason starts with noop:", async () => {
const doneCalls: string[] = [];
Expand Down
Loading