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:
@@ -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."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user