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(github): bound qualifier-only topic fragments in errors and logs so fanout cannot spam them (#954) (#1039)

Terry Lia5abaa2e0694
diff --git a/changelog.d/954.fixed.md b/changelog.d/954.fixed.md
new file mode 100644
index 00000000..06da16ca
--- /dev/null
+++ b/changelog.d/954.fixed.md
@@ -0,0 +1 @@
+GitHub qualifier-only rejections now truncate the topic in error detail and logs so a long planner query cannot spam stderr, the error envelope, and doctor hints on every subquery.
diff --git a/skills/last30days/scripts/lib/github.py b/skills/last30days/scripts/lib/github.py
index 2d7d5964..2b25c9b5 100644
--- a/skills/last30days/scripts/lib/github.py
+++ b/skills/last30days/scripts/lib/github.py
@@ -228,6 +228,17 @@ def strip_search_qualifiers(text: str) -> str:
return " ".join(stripped.split())
+# Bound topic fragments in logs/error envelopes so fanout cannot blow them up (#954).
+_DIAGNOSTIC_TOPIC_LIMIT = 120
+
+
+def _truncate_diagnostic(text: str, limit: int = _DIAGNOSTIC_TOPIC_LIMIT) -> str:
+ """Cap a topic fragment used in logs or error envelopes."""
+ if len(text) <= limit:
+ return text
+ return f"{text[:limit]}..."
+
+
def search_github(
topic: str,
from_date: str,
@@ -256,22 +267,27 @@ def search_github(
count = DEPTH_LIMITS.get(depth, DEPTH_LIMITS["default"])
core = extract_core_subject(topic)
plain_core = strip_search_qualifiers(core)
- if plain_core != core:
- _log(f"Stripped search qualifiers: '{core}' -> '{plain_core}'")
if not plain_core:
# A qualifier-only (or empty) topic leaves nothing to search on.
# Report it instead of querying an empty term, which would match the
# whole site and then be discarded by the date filter as a bogus
- # "no results" (issue #949).
+ # "no results" (issue #949). Truncate the topic; skip the strip log
+ # so this path does not repeat an unbounded core (issue #954).
_log("Topic contained only search qualifiers or was empty; nothing to search")
+ shown = _truncate_diagnostic(topic)
return {
"items": [],
"context": {"core": core, "from_date": from_date,
"to_date": to_date, "count": count},
"error": (
- f"GitHub topic contained only search qualifiers or was empty: {topic!r}"
+ f"GitHub topic contained only search qualifiers or was empty: {shown!r}"
),
}
+ if plain_core != core:
+ _log(
+ "Stripped search qualifiers: "
+ f"'{_truncate_diagnostic(core)}' -> '{_truncate_diagnostic(plain_core)}'"
+ )
core = plain_core
resolved_token = _resolve_token(token)
authed = bool(resolved_token)
diff --git a/tests/test_github_qualifier_spam.py b/tests/test_github_qualifier_spam.py
new file mode 100644
index 00000000..a438c794
--- /dev/null
+++ b/tests/test_github_qualifier_spam.py
@@ -0,0 +1,78 @@
+"""Qualifier-only GitHub topics must not embed unbounded raw topics.
+
+Stream fanout calls ``search_github`` once per subquery. Before #954 the
+error envelope used ``{topic!r}`` and the strip log used the full core, so
+log volume, error-report volume, and doctor-hint size scaled with both
+fanout and topic length.
+"""
+
+from unittest.mock import patch
+
+from lib import github
+
+_FROM = "2026-07-01"
+_TO = "2026-07-31"
+# Wrapper text plus a ~120-char topic slice. The pre-fix error embedded
+# the entire raw topic (thousands of chars on a pathological planner query).
+_ERROR_BOUND = 300
+_STRIP_LOG_BOUND = 400
+
+
+def _long_qualifier_only_topic() -> str:
+ return "created:>2025-03-20 " + ("stars:>1 " * 400)
+
+
+def test_qualifier_only_error_detail_is_bounded():
+ topic = _long_qualifier_only_topic()
+ with patch.object(github, "_resolve_token", return_value="t"), patch.object(
+ github, "_fetch_json"
+ ) as fetch:
+ result = github.search_github(topic, _FROM, _TO)
+ fetch.assert_not_called()
+ error = result["error"]
+ assert "qualifier" in error.lower()
+ assert len(error) < _ERROR_BOUND
+ assert len(error) < len(topic)
+ assert "created:>2025-03-20" in error
+ assert "..." in error
+
+
+def test_short_qualifier_only_topic_is_fully_shown():
+ topic = "created:>2025-03-20"
+ with patch.object(github, "_resolve_token", return_value="t"), patch.object(
+ github, "_fetch_json"
+ ) as fetch:
+ result = github.search_github(topic, _FROM, _TO)
+ fetch.assert_not_called()
+ assert topic in result["error"]
+ assert "..." not in result["error"]
+
+
+def test_qualifier_only_logs_are_bounded_across_fanout():
+ topic = _long_qualifier_only_topic()
+ logs: list[str] = []
+ with patch.object(github, "_resolve_token", return_value="t"), patch.object(
+ github, "_fetch_json"
+ ) as fetch, patch.object(github, "_log", side_effect=lambda m: logs.append(m)):
+ for _ in range(5):
+ github.search_github(topic, _FROM, _TO)
+ fetch.assert_not_called()
+ assert logs
+ for msg in logs:
+ assert len(msg) < _ERROR_BOUND
+ assert topic not in msg
+
+
+def test_mixed_topic_strip_log_is_bounded():
+ subject = "open source ai " * 200
+ topic = subject + "stars:>1000 created:>2025-03-20"
+ logs: list[str] = []
+ with patch.object(github, "_resolve_token", return_value="t"), patch.object(
+ github, "_fetch_json", return_value={"items": []}
+ ), patch.object(github, "_log", side_effect=lambda m: logs.append(m)):
+ github.search_github(topic, _FROM, _TO)
+ strip_logs = [m for m in logs if m.startswith("Stripped search qualifiers:")]
+ assert strip_logs
+ for msg in strip_logs:
+ assert len(msg) < _STRIP_LOG_BOUND
+ assert subject not in msg