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: corroborate discovered handles and exclude query scaffolding (#1310)
CapoAic2e74ebbe24a
diff --git a/changelog.d/+handle-corroboration.fixed.md b/changelog.d/+handle-corroboration.fixed.mdnew file mode 100644index 00000000..0ab6270d--- /dev/null+++ b/changelog.d/+handle-corroboration.fixed.md@@ -0,0 +1 @@+Handle discovery no longer treats short fragments of a topic word (for example "go" for "Google Gemini") as the topic's subject, now recognizes handles spelled from a name's prefixes (for example "steipete" for "Peter Steinberger"), and no longer gives first-party status to accounts named after query scaffolding words like "review" or "news".diff --git a/skills/last30days/scripts/lib/pipeline.py b/skills/last30days/scripts/lib/pipeline.pyindex d2f4b616..6a7be437 100644--- a/skills/last30days/scripts/lib/pipeline.py+++ b/skills/last30days/scripts/lib/pipeline.py@@ -4230,11 +4230,32 @@ def _topic_first_party_candidates(topic: str) -> set[str]:tokens.add(mention.lower())for word in re.findall(r"[A-Za-z0-9_]{3,15}", topic or ""):lowered = word.lower()- if lowered not in relevance.STOPWORDS:+ # Skip query scaffolding ("review", "news", "latest"): it describes the+ # search, not the subject, and rerank._handle_is_topic skips it too.+ if lowered not in relevance.STOPWORDS and lowered not in relevance.LOW_SIGNAL_QUERY_TOKENS:tokens.add(lowered)return tokens+def _handle_contains_topic_word(handle: str, topic: str) -> bool:+ """True when ``handle`` contains a whole topic word of three or more letters.++ Covers short subject names that sit inside a longer handle ("vuejs" for+ "Vue"), which rerank._handle_is_topic misses because it only counts+ containment for words of four or more letters. The containment runs one+ way only, so a short fragment of a longer topic word ("go" in "Google")+ never matches, and query scaffolding words ("review", "news") are skipped.+ """+ for word in re.findall(r"[a-z0-9]+", (topic or "").lower()):+ if len(word) < 3:+ continue+ if word in relevance.STOPWORDS or word in relevance.LOW_SIGNAL_QUERY_TOKENS:+ continue+ if word in handle:+ return True+ return False++def _name_lane_subject(topic: str) -> str:"""Resolve the entity name to search for by name, not the whole topic.@@ -4366,14 +4387,21 @@ def _run_supplemental_searches(for h in ([x_handle] + list(x_related or []))if h and h.strip()}- topic_tokens = {t for t in re.findall(r"[a-z0-9]+", topic.lower()) if len(t) > 2}seen = {h.lower() for h in resolved_handles_out}for h in [*handles, *related_handles]:clean = h.lstrip("@").strip().lower()if not clean or clean in seen:continue- corroborated = clean in explicit or any(- token in clean or clean in token for token in topic_tokens+ # "Looks like the topic's subject" is rerank's test: a handle that+ # contains a topic word or is spelled from word prefixes. A bare+ # substring match either way admitted fragments ("go" for "Google")+ # and missed real subjects ("steipete" for "Peter Steinberger").+ # Rerank's containment needs a 4+ letter word, so a short subject+ # name inside a longer handle ("vuejs" for "Vue") is added here.+ corroborated = (+ clean in explicit+ or rerank._handle_is_topic(clean, topic)+ or _handle_contains_topic_word(clean, topic))if corroborated:resolved_handles_out.append(clean)diff --git a/tests/test_first_party_floor.py b/tests/test_first_party_floor.pyindex c1f6b6f1..65b8ff4a 100644--- a/tests/test_first_party_floor.py+++ b/tests/test_first_party_floor.py@@ -257,6 +257,16 @@ def test_topic_candidates_exclude_stopwords():assert "the" not in got and "of" not in got+def test_topic_candidates_exclude_query_scaffolding_words():+ """Words like "review" or "news" describe the search, not the subject, so an+ account that happens to be named after one must not get first-party status+ (rerank._handle_is_topic already excludes the same words)."""+ from lib import pipeline+ got = pipeline._topic_first_party_candidates("Cursor review latest news")+ assert "cursor" in got+ assert not {"review", "latest", "news"} & got++def test_topic_candidates_do_not_exempt_unrelated_authors():"""Candidates only matter when a post's author matches one, so ordinarywords cost nothing -- no account is named 'lunch'."""diff --git a/tests/test_resolved_handles_wiring.py b/tests/test_resolved_handles_wiring.pyindex d1fdab0c..3368d87d 100644--- a/tests/test_resolved_handles_wiring.py+++ b/tests/test_resolved_handles_wiring.py@@ -38,6 +38,46 @@ def test_collector_normalizes_deduplicates_and_requires_corroboration():assert output == ["existing", "explicit", "exampledev", "related"]+def _resolve(topic, extracted):+ """Run the Phase 2 collector with a fixed extracted-handle list; return the+ handles it resolved beyond the explicit anchor handle (the collector returns+ early with no X items and no explicit handle, so one anchor keeps it running)."""+ output = []+ with patch.object(pipeline.entity_extract, "extract_entities", return_value={+ "x_handles": extracted, "x_hashtags": [], "reddit_subreddits": [],+ }), patch.object(pipeline.env, "x_backend_chain", return_value=[]):+ pipeline._run_supplemental_searches(+ topic=topic, bundle=schema.RetrievalBundle(), plan=_plan(),+ config={}, depth="default", date_range=("2026-03-01", "2026-03-31"),+ runtime=providers.mock_runtime({}, "default"), mock=False,+ rate_limited_sources=set(), rate_limit_lock=threading.Lock(),+ x_handle="anchor_handle", resolved_handles_out=output,+ )+ return [h for h in output if h != "anchor_handle"]+++def test_short_handles_are_not_corroborated_by_substring_overlap():+ """An extracted handle that is merely a short fragment of a topic word ("go"+ in "Google", "ai" in "Chair") does not name the topic and must not earn+ first-party status."""+ assert _resolve("Google Gemini", ["go", "google_ai_dev"]) == ["google_ai_dev"]+ assert _resolve("Chair review", ["ai"]) == []+++def test_handle_containing_a_full_three_letter_topic_word_is_corroborated():+ """A short subject name ("Vue") inside a longer handle ("vuejs") is still+ the subject, while a short fragment of a longer topic word ("go" in+ "Google") is not."""+ assert _resolve("Vue", ["vuejs", "go"]) == ["vuejs"]+ assert _resolve("Google Gemini", ["go"]) == []+ # Scaffolding words never name the subject, even when contained in a handle.+ assert _resolve("Cursor review", ["reviewbot"]) == []+++def test_handle_spelled_from_the_topic_name_is_still_corroborated():+ assert _resolve("Peter Steinberger", ["steipete", "commentator"]) == ["steipete"]++def test_discovered_handles_reach_real_fusion_and_reranking():raw = [{"id": "subject", "text": "A new release shipped today",