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

A cancelled run ends every process it started, grandchildren included, and a test proves it #10829

opened this

Merged 23d 19h ago, live in production

A cancel now writes one line to the run's log with the number of processes it ended, for example cancel ended 4 processes.

Notes

opened this

A cancel now writes one line to the run's log with the number of processes it ended, for example cancel ended 4 processes. The other two items in the issue were already done on main, so this pull adds only the log line:

  • Crew runs: test/crew-cancel-group.test.ts, from c95cc7f08 (#10704), spawns an agent that forks a child, which forks a grandchild. It cancels and checks that none survive.
  • Checks: test/run-cancel-tree.test.ts, from 727b4c0fd (#10783), does the same for a check cancelled through cancelRepoRun.

No leak turned up, so there was nothing to fix.

Change

  • src/runs/ended.ts (new) reads /proc and counts what a cancel will reach: the leader, every live member of its process group, and every live process below it. That includes a grandchild that left the group with setsid. Processes that have already exited but not been cleaned up yet (zombies) are left out.
  • The count is taken just before the signal is sent, so it is what the cancel reached at that moment.
  • Both cancel paths write the line through the run's own log: runStep in src/apps/process.ts for checks, install and test steps, and runClaude in src/crew/claude.ts for agent runs.

Tests

  • Both existing cancel tests now also assert that exactly one such line is logged, with a count of at least the processes they started.
  • test/run-cancel-ended.test.ts (new) covers the counting on a synthetic process table, the line's wording, and a real child and grandchild. All of these run without a unix socket.

Left out

  • When a check is cancelled during the deploy phase, the line counts only the test step, not the app process started next to it. That process is still stopped by its own killTree.
  • Counts are only available on Linux. Elsewhere the line says 0.

Checks run here: bun scripts/gate.ts and bun x tsc --noEmit are clean, and the three cancel tests plus steps-stop-tree, session-reap, apps-stop-tree and claude-context pass. scripts/fast.ts named 1,895 test files (about 161 minutes), so I ran these related suites instead and left the full suite to the forge's check. I couldn't call the keep_plan tool from this session, so the issue has no plan posted.

To try it: bun test test/run-cancel-ended.test.ts test/crew-cancel-group.test.ts test/run-cancel-tree.test.ts. Or cancel a running check on a preview and read the last lines of its log.

🤖 Generated with Claude Code

Closes #10826

commented

A cancel now writes one line to the run's log with the number of processes it ended, for example cancel ended 4 processes. The other two items in the issue were already done on main, so this pull adds only the log line:

  • Crew runs: test/crew-cancel-group.test.ts, from c95cc7f08 (#10704), spawns an agent that forks a child, which forks a grandchild. It cancels and checks that none survive.
  • Checks: test/run-cancel-tree.test.ts, from 727b4c0fd (#10783), does the same for a check cancelled through cancelRepoRun.

No leak turned up, so there was nothing to fix.

Change

  • src/runs/ended.ts (new) reads /proc and counts what a cancel will reach: the leader, every live member of its process group, and every live process below it. That includes a grandchild that left the group with setsid. Processes that have already exited but not been cleaned up yet (zombies) are left out.
  • The count is taken just before the signal is sent, so it is what the cancel reached at that moment.
  • Both cancel paths write the line through the run's own log: runStep in src/apps/process.ts for checks, install and test steps, and runClaude in src/crew/claude.ts for agent runs.

Tests

  • Both existing cancel tests now also assert that exactly one such line is logged, with a count of at least the processes they started.
  • test/run-cancel-ended.test.ts (new) covers the counting on a synthetic process table, the line's wording, and a real child and grandchild. All of these run without a unix socket.

Left out

  • When a check is cancelled during the deploy phase, the line counts only the test step, not the app process started next to it. That process is still stopped by its own killTree.
  • Counts are only available on Linux. Elsewhere the line says 0.

Checks run here: bun scripts/gate.ts and bun x tsc --noEmit are clean, and the three cancel tests plus steps-stop-tree, session-reap, apps-stop-tree and claude-context pass. scripts/fast.ts named 1,895 test files (about 161 minutes), so I ran these related suites instead and left the full suite to the forge's check. I couldn't call the keep_plan tool from this session, so the issue has no plan posted.

To try it: bun test test/run-cancel-ended.test.ts test/crew-cancel-group.test.ts test/run-cancel-tree.test.ts. Or cancel a running check on a preview and read the last lines of its log.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs