feat(digests): self-heal drain — auto-resume after quota/interruption (X12) #127

Merged
chaim merged 1 commits from worktree-digest-resume into main 2026-06-07 21:00:18 +00:00
Showing only changes of commit 3ae183009f - Show all commits

View File

@@ -36,6 +36,20 @@ CONCURRENCY = int(os.environ.get("DIGEST_DRAIN_CONCURRENCY", "3"))
async def main() -> int:
pool = await db.get_pool()
# Self-heal: an enrich that failed mid-LLM (e.g. the local claude
# subscription window was exhausted) can leave a row 'completed' with no
# concept_tag AND no underlying_citation — a real digest always extracts at
# least a citation, so "both empty" means the extraction never landed. Reset
# those to 'pending' so the next run retries (idempotent auto-resume). Safe:
# successfully-enriched rows always have a concept_tag or citation.
healed = await pool.execute(
"UPDATE digests SET extraction_status = 'pending' "
"WHERE extraction_status = 'completed' "
"AND coalesce(concept_tag,'') = '' AND coalesce(underlying_citation,'') = '' "
"AND coalesce(analysis_text,'') <> ''"
)
if healed and healed != "UPDATE 0":
print(f"self-heal: reset failed-empty digests → pending ({healed})", flush=True)
rows = await pool.fetch(
"SELECT id FROM digests WHERE extraction_status = 'pending' ORDER BY created_at"
)