Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

A hand-off that ends just before a kill reports its exit (#910)

Josephe2eff95784a1
diff --git a/crates/platform/src/process.rs b/crates/platform/src/process.rs
index e312f6f4..548358ee 100644
--- a/crates/platform/src/process.rs
+++ b/crates/platform/src/process.rs
@@ -809,6 +809,13 @@ impl Supervisor {
}
}
if self.kill.load(Ordering::SeqCst) || self.cancel.as_ref().is_some_and(|c| c()) {
+ // A program that exited since the check above ended on its own (a launcher that
+ // handed off, or a run that finished): say how, not that it was stopped.
+ if handed_off.is_none()
+ && let Ok(Some(status)) = self.child.try_wait()
+ {
+ return Stop::Exited(status);
+ }
return handed_off.map_or(Stop::Cancelled, Stop::Exited);
}
let elapsed = self.start.elapsed();
@@ -1276,8 +1283,23 @@ mod launch_tests {
fn a_launcher_that_hands_off_keeps_its_group_until_stopped() {
// Plain: a clean exit ends the run.
assert!(exits_with(0).run().unwrap().success);
- // Handing off: the launcher's clean exit doesn't, so the browser it started lives on.
- let mut p = exits_with(0).hands_off().spawn().unwrap();
+ // Handing off: the launcher's clean exit doesn't, so the browser it started lives on. The
+ // launcher leaves a mark as its last step and the kill waits for it: on a busy machine
+ // `cmd` could still be starting when a fixed 500 ms was up, and a launcher stopped before
+ // it handed off is a cancelled run, not a clean one.
+ let dir = tempfile::tempdir().unwrap();
+ let mark = dir.path().join("handed-off");
+ let launcher = if cfg!(windows) {
+ Process::new("cmd").args(["/C", "type nul > handed-off & exit 0"])
+ } else {
+ Process::new("sh").args(["-c", ": > handed-off; exit 0"])
+ };
+ let mut p = launcher.cwd(dir.path()).hands_off().spawn().unwrap();
+ let start = std::time::Instant::now();
+ while !mark.exists() && start.elapsed() < Duration::from_secs(20) {
+ std::thread::sleep(Duration::from_millis(20));
+ }
+ assert!(mark.exists(), "the launcher never ran");
assert!(p.wait_timeout(Duration::from_millis(500)).is_none(), "a clean hand-off ended the run");
assert!(p.kill_and_wait(Duration::from_secs(5)));
assert!(p.wait().unwrap().success);
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index f60cf3db..f11146b6 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -173,10 +173,16 @@ only when it's green and a maintainer has fully reviewed it, code as well as wor
- [ ] **decision** Replies don't reach people who file through the ticket relay (each such ticket
says so), yet the bot asks them for details. About half the open issues came that way. Get
replies back to them, or stop asking
-- [ ] `which::tests::usual_windows_dirs_come_after_path` (platform) fails on a Windows machine
- whose environment adds a folder (10 found, 9 expected, "nothing twice"), on `main` too; and
- `capture::console_tests::reads_what_the_program_drew_and_stops_at_the_deadline` failed once
- with the whole platform suite running and passes alone. Find what each depends on
+- [x] `which::tests::usual_windows_dirs_come_after_path` (platform) failed on Windows (10 found, 9
+ expected, "nothing twice"): it didn't count Antigravity's second folder, fixed by #770
+- [ ] `capture::console_tests::reads_what_the_program_drew_and_stops_at_the_deadline` failed once
+ with the whole platform suite running and passes alone (passed 3 whole-suite runs on Windows 11
+ on 2026-11-04). Find what it depends on
+- [x] `process::launch_tests::a_launcher_that_hands_off_keeps_its_group_until_stopped` failed on a
+ busy Windows machine: it killed the run 500 ms after the start, and a `cmd` that hadn't exited
+ by then made a cancelled run, not a hand-off. The test now waits for the launcher's mark, and
+ a kill that finds the program already exited reports its exit, not a cancel
+ — claimed: 00xJS, branch test/r5.2-hand-off-race
- [ ] `a_helper_is_judged_by_whether_it_runs` (ai crate) sometimes fails when several crates'
tests run at once and passes alone: it writes a script and runs it straight away, which a
busy machine can refuse while another test's child still holds the file open