fix(evidence): preserve legacy formula migration boundaries

This commit is contained in:
2026-08-25 01:28:54 +02:00
parent cc30148b69
commit dcb5acc312
4 changed files with 135 additions and 27 deletions
+13 -4
View File
@@ -64,11 +64,17 @@ def _formula_proposals(decisions: list["DecisionRecord"], linking: "SchemaLinkin
A proposal remains in the persisted session artifact until a separate curator
imports, reviews, and publishes it in the workspace repository.
"""
approved = {
decision.detail: decision.seq
retracted = {
decision.retracts
for decision in decisions
if decision.type == "concept_formula_approved" and decision.detail
if decision.type == "decision_retracted" and decision.retracts is not None
}
latest_f4_decision = {}
for decision in sorted(decisions, key=lambda item: item.seq):
if decision.seq in retracted or decision.subject != "phase:4" or not decision.detail:
continue
if decision.type in {"concept_formula_approved", "concept_formula_rejected"}:
latest_f4_decision[decision.detail] = decision
proposals = []
for formula in linking.concept_formulas:
if not isinstance(formula, dict):
@@ -83,6 +89,9 @@ def _formula_proposals(decisions: list["DecisionRecord"], linking: "SchemaLinkin
evidence_id = formula.get("evidence_id", formula.get("id", ""))
if isinstance(evidence_id, str) and evidence_id.startswith("evidence:"):
continue
decision = latest_f4_decision.get(concept)
if decision is None or decision.type != "concept_formula_approved":
continue
proposals.append({
"schema_version": 1,
"kind": "formula_proposal",
@@ -91,7 +100,7 @@ def _formula_proposals(decisions: list["DecisionRecord"], linking: "SchemaLinkin
"columns": columns,
"sql": sql,
"sources": formula.get("sources", []),
"decision_seq": approved.get(concept),
"decision_seq": decision.seq,
})
return proposals