Commit 9700da8
fix(F6): bash timeout kills whole process group, not just direct child (#81)
Track F-HIGH #6 from ROADMAP.md.
## Problem
`bash.rs:70-87` used `tokio::time::timeout(d, cmd.output())`. On
timeout the tokio future is dropped, taking the `Child` with it
— which kills only the immediate `bash` process. Bash's
subprocesses (npm install, cargo build, python test runner)
stayed alive as orphans reparented to PID 1.
For a `--sandbox` build the bwrap wrapper's `--die-with-parent`
mostly contained this, but unsandboxed builds leaked CPU + RAM
on every timed-out long-running command.
## Fix
New `run_with_timeout(cmd, secs)` helper replaces the inline
timeout logic. Key changes:
1. **Spawn in a new process group on Unix** via tokio's
`Command::process_group(0)`. The child becomes leader of a
new group with `pgid = pid`.
2. **`kill_on_drop(true)`** so the immediate child gets a
signal when the future drops on any platform.
3. **`Stdio::piped()`** for stdin/stdout/stderr — explicit
because manual `spawn` (vs `.output()`) defaults to inherit
and would route the agent's output to its own terminal,
returning empty buffers.
4. **On timeout, `libc::kill(-pid, SIGKILL)`** — negative pid
targets the process group, reaching every descendant. The
kill is done via `libc` (already a transitive dep, now
declared in `Cargo.toml` under `[target.'cfg(unix)']`).
5. On Windows we fall back to kill_on_drop only — proper job-
object cleanup would require additional deps; the direct-
child kill is the same behavior as before on that platform.
Matches pi's `bash.ts:76-81` `detached: true` + `killProcessTree(pid)`
shape.
## Tests
Two new Unix-only (`#[cfg(unix)]`) tests in
`agent::tools::bash::tests`:
- `run_with_timeout_kills_orphaned_child`: runs `sleep 5` with
a 1s timeout; asserts the call returns within 3s with a
timeout error. The fast return proves the process was
actually killed (otherwise we'd race to read output that
doesn't exist until second 5).
- `run_with_timeout_returns_output_on_success`: runs `echo hi`
with a 5s timeout; asserts stdout reaches us as "hi" —
guards against the Stdio::piped() fix accidentally breaking
the happy path.
660 pass (was 658, +2 Unix-only). All build profiles clean.
Co-authored-by: Yogthos <yogthos@gmail.com>1 parent c151abd commit 9700da8
3 files changed
Lines changed: 137 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
12 | 73 | | |
13 | 74 | | |
14 | 75 | | |
| |||
67 | 128 | | |
68 | 129 | | |
69 | 130 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
88 | 144 | | |
89 | 145 | | |
90 | 146 | | |
| |||
165 | 221 | | |
166 | 222 | | |
167 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
0 commit comments