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

A cancelled crew run leaves no grandchild process behind, proven with a real tree #14875

Merged opened this

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

Merged

A cancelled crew run that ignores SIGTERM is now killed after the grace and its log says so; before this, the kill happened without a log line.

Notes

shipped production is serving it deploy 15342fb

opened this

A cancelled crew run that ignores SIGTERM is now killed after the grace and its log says so; before this, the kill happened without a log line. Most of #14852 already held on main: a cancelled check (runStep) ends its whole tree within 2 s and logs the follow-up kill, and a crew run (runClaude) already took its grandchild down with it (test/crew-cancel-group.test.ts, test/crew-cancel-shell.test.ts).

The fix (src/crew/claude.ts): when the grace runs out and the agent is still running, the new killGroup writes graceKillLine() and then SIGKILLs the group, the same line a cancelled check writes. The kill only ever goes to the run's own group (-proc.pid), as before. It is only logged when the run was cancelled: the same path also handles a timeout, and a cancel: line would be wrong there.

The test (test/run-cancel-tree.test.ts) gains a "a cancelled crew run" section, with a stand-in agent that forks a shell that forks a sleep:

  • If the tree honours SIGTERM, all three processes are gone within 2 s of the cancel, the outcome is cancelled, and no kill line is logged.
  • If the tree ignores SIGTERM, all three are still alive a third of the way into the grace, gone within 2 s of the cancel, and the kill line is logged exactly once.

The second test fails without the fix. Neither test needs a socket, so none is skipped in socket-less mode; both are skipped off Linux only, like the rest of the file.

Allow-list (test/timers-named.test.ts): the entry for that timer matches its callback's first words, so it now matches … === null) killGroup.

Checks run: scripts/gate.ts --fix and tsc --noEmit are clean. scripts/fast.ts named 234 files (about 20 minutes, over its 5-minute budget), so I ran the subset that covers the change, all green: the cancel suites, claude-context, timers-named, unused-exports, no-polling and test-honesty. The forge's full check covers the rest.

I did not touch the timeout path's behaviour. The keep_plan and estimate tools were not available in this run, so no plan or estimate was recorded on the issue.

🤖 Generated with Claude Code

Closes #14852

commented

A cancelled crew run that ignores SIGTERM is now killed after the grace and its log says so; before this, the kill happened without a log line. Most of #14852 already held on main: a cancelled check (runStep) ends its whole tree within 2 s and logs the follow-up kill, and a crew run (runClaude) already took its grandchild down with it (test/crew-cancel-group.test.ts, test/crew-cancel-shell.test.ts).

The fix (src/crew/claude.ts): when the grace runs out and the agent is still running, the new killGroup writes graceKillLine() and then SIGKILLs the group, the same line a cancelled check writes. The kill only ever goes to the run's own group (-proc.pid), as before. It is only logged when the run was cancelled: the same path also handles a timeout, and a cancel: line would be wrong there.

The test (test/run-cancel-tree.test.ts) gains a "a cancelled crew run" section, with a stand-in agent that forks a shell that forks a sleep:

  • If the tree honours SIGTERM, all three processes are gone within 2 s of the cancel, the outcome is cancelled, and no kill line is logged.
  • If the tree ignores SIGTERM, all three are still alive a third of the way into the grace, gone within 2 s of the cancel, and the kill line is logged exactly once.

The second test fails without the fix. Neither test needs a socket, so none is skipped in socket-less mode; both are skipped off Linux only, like the rest of the file.

Allow-list (test/timers-named.test.ts): the entry for that timer matches its callback's first words, so it now matches … === null) killGroup.

Checks run: scripts/gate.ts --fix and tsc --noEmit are clean. scripts/fast.ts named 234 files (about 20 minutes, over its 5-minute budget), so I ran the subset that covers the change, all green: the cancel suites, claude-context, timers-named, unused-exports, no-polling and test-honesty. The forge's full check covers the rest.

I did not touch the timeout path's behaviour. The keep_plan and estimate tools were not available in this run, so no plan or estimate was recorded on the issue.

🤖 Generated with Claude Code

commented

When a crew run is cancelled and ignores SIGTERM, it is now killed once CANCEL_GRACE_MS runs out, along with its child and grandchild. The run log says it was killed. A run that does honour SIGTERM ends with its whole process tree within 2 s and nothing is killed.

Fix for the failed check: the gate rule "a test does not wait on a real timer" refused test/run-cancel-tree.test.ts:310. That line now ends with a // real-timer: note saying why, and so does the same sleep at line 233. Those tests run real processes and check that they are still alive a third of the way into the grace, so a fake clock cannot replace that wait. No test assertion changed.

Left alone: the gate also prints that agentPids in test/run-cancel-tree.test.ts matches pidsOf in test/crew-cancel-shell.test.ts. That line is a hint, not a failure. The two are four lines each and read pid files through each file's own polling helper, so I kept them separate rather than add a shared test helper inside this fix.

Checks run: bun scripts/gate.ts --fix and bun x tsc --noEmit pass. bun test test/run-cancel-tree.test.ts test/crew-cancel-shell.test.ts passes: 11 tests, none failing.

To try it: run bun test test/run-cancel-tree.test.ts on Linux.

🤖 Generated with Claude Code

Approved

Small, correct, no UI surface (no page or terminal change, so no both-doors or README concern). killGroup logs graceKillLine only for a cancel, not a timeout, and signals only the run own group. The new tests use a real three-process tree. The deaf-agent test fails without the fix. The honouring-agent test asserts no kill line. The timers-named allow-list entry is updated to match. Two things I would do next: (1) fold agentPids and pidsOf from crew-cancel-shell.test.ts into one shared test helper, which the gate already hints at; (2) assert the timeout path logs no cancel line, so the reason-gating in killGroup is pinned by a test.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs