fix(learning): process_final_version מאחסן דיסטילציה גם כשאין pair (INV-LRN4, #125.1) #196

Merged
chaim merged 1 commits from worktree-learning-loop-ops into main 2026-06-11 17:09:11 +00:00

View File

@@ -149,14 +149,28 @@ async def process_final_version(
# it (→ decision_lessons / appeal_type_rules, surfaced by T15) via the gate. # it (→ decision_lessons / appeal_type_rules, surfaced by T15) via the gate.
# (Previously this auto-upserted every new_expression as a style_pattern — # (Previously this auto-upserted every new_expression as a style_pattern —
# that both bypassed the gate and contaminated style with substance. Removed.) # that both bypassed the gate and contaminated style with substance. Removed.)
if pair_id is not None: #
await db.update_draft_final_pair( # create-or-update (INV-LRN4): normally mark-final already opened a
UUID(str(pair_id)), # 'final_received' pair, so we just advance it. For a case whose final
final_text=final_text, # pre-dates the mark-final snapshot mechanism (historical backfill) or a direct
diff_stats=diff_stats, # ingest_final_version call, no pair exists — open one now from the live blocks
analysis=analysis, # so the distillation is actually persisted instead of silently discarded.
status="analyzed", # Caveat: the captured draft is the CURRENT blocks (possibly edited after
# sign-off), not a true mark-final snapshot.
if pair_id is None:
pair_id = await db.create_draft_final_pair(case_id, draft_text, "")
logger.info(
"process_final_version: no 'final_received' pair for case %s — opened one "
"from live blocks (backfill path; draft may post-date sign-off)",
case_id,
) )
await db.update_draft_final_pair(
UUID(str(pair_id)),
final_text=final_text,
diff_stats=diff_stats,
analysis=analysis,
status="analyzed",
)
# Update decision + case status # Update decision + case status
await db.update_decision(UUID(decision["id"]), status="final") await db.update_decision(UUID(decision["id"]), status="final")