Commit 45a4d4d
fix(sdk/python): bound the harness subprocess exit wait — silent reasoner wedge (#778)
A reasoner calling a CLI harness provider could wedge silently forever:
stuck 'running' with no child process, no logs, and a healthy event loop.
Root-caused from a production swe-planner run that sat 26 minutes in that
state: run_cli's finally block ended with a bare `await proc.wait()`, which
parks indefinitely in two real situations —
1. Windows proactor loop loses the RegisterWaitWithQueue completion that
resolves proc.wait() even though the child already exited (CPython
gh-81562 / gh-111604). Both pipes are at EOF, no process remains, and
nothing ever wakes the coroutine.
2. An orphaned grandchild outlives a killed parent while holding the
inherited output pipes: asyncio resolves proc.wait() only after every
pipe disconnects, and on Windows proc.kill() cannot reach grandchildren
(pre-fix, test_run_cli_idle_watchdog_aborts_stalled_child hangs >100s
on a real Windows machine because of exactly this).
Fix:
- _wait_process_exit(): bound the exit wait with a grace period; on
expiry, kill whatever remains and recover the real exit status from
proc.returncode or by polling the underlying Popen object, which needs
no event delivery.
- _kill_group(): use `taskkill /F /T` on Windows as the killpg analog so
kills reach the whole tree (also guards os.killpg with hasattr — it
does not exist on Windows).
- run_cli now also kills the child when the wait loop exits abnormally
(cancellation included); previously a cancelled run_cli left the CLI
subprocess running and awaited its natural exit.
Tests: unit regressions for the lost-notification recovery and
kill-on-cancellation, plus a real-subprocess regression where a grandchild
holds the pipes — run_cli must conclude in bounded time on every platform.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent b0fc271 commit 45a4d4d
3 files changed
Lines changed: 174 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
64 | 112 | | |
65 | 113 | | |
66 | 114 | | |
| |||
106 | 154 | | |
107 | 155 | | |
108 | 156 | | |
109 | | - | |
| 157 | + | |
| 158 | + | |
110 | 159 | | |
111 | 160 | | |
112 | 161 | | |
113 | 162 | | |
114 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
115 | 180 | | |
116 | 181 | | |
117 | 182 | | |
118 | 183 | | |
119 | 184 | | |
120 | 185 | | |
121 | 186 | | |
| 187 | + | |
122 | 188 | | |
123 | 189 | | |
124 | 190 | | |
| |||
135 | 201 | | |
136 | 202 | | |
137 | 203 | | |
| 204 | + | |
138 | 205 | | |
139 | 206 | | |
140 | 207 | | |
| |||
146 | 213 | | |
147 | 214 | | |
148 | 215 | | |
149 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
150 | 221 | | |
151 | 222 | | |
152 | 223 | | |
153 | 224 | | |
154 | 225 | | |
155 | 226 | | |
156 | | - | |
| 227 | + | |
157 | 228 | | |
158 | 229 | | |
159 | 230 | | |
| |||
162 | 233 | | |
163 | 234 | | |
164 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
165 | 239 | | |
166 | 240 | | |
167 | 241 | | |
168 | | - | |
| 242 | + | |
169 | 243 | | |
170 | 244 | | |
171 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
61 | 126 | | |
62 | 127 | | |
63 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
0 commit comments