Commit 5977e21
fix(shell): bound command execution with timeout + context cancellation
shell ran cmd.Run() on a plain exec.Command with no timeout and no context,
so a stuck command (network read that never returns, interactive prompt,
infinite loop) wedged the agent forever — and Ctrl-C could not recover
because the loop's drain blocks on the tool goroutine. The sibling
parallel_shell already had a timeout; plain shell, the most-used tool, did
not.
- SetContext ties execution to the agent context (the loop already calls it
on context-aware tools), so Ctrl-C / turn timeout kills the command now.
- exec.CommandContext + a generous 30m backstop timeout bounds genuinely
stuck commands for unattended runs (serve, telegram) with no human to
interrupt. WaitDelay guarantees Run() returns even if the killed process
leaves children holding the pipes.
- Cancellation/timeout surface as clear errors, not opaque "signal: killed".
Tests: a sleeping command now returns promptly via both the timeout and
context-cancellation paths.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent 6a2055c commit 5977e21
2 files changed
Lines changed: 112 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
14 | 24 | | |
15 | 25 | | |
16 | 26 | | |
| |||
61 | 71 | | |
62 | 72 | | |
63 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
64 | 81 | | |
65 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
66 | 88 | | |
67 | 89 | | |
68 | 90 | | |
| |||
113 | 135 | | |
114 | 136 | | |
115 | 137 | | |
116 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
117 | 156 | | |
118 | 157 | | |
119 | 158 | | |
120 | 159 | | |
121 | 160 | | |
122 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
123 | 172 | | |
124 | 173 | | |
125 | 174 | | |
| |||
200 | 249 | | |
201 | 250 | | |
202 | 251 | | |
203 | | - | |
| 252 | + | |
204 | 253 | | |
205 | | - | |
| 254 | + | |
206 | 255 | | |
207 | | - | |
| 256 | + | |
208 | 257 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
15 | 17 | | |
16 | 18 | | |
17 | 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 | + | |
| 73 | + | |
18 | 74 | | |
19 | 75 | | |
20 | 76 | | |
| |||
130 | 186 | | |
131 | 187 | | |
132 | 188 | | |
133 | | - | |
| 189 | + | |
134 | 190 | | |
135 | 191 | | |
136 | 192 | | |
| |||
139 | 195 | | |
140 | 196 | | |
141 | 197 | | |
142 | | - | |
| 198 | + | |
143 | 199 | | |
144 | 200 | | |
145 | 201 | | |
| |||
303 | 359 | | |
304 | 360 | | |
305 | 361 | | |
306 | | - | |
| 362 | + | |
307 | 363 | | |
308 | 364 | | |
309 | 365 | | |
| |||
0 commit comments