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
scoutcrew
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( |
| 445 | 445 |
let graceTimer: ReturnType<typeof setTimeout> | undefined; |
| 446 | 446 |
const onAbort = (): void => { |
| 447 | 447 |
why = `${name} cancelled`; |
| 448 | |
options.log(endedLine(liveTree(proc.pid).length)); |
| 448 |
options.log(endedLine(liveTree(proc.pid))); |
| 449 | 449 |
if (cell === undefined) signalGroup(proc.pid, "SIGTERM"); |
| 450 | 450 |
else signalTree(proc.pid, "SIGTERM"); |
| 451 | 451 |
graceTimer = setTimeout(() => { |
src/crew/claude.ts
+1
−1
|
|
@@ -426,7 +426,7 @@ async function runClaudeRaw(input: ClaudeInput): Promise<ClaudeOutcome> { |
| 426 | 426 |
}, input.timeoutMs); |
| 427 | 427 |
const onAbort = (): void => { |
| 428 | 428 |
why = "cancelled"; |
| 429 | |
input.log(endedLine(liveTree(proc.pid).length)); |
| 429 |
input.log(endedLine(liveTree(proc.pid))); |
| 430 | 430 |
stopChild(); |
| 431 | 431 |
}; |
| 432 | 432 |
if (input.signal.aborted) onAbort(); |
src/runs/ended.ts
+10
−4
|
|
@@ -82,8 +82,14 @@ export function treeOf(rows: readonly ProcRow[], leader: number): number[] { |
| 82 | 82 |
|
| 83 | 83 |
export const liveTree = (leader: number): number[] => treeOf(readProcs(), leader); |
| 84 | 84 |
|
| 85 | |
|
| 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 |
|
| 87 |
|
| 88 |
|
| 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(" ")}`; |
| 89 | 95 |
} |
test/crew-cancel-group.test.ts
+3
|
|
@@ -121,6 +121,9 @@ sleep 300 |
| 121 | 121 |
const ended = lines.filter((l) => l.startsWith("cancel ended ")); |
| 122 | 122 |
expect(ended).toHaveLength(1); |
| 123 | 123 |
expect(Number(/^cancel ended (\d+) process/.exec(ended[0]!)?.[1])).toBeGreaterThanOrEqual(pids.length); |
| 124 |
|
| 125 |
const named = (ended[0]!.split(": ")[1] ?? "").split(" ").map(Number); |
| 126 |
for (const pid of pids) expect(named).toContain(pid); |
| 124 | 127 |
|
| 125 | 128 |
const deadline = Date.now() + 2_000; |
| 126 | 129 |
const answers = (): number[] => |
test/run-cancel-ended.test.ts
+5
−5
|
|
@@ -38,11 +38,11 @@ describe("parseStat", () => { |
| 38 | 38 |
}); |
| 39 | 39 |
|
| 40 | 40 |
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"); |
| 46 | 46 |
}); |
| 47 | 47 |
}); |
| 48 | 48 |
|
test/run-cancel-tree.test.ts
+3
|
|
@@ -167,6 +167,9 @@ describe.skipIf(process.platform !== "linux")("a cancelled check", () => { |
| 167 | 167 |
const ended = readRunLog(dataDir, run.id).lines.filter((l) => l.startsWith("cancel ended ")); |
| 168 | 168 |
expect(ended).toHaveLength(1); |
| 169 | 169 |
expect(Number(/^cancel ended (\d+) process/.exec(ended[0]!)?.[1])).toBeGreaterThanOrEqual(pids.length); |
| 170 |
|
| 171 |
const named = (ended[0]!.split(": ")[1] ?? "").split(" ").map(Number); |
| 172 |
for (const pid of pids) expect(named).toContain(pid); |
| 170 | 173 |
|
| 171 | 174 |
const lines = readRunLog(dataDir, run.id).lines; |
| 172 | 175 |
expect(lines.filter((l) => l === "cancelled by alice")).toHaveLength(1); |