feat: make default fun level actually surface comedy (#272)

Most users never touch FUN_LEVEL. Default medium was shipping a stats
block but rarely a Best Takes block, and when it did it was below the
cluster fold where a synthesizing model had already stopped reading.
A 2,304-upvote Reddit comment ("WHAT?! I reached my monthly limit
just reading this post") on the 2026-04-17 Opus 4.7 run sat inside
cluster 11 and never made it into synthesis. Four coordinated changes:

1. render: promote Best Takes above the cluster list so the synthesizer
   sees comedy before it anchors on cluster 1.
2. render: lower medium threshold from 70 to 55 (heuristic maxes at 80),
   drop the two-gem floor to one-gem. Default now reliably emits the
   block on typical runs.
3. rerank: score individual top_comments by upvote ratio to their parent
   thread. A 2,304-upvote comment on a 300-upvote thread now outranks a
   400-upvote comment on a 3,400-upvote thread, which is the viral-wit
   signal. Handles both the LLM scoring path and the heuristic fallback.
4. render: merge scored comment gems into Best Takes alongside candidate
   gems, sorted together. Comment lines show body + parent title +
   r/subreddit or @handle + absolute upvotes.
5. SKILL: tell the synthesizer to quote at least two Best Takes entries
   verbatim, with an example of the new comment format.

Plan: docs/plans/2026-04-17-001-feat-default-fun-surfacing-plan.md

🤖 Generated with Claude Opus 4.7 (1M context) via [Claude Code](https://claude.com/claude-code) + Compound Engineering v2.56.1

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Van Horn
2026-04-17 08:30:39 -04:00
committed by GitHub
parent 0103324701
commit bad1d312ef
5 changed files with 350 additions and 37 deletions
+113 -4
View File
@@ -387,15 +387,124 @@ class RenderBestTakesCompactTests(unittest.TestCase):
text = render.render_compact(report)
self.assertNotIn("## Best Takes", text)
def test_no_best_takes_with_1_high_fun_candidate(self):
"""No Best Takes section when only 1 candidate above threshold."""
def test_best_takes_with_1_high_fun_candidate(self):
"""Best Takes section appears even with only 1 candidate above threshold.
The single-gem floor means a single viral quote is enough to show the block,
which is essential for the default medium level on most research topics.
"""
candidates = [
self._make_candidate("c1", fun_score=80),
self._make_candidate("c2", fun_score=50),
self._make_candidate("c2", fun_score=40),
]
report = self._make_report_with_candidates(candidates)
text = render.render_compact(report)
self.assertNotIn("## Best Takes", text)
self.assertIn("## Best Takes", text)
self.assertIn("(fun:80)", text)
def test_best_takes_renders_above_clusters(self):
"""Best Takes section appears before the Ranked Evidence Clusters header."""
candidates = [
self._make_candidate("c1", fun_score=85),
self._make_candidate("c2", fun_score=75),
]
report = self._make_report_with_candidates(candidates)
text = render.render_compact(report)
self.assertLess(text.index("## Best Takes"), text.index("## Ranked Evidence Clusters"))
def test_comment_level_gem_appears_in_best_takes(self):
"""A high-fun top_comment on a low-fun parent candidate still qualifies."""
item = schema.SourceItem(
item_id="item-c1",
source="reddit",
title="Post c1",
body="Body.",
url="https://reddit.com/r/test/comments/c1/",
container="test",
published_at="2026-03-15",
date_confidence="high",
engagement={"score": 300, "num_comments": 30},
metadata={
"top_comments": [{
"body": "WHAT?! I reached my monthly limit just reading this post",
"excerpt": "WHAT?! I reached my monthly limit just reading this post",
"score": 2304,
"fun_score": 88.0,
}],
},
)
candidate = schema.Candidate(
candidate_id="c1",
item_id="item-c1",
source="reddit",
title="Post c1",
url="https://reddit.com/r/test/comments/c1/",
snippet="",
subquery_labels=["primary"],
native_ranks={"primary:reddit": 1},
local_relevance=0.9,
freshness=90,
engagement=88,
source_quality=1.0,
rrf_score=0.02,
rerank_score=92,
final_score=90,
sources=["reddit"],
source_items=[item],
fun_score=35.0, # parent below threshold
)
report = self._make_report_with_candidates([candidate])
text = render.render_compact(report)
self.assertIn("## Best Takes", text)
self.assertIn("WHAT?! I reached my monthly limit", text)
self.assertIn("2,304", text)
self.assertIn("r/test", text)
self.assertIn('in "Post c1"', text)
def test_comment_and_candidate_gems_sorted_by_fun_score(self):
"""Higher fun score comes first, regardless of whether it's a candidate or a comment."""
item = schema.SourceItem(
item_id="item-c1",
source="reddit",
title="Post c1",
body="Body.",
url="https://reddit.com/r/test/comments/c1/",
container="test",
engagement={"score": 100},
metadata={
"top_comments": [{
"body": "higher-ranked comment",
"score": 800,
"fun_score": 90.0,
}],
},
)
comment_candidate = schema.Candidate(
candidate_id="cc",
item_id="item-c1",
source="reddit",
title="Parent thread title",
url="https://reddit.com/r/test/comments/c1/",
snippet="",
subquery_labels=["primary"],
native_ranks={"primary:reddit": 1},
local_relevance=0.9,
freshness=90,
engagement=10,
source_quality=1.0,
rrf_score=0.02,
sources=["reddit"],
source_items=[item],
fun_score=30.0,
)
lower_candidate = self._make_candidate("cl", fun_score=70)
report = self._make_report_with_candidates([comment_candidate, lower_candidate])
text = render.render_compact(report)
comment_pos = text.find("higher-ranked comment")
lower_pos = text.find("(fun:70)")
self.assertNotEqual(comment_pos, -1)
self.assertNotEqual(lower_pos, -1)
self.assertLess(comment_pos, lower_pos)
if __name__ == "__main__":
+92 -1
View File
@@ -9,7 +9,12 @@ SCRIPTS_DIR = Path(__file__).parent.parent / "scripts"
sys.path.insert(0, str(SCRIPTS_DIR))
from lib import schema
from lib.rerank import _apply_single_fun_fallback, _extract_comment_text
from lib.rerank import (
_apply_fun_fallback,
_apply_single_fun_fallback,
_extract_comment_text,
_score_comments_per_candidate,
)
def _make_candidate(
@@ -17,10 +22,12 @@ def _make_candidate(
snippet: str = "",
engagement: float | None = 0.0,
top_comments: list[dict] | None = None,
parent_raw_engagement: int | None = None,
) -> schema.Candidate:
"""Build a minimal Candidate with optional source_items carrying top_comments."""
source_items = []
if top_comments is not None:
item_engagement = {"score": parent_raw_engagement} if parent_raw_engagement is not None else {}
source_items.append(
schema.SourceItem(
item_id="si-1",
@@ -28,6 +35,7 @@ def _make_candidate(
title=title,
body="",
url="https://reddit.com/r/test/1",
engagement=item_engagement,
metadata={"top_comments": top_comments},
)
)
@@ -112,6 +120,89 @@ class TestFunFallbackCommentText:
assert candidate.fun_explanation == "heuristic-fallback"
class TestScoreCommentsPerCandidate:
"""Per-comment fun scoring: high-ratio viral comments outrank absolute-high comments on dominant threads."""
def test_high_ratio_comment_outranks_low_ratio(self):
"""A 2304-upvote comment on a 300-upvote parent should score higher than
a 400-upvote comment on a 3400-upvote parent (high ratio = viral wit)."""
viral = _make_candidate(
parent_raw_engagement=300,
top_comments=[{"body": "WHAT?! I reached my monthly limit just reading this post", "score": 2304}],
)
average = _make_candidate(
parent_raw_engagement=3400,
top_comments=[{"body": "we can't trust benchmarks anymore and need to re-run them", "score": 400}],
)
_score_comments_per_candidate(viral)
_score_comments_per_candidate(average)
viral_score = viral.source_items[0].metadata["top_comments"][0]["fun_score"]
average_score = average.source_items[0].metadata["top_comments"][0]["fun_score"]
assert viral_score > average_score
def test_2304_upvote_comment_on_small_parent_crosses_medium_threshold(self):
"""The exact Opus 4.7 case: the comment should score >= 55 (medium threshold)."""
candidate = _make_candidate(
parent_raw_engagement=300,
top_comments=[{
"body": "WHAT?! I reached my monthly limit just reading this post",
"score": 2304,
}],
)
_score_comments_per_candidate(candidate)
comment = candidate.source_items[0].metadata["top_comments"][0]
assert comment["fun_score"] >= 55.0
def test_reddit_excerpt_field_also_works(self):
"""Reddit uses 'excerpt' not 'body'. The scorer must handle that."""
candidate = _make_candidate(
parent_raw_engagement=100,
top_comments=[{"excerpt": "bruh this is gold", "score": 500}],
)
_score_comments_per_candidate(candidate)
comment = candidate.source_items[0].metadata["top_comments"][0]
assert "fun_score" in comment
assert comment["fun_score"] > 0
def test_no_parent_upvotes_does_not_crash(self):
"""A candidate without parent engagement still scores comments via the absolute-upvote fallback."""
candidate = _make_candidate(
parent_raw_engagement=None,
top_comments=[{"body": "lmao", "score": 200}],
)
_score_comments_per_candidate(candidate)
comment = candidate.source_items[0].metadata["top_comments"][0]
assert "fun_score" in comment
def test_malformed_comments_skipped(self):
"""Non-dict entries and missing-body entries are skipped without raising."""
candidate = _make_candidate(
parent_raw_engagement=500,
top_comments=[
"not a dict", # malformed, still counts toward the top-3 window
{"body": "", "score": 10}, # empty body within window
{"body": "valid", "score": 50}, # valid within window
],
)
_score_comments_per_candidate(candidate)
comments = candidate.source_items[0].metadata["top_comments"]
# Only the valid one gets a fun_score
valid = [c for c in comments if isinstance(c, dict) and c.get("fun_score") is not None]
assert len(valid) == 1
assert valid[0]["body"] == "valid"
def test_score_comments_runs_after_fallback(self):
"""_apply_fun_fallback wires in comment scoring automatically."""
candidate = _make_candidate(
parent_raw_engagement=300,
top_comments=[{"body": "bro what 😭", "score": 1500}],
)
_apply_fun_fallback([candidate])
comment = candidate.source_items[0].metadata["top_comments"][0]
assert "fun_score" in comment
assert candidate.fun_score is not None
class TestExtractCommentText:
"""Verify _extract_comment_text handles edge cases."""