Skip to content

Studio: on Windows a run's deadline kills its whole process tree, through a Job Object (#940) - #1017

Merged
danielrispler merged 4 commits into
mainfrom
issue-940-studio-windows-the-process
Dec 1, 2026
Merged

danielrispler merged 4 commits into
mainfrom
issue-940-studio-windows-the-process

Conversation

@danielrispler

@danielrispler danielrispler commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Closes #940 (spec #936, "The process runner").

Summary

On Windows a run's deadline now kills the command's whole process tree through a Job Object, as a process group does on Unix. The public surface is unchanged.

 run(command, input, deadline, given_up)
-  child = in_own_group(command).spawn()        # Windows: no group
+  child = Tree::start(command)                 # Unix: process group · Windows: process-wrap JobObject
   loop child.try_wait()                        # Windows: the direct child, never the job
-  on deadline / given_up / try_wait error / pipes held past deadline: kill_tree(child)   # Windows: the command only
+  on deadline / given_up / try_wait error / pipes held past deadline: child.kill()       # Windows: terminates the job
   after a clean exit: leftovers are left alone   # no KillOnDrop, so closing the job kills nothing
workbench/src/run.rs     Tree (cfg arms) replaces Child + kill_tree; the interim Windows stubs go
workbench/Cargo.toml     process-wrap 11 (std, job-object), Windows only
workbench/tests/run.rs   the runner rows use the Rust fake on every platform; their cfg(unix) gates are lifted
test-support/            the fake can start a helper (Helper, helper_pid, running); windows-sys on Windows

test-support isn't in the ticket's Touches line. The Windows rows need it: the sh helper can't run there, and the fake needed a helper it can start and a cross-platform running(pid).

Test changes:

  • Renamed a_deadline_kills_the_whole_process_group to a_deadline_kills_the_whole_process_tree.
  • The deadline, helper-hold and given-up-with-helper rows now also assert that the helper is gone.
  • New row: a_helper_left_behind_by_a_clean_exit_is_left_alone.
  • The silent-exit row expects exit code: 3 on Windows.
  • No tests were removed or merged.

Evidence

Windows, windows.yml on this branch:

  • Before (commit 083e6c1: tests only, runner unchanged), run 46611027828:
    • x64: a_deadline_kills_the_whole_process_tree failed with "the helper 8784 outlived the deadline".
    • arm64: the same row, plus a_helper_that_outlives_the_command_cannot_hold_the_run_past_its_deadline, failed with "the helper … outlived the deadline".
    • Nextest stops after the first failures, so the other tree rows didn't run there. Their break checks below show them red on macOS.
  • After (the runner on a Job Object): run 46611999918: every row passes on x64 and arm64. The review-fix commit 73d4280 runs on Windows again with this PR.

Break checks on macOS (each behaviour broken for a moment, then restored):

  • Runner kills only the command: the deadline, helper-hold and given-up-with-helper rows fail with "the helper N outlived …".
  • Runner kills the tree after a clean exit: a_helper_left_behind_by_a_clean_exit_is_left_alone fails. The first version of this row passed when it should have failed. On Unix, kill(pid, 0) still counts a killed orphan as running until launchd reaps it. The row now asserts that the helper does not go within the same 2 s window that goes watches.
  • No kill when the run is given up: a_run_given_up_while_a_helper_holds_its_output_ends_before_its_deadline fails on its goes assertion.

npm run check and npm run check:windows pass.

On f249909, macos rust and snap (1/2) were cancelled at 15 minutes with no step run and no log, so they likely never got a runner. Each was rerun once (gh run rerun --failed), and both passed.

Correctness pass

/code-review high (standards, plus spec and correctness):

  • Fixed: docs/studio/development.md still said Windows kills only the command "until Studio: Windows — the process runner on Job Objects (#936) #940".
  • Fixed: the given-up-with-helper row gave up after 300 ms even if the helper hadn't started yet. On a slow Windows runner it would panic with "started no helper". It now gives up only once the helper's pid is written.
  • Verified, no change:
    • inner_mut() reaches std's Child.
    • Terminating the job still works after the leader is reaped.
    • process-wrap starts the command suspended, so nothing can run before it joins the job.
    • Dropping the wrapper kills nothing (no KillOnDrop).
    • The command survives a failed spawn.
  • Fixed after CI: a flake risk in the left-alone row. I first rejected this finding (the helper's 5 s starts before the command exits, so I reckoned on about 3 s of margin). Then CI's macos rust failed on that row, in run 46613136641: it took 5.067 s, so the helper ran out its own 5 s while the row was still watching. The helper now waits LONG (20 s). The break check still turns it red.
  • Rejected: duplicated doc comments on the cfg arms, and folding the older timed-out rows into one table. These are judgement calls on code the ticket didn't ask to restructure.

Outside review

skipped: no risk match

Merge Danger

Door: two-way. It's a runner arm and its tests, and reverting restores the interim Windows arm.

Blast Radius: Windows-only. On Unix only the type around the child changed, and the kill and waits are the same calls.

🤖 Generated with Claude Code

danielrispler and others added 4 commits December 1, 2026 10:52
…e helper (#940)

The rows fail on Windows until the runner kills the whole tree there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ough a Job Object (#940)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…c tells the Job Object (#940)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A 5 s helper ran out on CI's macOS while the run was still ending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danielrispler
danielrispler merged commit 99dfe5a into main Dec 1, 2026
22 of 24 checks passed
@danielrispler
danielrispler deleted the issue-940-studio-windows-the-process branch December 1, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Studio: Windows — the process runner on Job Objects (#936)

1 participant