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(polymarket): block domain fallback when hard informative terms miss

Trevin Chowce489808fabc
diff --git a/skills/last30days/scripts/lib/polymarket.py b/skills/last30days/scripts/lib/polymarket.py
index 557cbb25..5a6cb7e6 100644
--- a/skills/last30days/scripts/lib/polymarket.py
+++ b/skills/last30days/scripts/lib/polymarket.py
@@ -131,9 +131,40 @@ _DOMAIN_WORDS = frozenset({
"software", "plugin", "skill", "agent", "bot", "search", "research",
})
+# Soft residue left after stripping domain words from a sweep topic
+# ("AI frontier developments"). Domain-word fallback may fire when these are
+# the only informative leftovers. Distinctive terms like "benchmark" block it.
+_SWEEP_RESIDUE = frozenset({
+ "frontier", "developments", "development", "news", "trends", "trend",
+ "latest", "industry", "space", "ecosystem", "landscape", "overview",
+ "updates", "update", "future", "outlook", "sector", "field", "world",
+})
+
_NOISE_WORDS = _NOISE_WORDS | _DOMAIN_WORDS
+def _domain_word_fallback_allows(core_words: list[str], informative: list[str],
+ title_lower: str, title_words: set[str]) -> bool:
+ """Allow domain-word title matches only for pure/soft domain sweeps.
+
+ Blocks mixed topics like \"MCP protocol benchmark\" from accepting a Kyoto
+ Protocol market via the shared domain token \"protocol\" when the distinctive
+ informative word (\"benchmark\") missed.
+ """
+ hard_informative = [w for w in informative if w not in _SWEEP_RESIDUE]
+ if hard_informative:
+ return False
+ domain_words = [w for w in core_words if w in _DOMAIN_WORDS]
+ if not domain_words:
+ return False
+ for word in domain_words:
+ if word in title_words:
+ return True
+ if len(word) >= 4 and word in title_lower:
+ return True
+ return False
+
+
def _passes_topic_filter(topic: str, event_title: str) -> bool:
"""Check if event title contains enough informative words from the topic.
@@ -179,25 +210,8 @@ def _passes_topic_filter(topic: str, event_title: str) -> bool:
if match_count >= min_matches:
return True
- # Domain-word fallback. When the topic IS a domain (e.g. an AI-news sweep),
- # the words carrying the subject — "ai", "model" — sit in _NOISE_WORDS, and
- # the informative residue ("artificial", "intelligence") never appears in
- # real market titles, which say "AI". That made the filter reject every AI
- # market by construction. So if the informative words missed, fall back to
- # the topic's own domain words. Narrow product topics ("Mill.com food
- # recycler") contain no such words at all, so the fallback never fires for
- # them and upstream's false-match guard is untouched.
- domain_words = [w for w in core_words if w in _DOMAIN_WORDS]
- if not domain_words:
- return False
-
- for word in domain_words:
- if word in title_words:
- return True
- if len(word) >= 4 and word in title_lower:
- return True
-
- return False
+ # Domain-word fallback for soft domain sweeps only (see helper).
+ return _domain_word_fallback_allows(core_words, informative, title_lower, title_words)
def _passes_any_informative_word(topic: str, event_title: str) -> bool:
@@ -227,22 +241,7 @@ def _passes_any_informative_word(topic: str, event_title: str) -> bool:
if len(word) >= 4 and word in title_lower:
return True
- # Domain-word fallback — mirrors _passes_topic_filter. For a domain sweep
- # ("AI frontier developments") the subject words "ai"/"model" sit in
- # _NOISE_WORDS, so the informative residue ("frontier", "developments")
- # never appears in real market titles and every AI market gets dropped
- # here — undoing the parse-stage fix one stage later. Fall back to the
- # topic's own domain words. Narrow product/comparison topics carry no
- # _DOMAIN_WORDS, so the fallback never fires for them (behavior unchanged).
- domain_words = [w for w in core_words if w in _DOMAIN_WORDS]
- if not domain_words:
- return False
- for word in domain_words:
- if word in title_words:
- return True
- if len(word) >= 4 and word in title_lower:
- return True
- return False
+ return _domain_word_fallback_allows(core_words, informative, title_lower, title_words)
def filter_items_against_topic(topic: str, items: List[Any]) -> List[Any]:
diff --git a/tests/test_polymarket.py b/tests/test_polymarket.py
index d22a6a9d..928be027 100644
--- a/tests/test_polymarket.py
+++ b/tests/test_polymarket.py
@@ -189,6 +189,24 @@ def test_passes_topic_filter_two_word_still_needs_one():
) is True
+
+def test_domain_fallback_keeps_soft_sweep_ai_markets():
+ """Soft sweep residue may match via domain words (the #859 fix)."""
+ assert polymarket._passes_topic_filter(
+ "AI frontier developments", "Will AI models beat humans at coding?"
+ ) is True
+
+
+def test_domain_fallback_blocked_when_hard_informative_misses():
+ """Mixed topics must not accept unrelated markets via a shared domain token."""
+ assert polymarket._passes_topic_filter(
+ "MCP protocol benchmark", "Will the Kyoto Protocol survive?"
+ ) is False
+ assert polymarket._passes_any_informative_word(
+ "MCP protocol benchmark", "Will the Kyoto Protocol survive?"
+ ) is False
+
+
def test_passes_topic_filter_multi_word_edge_exactly_three():
"""Topic with exactly 3 informative words, 1 match -> rejected."""
assert polymarket._passes_topic_filter(