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: tighten evidence relevance floor

terry-li-hma2ed2f3167f2
diff --git a/skills/last30days/scripts/lib/render.py b/skills/last30days/scripts/lib/render.py
index d0f74910..5a312a4a 100644
--- a/skills/last30days/scripts/lib/render.py
+++ b/skills/last30days/scripts/lib/render.py
@@ -355,7 +355,20 @@ def _render_ranked_clusters(
)
if cluster.uncertainty:
lines.append(f"- Uncertainty: {cluster.uncertainty}")
- for rep_index, candidate_id in enumerate(cluster.representative_ids, start=1):
+ representative_ids = [
+ candidate_id
+ for candidate_id in cluster.representative_ids
+ if candidate_id in candidate_by_id
+ and _best_take_relevance_ok(candidate_by_id[candidate_id])
+ ]
+ if not representative_ids:
+ representative_ids = [
+ candidate_id
+ for candidate_id in cluster.candidate_ids
+ if candidate_id in candidate_by_id
+ and _best_take_relevance_ok(candidate_by_id[candidate_id])
+ ][:1]
+ for rep_index, candidate_id in enumerate(representative_ids, start=1):
candidate = candidate_by_id.get(candidate_id)
if not candidate:
continue
@@ -371,10 +384,11 @@ def _clusters_clearing_relevance_floor(
"""Return visible clusters with positive, non-entity-miss evidence.
A zero-score cluster is diagnostic retrieval residue rather than evidence.
- Likewise, a positive cluster whose known representatives are all explicitly
- entity-miss-demoted must not be promoted by engagement into the synthesis.
- Missing representative records are not treated as a miss: score remains the
- only signal available in that defensive edge case.
+ Likewise, a positive cluster with known members but no qualifying member
+ must not be promoted by engagement into the synthesis. Every cluster member
+ is considered because MMR representatives can omit valid evidence. Missing
+ member records are not treated as misses: score remains the only signal
+ available when no member record is present.
"""
candidate_by_id = {
candidate.candidate_id: candidate for candidate in report.ranked_candidates
@@ -383,15 +397,12 @@ def _clusters_clearing_relevance_floor(
for cluster in clusters:
if cluster.score <= 0:
continue
- representatives = [
+ members = [
candidate_by_id[candidate_id]
- for candidate_id in cluster.representative_ids
+ for candidate_id in cluster.candidate_ids
if candidate_id in candidate_by_id
]
- if representatives and all(
- "entity-miss" in (candidate.explanation or "").lower()
- for candidate in representatives
- ):
+ if members and not any(_best_take_relevance_ok(candidate) for candidate in members):
continue
solid.append(cluster)
return solid
diff --git a/skills/last30days/scripts/lib/rerank.py b/skills/last30days/scripts/lib/rerank.py
index 255bb299..eb2290a7 100644
--- a/skills/last30days/scripts/lib/rerank.py
+++ b/skills/last30days/scripts/lib/rerank.py
@@ -24,6 +24,7 @@ ENTITY_MISS_PENALTY = 25.0
# project mode carry a high local-relevance floor and therefore escape this
# visibility gate even when their short title omits the user's wording.
FALLBACK_ENTITY_MISS_CONFIDENCE_ESCAPE = 0.5
+FALLBACK_ENTITY_MISS_TOPIC_ESCAPE = 0.25
_FALLBACK_ENTITY_MISS_EXPLANATION = "fallback-local-score (entity-miss demotion)"
# Small additive credit for a post authored by one of the run's resolved
@@ -679,9 +680,11 @@ def prune_fallback_entity_misses(
Broad recommendation queries can be misread as one long primary entity,
causing every fallback candidate to receive the entity-miss marker. The
marker alone is therefore not a safe filter. A candidate is removed only
- when it also has no lexical overlap with the stable raw topic and lacks a
- strong local-relevance signal from an explicitly scoped retrieval path.
- Source items remain in the report's diagnostic source dump.
+ when its stable title and snippet do not clear a meaningful raw-topic
+ relevance floor and it lacks a strong local-relevance signal from an
+ explicitly scoped retrieval path. Comments and transcripts are excluded
+ from this escape because incidental words there do not ground the candidate
+ itself. Source items remain in the report's diagnostic source dump.
"""
if not topic:
return candidates
@@ -694,7 +697,11 @@ def prune_fallback_entity_misses(
if candidate.local_relevance >= FALLBACK_ENTITY_MISS_CONFIDENCE_ESCAPE:
kept.append(candidate)
continue
- if relevance.token_overlap_relevance(topic, _candidate_haystack(candidate)) > 0.0:
+ primary_text = f"{candidate.title or ''} {candidate.snippet or ''}"
+ if (
+ relevance.token_overlap_relevance(topic, primary_text)
+ >= FALLBACK_ENTITY_MISS_TOPIC_ESCAPE
+ ):
kept.append(candidate)
return kept
diff --git a/tests/test_render_v3.py b/tests/test_render_v3.py
index 4486e39e..9a5ea1ca 100644
--- a/tests/test_render_v3.py
+++ b/tests/test_render_v3.py
@@ -1,3 +1,4 @@
+import copy
import unittest
from lib import render, schema
@@ -161,6 +162,28 @@ class RenderV3Tests(unittest.TestCase):
self.assertIn("**Nothing solid this window.**", text)
self.assertNotIn("### 1. Grounded result", text)
+ def test_qualifying_nonrepresentative_preserves_cluster_and_becomes_visible(self):
+ report = sample_report()
+ missed_representative = report.ranked_candidates[0]
+ missed_representative.final_score = 14
+ missed_representative.explanation = (
+ "fallback-local-score (entity-miss demotion)"
+ )
+ qualifying_member = copy.deepcopy(missed_representative)
+ qualifying_member.candidate_id = "c2"
+ qualifying_member.title = "Solid nonrepresentative evidence"
+ qualifying_member.final_score = 72
+ qualifying_member.explanation = "high-signal result"
+ report.ranked_candidates.append(qualifying_member)
+ report.clusters[0].candidate_ids.append("c2")
+ report.clusters[0].score = 72
+
+ text = render.render_compact(report)
+
+ self.assertNotIn("**Nothing solid this window.**", text)
+ self.assertIn("### 1. Grounded result", text)
+ self.assertIn("Solid nonrepresentative evidence", text)
+
class OutputEnvelopeTests(unittest.TestCase):
"""LAW 6 envelope comments: scope "pass through verbatim" unambiguously.
diff --git a/tests/test_rerank_v3.py b/tests/test_rerank_v3.py
index 6080e10c..700529ec 100644
--- a/tests/test_rerank_v3.py
+++ b/tests/test_rerank_v3.py
@@ -348,13 +348,40 @@ class FallbackVisibilityTests(unittest.TestCase):
local_relevance=0.2,
explanation="fallback-local-score",
)
+ incidental_metadata = self._candidate(
+ title="A completely unrelated film discussion",
+ snippet="No connection to the requested workflow.",
+ local_relevance=0.38,
+ explanation="fallback-local-score (entity-miss demotion)",
+ source="reddit",
+ )
+ incidental_metadata.metadata = {
+ "transcript_snippet": "One speaker briefly says agents.",
+ "top_comments": [{"excerpt": "Execution was the best part."}],
+ }
+ generic_title = self._candidate(
+ title="Best starship story this month",
+ snippet="A boy builds a fleet from scrap.",
+ local_relevance=0.38,
+ explanation="fallback-local-score (entity-miss demotion)",
+ source="x",
+ )
kept = rerank.prune_fallback_entity_misses(
- [starship, adjacent, scoped_project, ordinary_fallback],
+ [
+ starship,
+ adjacent,
+ scoped_project,
+ ordinary_fallback,
+ incidental_metadata,
+ generic_title,
+ ],
topic=self.topic,
)
self.assertNotIn(starship, kept)
+ self.assertNotIn(incidental_metadata, kept)
+ self.assertNotIn(generic_title, kept)
self.assertIn(adjacent, kept)
self.assertIn(scoped_project, kept)
self.assertIn(ordinary_fallback, kept)