Why-it-belongs: top-up requires all three fields (idempotency fix)

Per Codex: generate_summary treated why_belongs alone as a complete explanation,
but get_explanation requires all three — so a partial older row (e.g. only
why_belongs) would never top up and the page would fall back forever. Now the
fully-cached check requires summary + what_happened + why_matters + why_belongs.
Test covers the partial-row top-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
jay
2026-06-09 20:10:27 -04:00
parent 337dc3f901
commit 008364e922
2 changed files with 30 additions and 3 deletions
+6 -3
View File
@@ -136,10 +136,13 @@ def generate_summary(conn: sqlite3.Connection, article_id: int, client: LocalMod
explanation is topped up on the next call (so existing pages gain the section).
"""
existing = conn.execute(
"SELECT summary, why_belongs FROM article_summaries WHERE article_id = ?", (article_id,)
"SELECT summary, what_happened, why_matters, why_belongs FROM article_summaries WHERE article_id = ?",
(article_id,),
).fetchone()
if existing and existing["summary"] and existing["why_belongs"]:
return existing["summary"] # summary + a complete explanation already cached
# Fully cached only when the explanation is COMPLETE (all three) — matches
# get_explanation(), so a partial older row gets topped up on the next call.
if existing and existing["summary"] and existing["what_happened"] and existing["why_matters"] and existing["why_belongs"]:
return existing["summary"]
row = conn.execute(
"SELECT a.title, a.description, a.canonical_url, a.duplicate_of, s.accepted "
"FROM articles a LEFT JOIN article_scores s ON s.article_id = a.id WHERE a.id = ?",