Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

Merge remote-tracking branch 'origin/main' into pr-624-fix-588-windows-killpg-fallback

Trevin Chow46269c46a5fc
diff --cc skills/last30days/scripts/lib/subproc.py
index 24fc4215,cbed2701..c2971cdb
--- a/skills/last30days/scripts/lib/subproc.py
+++ b/skills/last30days/scripts/lib/subproc.py
@@@ -90,11 -90,20 +90,23 @@@ def run_with_timeout
try:
proc.wait(timeout=5)
except subprocess.TimeoutExpired:
- proc.kill()
+ # Child ignored SIGTERM (or our killpg lost the race); escalate.
+ # Guard killpg/getpgid the same way the SIGTERM path above does:
+ # they are POSIX-only and raise AttributeError on Windows. The
+ # primary path was hardened in #552; this mirrors that guard on the
+ # escalation path (added later in #433) so the same crash can't
+ # re-surface here (#588).
+ try:
+ if hasattr(os, "killpg") and hasattr(os, "getpgid"):
+ os.killpg(os.getpgid(proc.pid), signal.SIGKILL)
+ else:
+ proc.kill()
+ except (ProcessLookupError, PermissionError, OSError, AttributeError):
+ proc.kill()
- proc.wait()
+ try:
+ proc.wait(timeout=5)
+ except subprocess.TimeoutExpired:
+ pass # process unkillable (e.g. D-state); leave as zombie
raise SubprocTimeout(f"Command {cmd[0]} timed out after {timeout}s")
return SubprocResult(
diff --cc tests/test_subproc.py
index 8c6c23f8,95bafeb6..16f372bc
--- a/tests/test_subproc.py
+++ b/tests/test_subproc.py
@@@ -93,5 -142,57 +142,58 @@@ class TestRunWithTimeout(unittest.TestC
self.assertEqual(result.returncode, 0)
self.assertEqual(result.stdout.strip(), "ok")
+ def test_sigterm_ignoring_child_is_sigkill_escalated(self):
+ """A child that ignores SIGTERM must be escalated to SIGKILL.
+
+ Without escalation, ``proc.wait(timeout=5)`` raises
+ ``subprocess.TimeoutExpired`` past the ``except`` block instead of the
+ documented ``SubprocTimeout``, and the child stays alive.
+ """
+ with self.assertRaises(subproc.SubprocTimeout):
+ subproc.run_with_timeout(
+ ["sh", "-c", "trap '' TERM; sleep 30"],
+ timeout=1,
+ )
+
+ def test_escalation_path_guards_killpg_attributeerror(self):
+ """The SIGKILL escalation must not crash if killpg is unavailable (Windows).
+
+ Regression for the #588 class of bug on the escalation path added in
+ #433: os.killpg raising AttributeError must be caught and fall back to
+ proc.kill(), so the documented SubprocTimeout surfaces instead of a bare
+ AttributeError. The primary SIGTERM path was already guarded (#552); this
+ mirrors that guard on the escalation path.
+ """
+ TimeoutExpired = subproc.subprocess.TimeoutExpired
+
+ class _FakeProc:
+ def __init__(self):
+ self.pid = 4321
+ self.kill_count = 0
+
+ def communicate(self, timeout=None):
+ raise TimeoutExpired(cmd="x", timeout=timeout)
+
+ def wait(self, timeout=None):
+ # First wait (timeout=5) forces the SIGKILL escalation branch;
- # the final wait() (no timeout) returns.
++ # the final bounded wait is swallowed if the process still
++ # refuses to exit.
+ if timeout is not None:
+ raise TimeoutExpired(cmd="x", timeout=timeout)
+ return 0
+
+ def kill(self):
+ self.kill_count += 1
+
+ fake = _FakeProc()
+ with patch.object(subproc.subprocess, "Popen", return_value=fake), \
+ patch.object(subproc.os, "getpgid", lambda pid: pid), \
+ patch.object(subproc.os, "killpg", side_effect=AttributeError("no killpg on Windows")):
+ with self.assertRaises(subproc.SubprocTimeout):
+ subproc.run_with_timeout(["x"], timeout=1)
+ # Both the primary and escalation paths must have fallen back to kill().
+ self.assertGreaterEqual(fake.kill_count, 2)
+
+
if __name__ == "__main__":
unittest.main()