Skip to content

Commit 8b767f2

Browse files
shengyfuCopilot
andcommitted
Bound subprocess cleanup exit races and keep CI matrix independent
Allow a 250ms exit grace after group-signal permission errors, preserving the original error for a still-live child. Cover delayed exit and bounded denial, and disable matrix fail-fast so one platform cannot cancel the others. Co-authored-by: Copilot App <[email protected]>
1 parent fd0a228 commit 8b767f2

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
test:
3030
name: Test (${{ matrix.os }})
3131
strategy:
32+
fail-fast: false
3233
matrix:
3334
os: [ubuntu-latest, macos-latest, windows-latest]
3435
runs-on: ${{ matrix.os }}

‎scripts/agent/runtime.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,13 @@ def record(raw):
322322
os.killpg(proc.pid, signal.SIGKILL)
323323
except ProcessLookupError:
324324
pass
325-
except PermissionError:
326-
# macOS can return EPERM for an exited process group.
327-
# Ignore it only if our child really finished in the race.
328-
if proc.poll() is None:
329-
raise
325+
except PermissionError as error:
326+
# Allow a short exit race without hiding a denied signal
327+
# to a child that remains alive.
328+
try:
329+
proc.wait(timeout=0.25)
330+
except subprocess.TimeoutExpired:
331+
raise error
330332
proc.wait()
331333
finally:
332334
proc.stdout.close()

‎scripts/agent/test_agent.py‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,36 @@ def disappeared(pid, sig):
425425
self.assertTrue(proc.stdout.closed)
426426
self.assertTrue(proc.stderr.closed)
427427

428+
def test_permission_error_waits_for_exit_before_returning_truncated_result(self):
429+
with self.truncating_query() as proc:
430+
actual_wait = proc.wait
431+
432+
def exit_during_wait(timeout=None):
433+
if proc.returncode is None:
434+
self.assertEqual(timeout, 0.25)
435+
# Keep the child live through EPERM, then exit as the wait starts.
436+
proc.kill()
437+
return actual_wait(timeout=timeout)
438+
439+
with patch.object(runtime.os, "killpg", side_effect=PermissionError("exiting group")):
440+
with patch.object(proc, "wait", side_effect=exit_during_wait) as wait:
441+
result = self.search("find_files", max_results=1)
442+
wait.assert_any_call(timeout=0.25)
443+
self.assertTrue(result["truncated"])
444+
self.assertEqual(result["results"], [{"path": "a"}])
445+
self.assertIsNotNone(proc.returncode)
446+
self.assertTrue(proc.stdout.closed)
447+
self.assertTrue(proc.stderr.closed)
448+
428449
def test_permission_error_for_live_query_is_not_ignored(self):
429450
with self.truncating_query() as proc:
430-
with patch.object(runtime.os, "killpg", side_effect=PermissionError("signal denied")):
431-
with self.assertRaisesRegex(PermissionError, "signal denied"):
432-
self.search("find_files", max_results=1)
451+
error = PermissionError("signal denied")
452+
with patch.object(runtime.os, "killpg", side_effect=error):
453+
with patch.object(proc, "wait", wraps=proc.wait) as wait:
454+
with self.assertRaisesRegex(PermissionError, "signal denied") as raised:
455+
self.search("find_files", max_results=1)
456+
self.assertIs(raised.exception, error)
457+
wait.assert_called_once_with(timeout=0.25)
433458
self.assertIsNone(proc.poll())
434459
self.assertTrue(proc.stdout.closed)
435460
self.assertTrue(proc.stderr.closed)

0 commit comments

Comments
 (0)