AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
fix(subproc): guard SIGKILL escalation against killpg AttributeError on Windows (#638)
Matt Van Horn0a5bdee16dff
diff --git a/skills/last30days/scripts/lib/subproc.py b/skills/last30days/scripts/lib/subproc.pyindex da6d4309..cbed2701 100644--- a/skills/last30days/scripts/lib/subproc.py+++ b/skills/last30days/scripts/lib/subproc.py@@ -91,9 +91,17 @@ def run_with_timeout(proc.wait(timeout=5)except subprocess.TimeoutExpired:# 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:- os.killpg(os.getpgid(proc.pid), signal.SIGKILL)- except (ProcessLookupError, PermissionError, OSError):+ 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()raise SubprocTimeout(f"Command {cmd[0]} timed out after {timeout}s")diff --git a/tests/test_subproc.py b/tests/test_subproc.pyindex afd09ee6..95bafeb6 100644--- a/tests/test_subproc.py+++ b/tests/test_subproc.py@@ -155,6 +155,44 @@ class TestRunWithTimeout(unittest.TestCase):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.+ 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()