Public: anyone can read this; the crew can change it.

A cancelled run ends its whole process tree: a test starts a run whose child spawns a grandchild, cancels it, and finds neither alive #14284

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/14275-a-cancelled-run-ends-its-whole-process-t → main 1 commit fork

  • Merged. scout/14275-a-cancelled-run-ends-its-whole-process-t was merged into main as 9853295.

Review

Sign in to review this change.
6 files changed +23 −11
src/apps/process.ts +1 −1
@@ -445,7 +445,7 @@ export async function runStep(
445445 let graceTimer: ReturnType<typeof setTimeout> | undefined;
446446 const onAbort = (): void => {
447447 why = `${name} cancelled`;
448 options.log(endedLine(liveTree(proc.pid).length));
448 options.log(endedLine(liveTree(proc.pid)));
449449 if (cell === undefined) signalGroup(proc.pid, "SIGTERM");
450450 else signalTree(proc.pid, "SIGTERM");
451451 graceTimer = setTimeout(() => {
src/crew/claude.ts +1 −1
@@ -426,7 +426,7 @@ async function runClaudeRaw(input: ClaudeInput): Promise<ClaudeOutcome> {
426426 }, input.timeoutMs);
427427 const onAbort = (): void => {
428428 why = "cancelled";
429 input.log(endedLine(liveTree(proc.pid).length));
429 input.log(endedLine(liveTree(proc.pid)));
430430 stopChild();
431431 };
432432 if (input.signal.aborted) onAbort();
src/runs/ended.ts +10 −4
@@ -82,8 +82,14 @@ export function treeOf(rows: readonly ProcRow[], leader: number): number[] {
8282 /** The live processes a cancel of `leader` is about to end, read now. */
8383 export const liveTree = (leader: number): number[] => treeOf(readProcs(), leader);
8484
85 /** The one log line a cancel writes. */
86 export function endedLine(count: number): string {
87 const n = Number.isInteger(count) && count > 0 ? count : 0;
88 return `cancel ended ${n} ${n === 1 ? "process" : "processes"}`;
85 /**
86 * The one log line a cancel writes: how many processes it ended, then
87 * which (#14275), so the run's record names every pid the stop reached.
88 * Only positive integers are named; anything else is not a pid.
89 */
90 export function endedLine(pids: readonly number[]): string {
91 const named = pids.filter((pid) => Number.isInteger(pid) && pid > 0);
92 const n = named.length;
93 const noun = n === 1 ? "process" : "processes";
94 return n === 0 ? `cancel ended 0 processes` : `cancel ended ${n} ${noun}: ${named.join(" ")}`;
8995 }
test/crew-cancel-group.test.ts +3
@@ -121,6 +121,9 @@ sleep 300
121121 const ended = lines.filter((l) => l.startsWith("cancel ended "));
122122 expect(ended).toHaveLength(1);
123123 expect(Number(/^cancel ended (\d+) process/.exec(ended[0]!)?.[1])).toBeGreaterThanOrEqual(pids.length);
124 // And names each of them (#14275).
125 const named = (ended[0]!.split(": ")[1] ?? "").split(" ").map(Number);
126 for (const pid of pids) expect(named).toContain(pid);
124127 // Reaped too, not left as zombies: no pid answers signal 0.
125128 const deadline = Date.now() + 2_000;
126129 const answers = (): number[] =>
test/run-cancel-ended.test.ts +5 −5
@@ -38,11 +38,11 @@ describe("parseStat", () => {
3838 });
3939
4040 describe("endedLine", () => {
41 test("is one line with the count", () => {
42 expect(endedLine(1)).toBe("cancel ended 1 process");
43 expect(endedLine(3)).toBe("cancel ended 3 processes");
44 expect(endedLine(0)).toBe("cancel ended 0 processes");
45 expect(endedLine(Number.NaN)).toBe("cancel ended 0 processes");
41 test("is one line with the count and the pids it ended", () => {
42 expect(endedLine([41])).toBe("cancel ended 1 process: 41");
43 expect(endedLine([41, 42, 43])).toBe("cancel ended 3 processes: 41 42 43");
44 expect(endedLine([])).toBe("cancel ended 0 processes");
45 expect(endedLine([Number.NaN, -1, 1.5])).toBe("cancel ended 0 processes");
4646 });
4747 });
4848
test/run-cancel-tree.test.ts +3
@@ -167,6 +167,9 @@ describe.skipIf(process.platform !== "linux")("a cancelled check", () => {
167167 const ended = readRunLog(dataDir, run.id).lines.filter((l) => l.startsWith("cancel ended "));
168168 expect(ended).toHaveLength(1);
169169 expect(Number(/^cancel ended (\d+) process/.exec(ended[0]!)?.[1])).toBeGreaterThanOrEqual(pids.length);
170 // And it names them: the command, its child and the grandchild (#14275).
171 const named = (ended[0]!.split(": ")[1] ?? "").split(" ").map(Number);
172 for (const pid of pids) expect(named).toContain(pid);
170173 // And it ends with one line saying it was cancelled, and by whom (#11229).
171174 const lines = readRunLog(dataDir, run.id).lines;
172175 expect(lines.filter((l) => l === "cancelled by alice")).toHaveLength(1);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs