Skip to content

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

Fix uncaught Windows crash on subprocess timeout in subproc.py (#552)

SAI MOHANEESH46fe7570ad47
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e26bc3ca..12ab1f4d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- YouTube items with successfully extracted transcripts are no longer pruned by title-only relevance scoring; the transcript content proves substantive topical coverage even when the video title has low lexical overlap with the query ([#468](https://github.com/mvanhorn/last30days-skill/issues/468))
- First-run setup wizard in SKILL.md now references the existing Python setup wizard (`last30days.py setup`) instead of the missing `nux-wizard.md` file, so first-run setup actually runs on new installs. ([#574](https://github.com/mvanhorn/last30days-skill/issues/574))
- `check-config.sh` no longer exits 1 when a `.env` value contains an unbalanced quote — replaced `xargs` (which interprets quotes) with `sed` for whitespace trimming in `load_env_vars` ([#506](https://github.com/mvanhorn/last30days-skill/issues/506))
+- `subproc.py` `run_with_timeout()` now guards `os.killpg` / `os.getpgid` with `hasattr`, preventing an uncaught `AttributeError` crash when a subprocess times out on Windows where these functions don't exist ([#527](https://github.com/mvanhorn/last30days-skill/issues/527))
- Entity-grounding rerank demotion now keys on the head token of the primary entity instead of requiring the full multi-word phrase as a contiguous substring. A high-engagement on-entity item (e.g. a 323-pt HN thread titled "Stripe is friendly to 'friendly fraud'") is no longer demoted to score 0 on a `Stripe payments` query just because it lacks the trailing search-hint word. The intended demotion still fires for items that never name the brand at all. The keyless Reddit comment-enrichment slot selection (`_slot_priority`), which mirrors this signal, was updated to the same head-token grounding so the two paths stay consistent.
- `--plan` / `--competitors-plan` file reads now specify `encoding="utf-8"` and catch `UnicodeDecodeError`, preventing crashes on non-ASCII content like accented entity names on Windows (cp1252). `check_perms()` in `check-config.sh` now skips the POSIX 600-permission check on MSYS/MinGW/Cygwin where `stat` runs in noacl mode. `skill_meta.py` `read_skill_version()` now passes `encoding="utf-8"` so SKILL.md emoji doesn't break version detection on Windows. ([#549](https://github.com/mvanhorn/last30days-skill/issues/549))
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 067af769..36ac3a49 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -60,3 +60,4 @@ v3 has durable watchlist with multi-source storage and extended time windows.
- [@jonthebeef](https://github.com/jonthebeef) - Early testing and feedback
- [@23241a6749](https://github.com/23241a6749) - Windows cp1252 fixes: utf-8 plan-file reads, skill_meta version-detection encoding, MSYS noacl permission check skip ([#549](https://github.com/mvanhorn/last30days-skill/pull/549)); first-run setup wizard fix: SKILL.md references existing Python setup wizard instead of missing nux-wizard.md ([#574](https://github.com/mvanhorn/last30days-skill/pull/574))
- [@23241a6749](https://github.com/23241a6749) - check-config.sh xargs unterminated quote fix ([#506](https://github.com/mvanhorn/last30days-skill/issues/506))
+- [@23241a6749](https://github.com/23241a6749) - Windows subprocess timeout fix: guard os.killpg/os.getpgid with hasattr in subproc.py ([#527](https://github.com/mvanhorn/last30days-skill/issues/527))
diff --git a/skills/last30days/scripts/lib/subproc.py b/skills/last30days/scripts/lib/subproc.py
index bc5772e4..da9e51dd 100644
--- a/skills/last30days/scripts/lib/subproc.py
+++ b/skills/last30days/scripts/lib/subproc.py
@@ -81,7 +81,10 @@ def run_with_timeout(
stdout, stderr = proc.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
try:
- os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
+ if hasattr(os, "killpg") and hasattr(os, "getpgid"):
+ os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
+ else:
+ proc.kill()
except (ProcessLookupError, PermissionError, OSError):
proc.kill()
proc.wait(timeout=5)
diff --git a/tests/test_subproc.py b/tests/test_subproc.py
index 8c6c23f8..c7067752 100644
--- a/tests/test_subproc.py
+++ b/tests/test_subproc.py
@@ -4,6 +4,8 @@ Covers the process-group cleanup path, timeout behavior, success path,
PID callback wiring, and environment inheritance.
"""
+import builtins
+import os as real_os
import unittest
from unittest.mock import patch
@@ -79,6 +81,22 @@ class TestRunWithTimeout(unittest.TestCase):
self.assertIsInstance(seen_pids[0], int)
self.assertGreater(seen_pids[0], 0)
+ def test_timeout_falls_back_to_kill_when_killpg_unavailable(self):
+ """Simulate Windows (no killpg/getpgid) — should fall back to proc.kill()."""
+ real_hasattr = builtins.hasattr
+
+ def selective_hasattr(obj, name):
+ if obj is real_os and name in ("killpg", "getpgid", "setsid"):
+ return False
+ return real_hasattr(obj, name)
+
+ with patch.object(builtins, "hasattr", side_effect=selective_hasattr):
+ with self.assertRaises(subproc.SubprocTimeout):
+ subproc.run_with_timeout(
+ ["sh", "-c", "sleep 10"],
+ timeout=1,
+ )
+
def test_on_pid_callback_exceptions_are_suppressed(self):
"""If the PID callback raises, the subprocess should still run to completion."""
def raising_callback(pid):