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(github): strip planner-injected search qualifiers from topic queries (#955)
Som Samantray9b4684d5f373
diff --git a/changelog.d/949.fixed.md b/changelog.d/949.fixed.mdnew file mode 100644index 00000000..b7cf2eb1--- /dev/null+++ b/changelog.d/949.fixed.md@@ -0,0 +1 @@+The GitHub source no longer reports zero results when the planner writes search qualifiers into the topic (e.g. `open source AI stars:>1000 created:>2025-03-20`). `search_github` appends its own `created:>{from_date}` window, and two `created:` qualifiers collide: GitHub honors the first and ignores the appended window, so out-of-window items are fetched and then dropped wholesale by the local date filter, surfacing as a silent `no-results`. Qualifiers are now stripped from the topic before the query is built (including comma/semicolon-glued forms and quoted values such as `label:"bug fix"`), topic terms glued after a qualifier value are preserved, and a qualifier-only topic reports an explicit error instead of searching the whole site.diff --git a/docs/residual-review-findings/42c5ab5bebcb3d4bd4d8bfc11f89b4df4bc1da9b.md b/docs/residual-review-findings/42c5ab5bebcb3d4bd4d8bfc11f89b4df4bc1da9b.mdnew file mode 100644index 00000000..c5e34c53--- /dev/null+++ b/docs/residual-review-findings/42c5ab5bebcb3d4bd4d8bfc11f89b4df4bc1da9b.md@@ -0,0 +1,29 @@+## Residual Review Findings++Run context: ce-code-review `mode:agent` on branch `fix/github-qualifier-strip` (head `42c5ab5bebcb3d4bd4d8bfc11f89b4df4bc1da9b`), plan `docs/plans/2026-08-07-001-fix-github-qualifier-collision-plan.md`, run id `20260807-231856-17902`. Findings not applied in LFG step 5; filed for durability.++### Filed (tracker: GitHub Issues)++- **P1** — `skills/last30days/scripts/lib/github.py:237` — Qualifier-only topic classified as ERROR poisons retry eligibility — [mvanhorn/last30days-skill#951](https://github.com/mvanhorn/last30days-skill/issues/951) (settled-conflict: report-only per KTD-1)+- **P2** — `skills/last30days/scripts/lib/github.py:186` — Quote-wrapped or paren-wrapped qualifiers bypass the strip — [mvanhorn/last30days-skill#952](https://github.com/mvanhorn/last30days-skill/issues/952)+- **P2** — `skills/last30days/scripts/lib/github.py:231` — Empty or noise-plus-qualifier topics flip to hard ERROR — [mvanhorn/last30days-skill#953](https://github.com/mvanhorn/last30days-skill/issues/953) (settled-conflict: report-only per KTD-1)+- **P3** — `skills/last30days/scripts/lib/github.py:229` — Repeated qualifier-only subqueries spam logs and error detail — [mvanhorn/last30days-skill#954](https://github.com/mvanhorn/last30days-skill/issues/954)++### Settled-conflict findings (report-only, not filed as apply requests)++- **P1** — `skills/last30days/scripts/lib/github.py:237` — Qualifier-only topic classified as ERROR poisons retry eligibility — conflicts with KTD-1 (session-settled plan decision: qualifier-only topics return the error envelope). Downstream ERROR/attempted classification blocks `_retry_thin_sources`; filed as #951 for durability, not for application.+- **P2** — `skills/last30days/scripts/lib/github.py:231` — Empty or noise-plus-qualifier topics flip to hard ERROR — conflicts with KTD-1/R3 (error envelope for qualifier-only/empty topics). Filed as #953 for durability, not for application.++### No sink / failed++None.++### Proceeded-and-flagged settled-decision conflicts (from ce-work step 2)++None — ce-work returned no `settled_decision_conflicts`.++### Residual risks carried from the review++- Error-envelope `context["core"]` is unstripped in the qualifier-only path vs stripped in the success path; no current consumer is affected.+- GitHub 422 behavior for unbalanced quotes is external API behavior, not exercised in tests.+- Planner emission of comma-glued, quoted, or wrapped qualifier shapes is LLM behavior; exposure is unquantifiable from code.diff --git a/skills/last30days/scripts/lib/github.py b/skills/last30days/scripts/lib/github.pyindex f8774a99..30e4faa0 100644--- a/skills/last30days/scripts/lib/github.py+++ b/skills/last30days/scripts/lib/github.py@@ -166,6 +166,38 @@ def _compute_relevance(return round(relevance, 2)+# GitHub search qualifiers the planner sometimes writes straight into the topic+# string (e.g. "open source AI stars:>1000 created:>2025-03-20"). They must not+# reach the query builder in `search_github`: it appends its own+# `created:>{from_date}`, and when two `created:` qualifiers collide GitHub+# honours the FIRST and silently ignores ours. The API then returns+# out-of-window items that `parse_github_response`'s date filter drops+# wholesale — a source that fetches results and reports zero (issue #949).+QUALIFIER_KEYS = frozenset({+ "archived", "assignee", "author", "base", "closed", "comments", "commenter",+ "created", "fork", "forks", "head", "in", "interactions", "involves", "is",+ "label", "language", "license", "linked", "mentions", "merged", "milestone",+ "no", "org", "project", "pushed", "reactions", "repo", "review",+ "review-requested", "reviewed-by", "size", "sort", "stars", "state", "team",+ "topic", "topics", "type", "updated", "user",+})++_QUALIFIER_RE = re.compile(+ r"(?:(?<=[\s,;])|^)(?:" + "|".join(sorted(QUALIFIER_KEYS)) + r"):(?:[<>]=?)?(?:\"[^\"]*\"|[^\s,;()\[\]]+)[,;]?",+ re.IGNORECASE,+)+++def strip_search_qualifiers(text: str) -> str:+ """Strip GitHub search qualifiers from a topic, leaving plain-language text.++ Whitespace is collapsed. Returns an empty string when the topic was nothing+ but qualifiers; callers must handle that rather than searching on an empty+ term, which would match the entire site.+ """+ return " ".join(_QUALIFIER_RE.sub(" ", text).split())++def search_github(topic: str,from_date: str,@@ -193,6 +225,24 @@ 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).+ _log("Topic contained only search qualifiers or was empty; nothing to search")+ 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}"+ ),+ }+ core = plain_coreresolved_token = _resolve_token(token)authed = bool(resolved_token)if not authed:diff --git a/tests/test_github.py b/tests/test_github.pyindex cea88acc..e3ee2510 100644--- a/tests/test_github.py+++ b/tests/test_github.py@@ -2,6 +2,7 @@import jsonimport unittest+import urllib.parsefrom unittest.mock import patch, MagicMockfrom lib import github@@ -495,5 +496,163 @@ class TestPersonPushEventsLane(unittest.TestCase):self.assertEqual(items[0]["metadata"]["event_id"], "2")+class TestStripSearchQualifiers(unittest.TestCase):+ """Planner-injected GitHub search qualifiers must never reach the query+ builder: search_github appends its own created:>{from_date}, and two+ created: qualifiers collide (GitHub honors the first), which then makes+ the local date filter drop everything (issue #949)."""++ def test_strips_qualifiers_keeps_words(self):+ self.assertEqual(+ github.strip_search_qualifiers(+ "open source ai stars:>1000 created:>2025-03-20"+ ),+ "open source ai",+ )++ def test_plain_word_is_not_a_qualifier_without_colon(self):+ self.assertEqual(+ github.strip_search_qualifiers("ai in healthcare"),+ "ai in healthcare",+ )++ def test_qualifiers_removed_from_mixed_topic(self):+ self.assertEqual(+ github.strip_search_qualifiers("langchain is:issue created:>2026-01-01"),+ "langchain",+ )++ def test_case_insensitive_qualifier_only_topic(self):+ self.assertEqual(github.strip_search_qualifiers("Stars:>1000"), "")++ def test_slash_containing_value_consumed(self):+ self.assertEqual(+ github.strip_search_qualifiers("repo:facebook/react bug"),+ "bug",+ )++ def test_qualifier_glued_after_comma_is_stripped(self):+ # A comma-glued qualifier (planner output like "ai,created:>2025-03-20")+ # must not survive to collide with the adapter's own created: window.+ self.assertEqual(+ github.strip_search_qualifiers("ai,created:>2025-03-20"),+ "ai,",+ )++ def test_qualifier_glued_after_semicolon_is_stripped(self):+ self.assertEqual(+ github.strip_search_qualifiers("ai;created:>2025-03-20"),+ "ai;",+ )++ def test_quoted_qualifier_value_fully_consumed(self):+ # label:"bug fix" spans a space; the whole quoted value must be+ # consumed so no stray fragment (e.g. `fix"`) reaches the query.+ self.assertEqual(+ github.strip_search_qualifiers('label:"bug fix" open source'),+ "open source",+ )++ def test_topic_term_glued_after_qualifier_value_is_preserved(self):+ # A topic term glued after a qualifier value ("created:>2025-03-20,+ # robotics") must survive stripping - the value class must stop at+ # the separator instead of greedily eating the following term.+ result = github.strip_search_qualifiers("created:>2025-03-20,robotics")+ self.assertIn("robotics", result)+ self.assertNotIn("created:", result)++ def test_mid_topic_qualifier_with_glued_term_preserves_subject(self):+ result = github.strip_search_qualifiers("ai created:>2025-03-20,robotics")+ self.assertIn("robotics", result)+ self.assertIn("ai", result)+ self.assertNotIn("created:", result)+++class TestSearchGithubQualifiers(unittest.TestCase):+ """End-to-end behavior of search_github on qualifier-bearing topics."""++ def _capturing_fetch(self, captured):+ def fake_fetch(url, *args, **kwargs):+ captured["url"] = url+ return {"total_count": 0, "items": []}+ return fake_fetch++ def _query(self, captured_url):+ return urllib.parse.parse_qs(+ urllib.parse.urlparse(captured_url).query+ )["q"][0]++ @patch.object(github, "_resolve_token", return_value="test-token")+ def test_planner_qualifiers_stripped_before_query_build(self, mock_token):+ captured = {}+ with patch.object(github, "_fetch_json", side_effect=self._capturing_fetch(captured)):+ github.search_github(+ "open source ai stars:>1000 created:>2025-03-20",+ "2026-07-01", "2026-07-31",+ )+ q = self._query(captured["url"])+ self.assertEqual(q, "open source ai created:>2026-07-01")+ self.assertEqual(q.count("created:"), 1)++ @patch.object(github, "_resolve_token", return_value="test-token")+ def test_qualifier_only_topic_errors_without_network(self, mock_token):+ with patch.object(github, "_fetch_json") as mock_fetch:+ result = github.search_github(+ "created:>2025-03-20", "2026-07-01", "2026-07-31",+ )+ mock_fetch.assert_not_called()+ self.assertEqual(result["items"], [])+ self.assertIn("error", result)+ self.assertIn("qualifier", result["error"].lower())+ self.assertEqual(result["context"]["from_date"], "2026-07-01")++ @patch.object(github, "_resolve_token", return_value="test-token")+ def test_qualifier_key_word_without_colon_survives(self, mock_token):+ captured = {}+ with patch.object(github, "_fetch_json", side_effect=self._capturing_fetch(captured)):+ github.search_github(+ "state of the art ai", "2026-07-01", "2026-07-31",+ )+ q = self._query(captured["url"])+ # `state` is a GitHub qualifier key but appears here without a colon;+ # it must survive extract_core_subject + the qualifier strip.+ self.assertIn("state", q)+ self.assertEqual(q.count("created:"), 1)++++ @patch.object(github, "_resolve_token", return_value="test-token")+ def test_comma_glued_qualifier_builds_single_created_query(self, mock_token):+ captured = {}+ with patch.object(github, "_fetch_json", side_effect=self._capturing_fetch(captured)):+ github.search_github(+ "ai,created:>2025-03-20", "2026-07-01", "2026-07-31",+ )+ q = self._query(captured["url"])+ self.assertEqual(q.count("created:"), 1)+ self.assertIn("created:>2026-07-01", q)+ self.assertNotIn("created:>2025-03-20", q)++ @patch.object(github, "_resolve_token", return_value="test-token")+ def test_empty_topic_errors_without_network(self, mock_token):+ with patch.object(github, "_fetch_json") as mock_fetch:+ result = github.search_github("", "2026-07-01", "2026-07-31")+ mock_fetch.assert_not_called()+ self.assertEqual(result["items"], [])+ self.assertIn("error", result)++ @patch.object(github, "_resolve_token", return_value="test-token")+ def test_glued_term_after_qualifier_value_reaches_query(self, mock_token):+ captured = {}+ with patch.object(github, "_fetch_json", side_effect=self._capturing_fetch(captured)):+ github.search_github(+ "ai created:>2025-03-20,robotics", "2026-07-01", "2026-07-31",+ )+ q = self._query(captured["url"])+ self.assertIn("robotics", q)+ self.assertIn("ai", q)+ self.assertEqual(q.count("created:"), 1)++if __name__ == "__main__":unittest.main()