scripts/verify_iip0041_clinical_h1_cd64t_siglec.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0041_clinical_h1_cd64t_siglec.py · SHA-256: f004cf6d8259b8b4…
r_r10_zero = evaluate_gate28a_h1_promotion(p_r10_zero, trusted_clinical_store=r10_store)
r10_resc_base60 = [
{
"recipient_id": f"R{lot:02d}-{rep}",
"lot_id": f"L{lot:02d}",
"mcb_id": f"M{lot // 3}",
"followup_months": 12,
"met_c2b_criteria": True,
"intercurrent_event": "NONE",
}
for lot in range(15)
for rep in range(4)
]
r10_resc_bank_map = {r["lot_id"]: r["mcb_id"] for r in r10_resc_base60}
r10_resc1 = copy.deepcopy(r10_resc_base60)
r10_resc1[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_lot_id="RA")
r10_resc1_rows = _derive_reconciling_cmc_lot_ledger_from_recipients(r10_resc1, r10_resc_bank_map)
r10_resc2_rows = copy.deepcopy(r10_resc1_rows) + [{
"lot_id": "RB", "mcb_id": "M0", "lot_type": "RESCUE_REPEAT_LOT",
"disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1,
"rescued_recipient_id": "R00-0", "rescued_primary_lot_id": "L00",
"recipient_outcomes": {"R00-0": True},
}]
p_r10_one_ok, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_resc1, cohort_id="COHORT-R10-RESC-1-OK",
lot_to_mcb_manifest={**r10_resc_bank_map, "RA": "M0"}, parallel_cmc_lot_ledger=r10_resc1_rows,
)
r_r10_one_ok = evaluate_gate28a_h1_promotion(p_r10_one_ok, trusted_clinical_store=r10_store)
# Extra CMC rescue RB omitted from clinical cohort (clinical=['RA'] vs CMC=['RA','RB'], both in manifest) -> HOLD!
p_r10_extra_rb, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_resc1, cohort_id="COHORT-R10-RESC-EXTRA-RB",
lot_to_mcb_manifest={**r10_resc_bank_map, "RA": "M0", "RB": "M0"}, parallel_cmc_lot_ledger=r10_resc2_rows,
)
r_r10_extra_rb = evaluate_gate28a_h1_promotion(p_r10_extra_rb, trusted_clinical_store=r10_store)
# Exact-match 2 rescues: clinical rescue_lot_ids=['RA','RB'] vs CMC=['RA','RB'] -> PROMOTE!
r10_resc2_clin = copy.deepcopy(r10_resc_base60)
r10_resc2_clin[0].update(intercurrent_event="RESCUE_REPEAT_INFUSION", rescue_lot_ids=["RA", "RB"])
p_r10_two_ok, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_resc2_clin, cohort_id="COHORT-R10-RESC-2-OK",
lot_to_mcb_manifest={**r10_resc_bank_map, "RA": "M0", "RB": "M0"}, parallel_cmc_lot_ledger=r10_resc2_rows,
)
r_r10_two_ok = evaluate_gate28a_h1_promotion(p_r10_two_ok, trusted_clinical_store=r10_store)
# Clinical declares 2 rescues ['RA','RB'] while CMC has only ['RA'] -> HOLD!
p_r10_two_vs_one, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_resc2_clin, cohort_id="COHORT-R10-RESC-2-VS-1",
lot_to_mcb_manifest={**r10_resc_bank_map, "RA": "M0", "RB": "M0"}, parallel_cmc_lot_ledger=r10_resc1_rows,
)
r_r10_two_vs_one = evaluate_gate28a_h1_promotion(p_r10_two_vs_one, trusted_clinical_store=r10_store)
# Unindexed clinical rescue (ie_only) vs 2 CMC rescues ['RA','RB'] -> HOLD!
r10_resc_ie_only = copy.deepcopy(r10_resc_base60)
r10_resc_ie_only[0]["intercurrent_event"] = "RESCUE_REPEAT_INFUSION"
p_r10_ie_vs_two, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_resc_ie_only, cohort_id="COHORT-R10-RESC-IE-VS-2",
lot_to_mcb_manifest={**r10_resc_bank_map, "RA": "M0", "RB": "M0"}, parallel_cmc_lot_ledger=r10_resc2_rows,
)
r_r10_ie_vs_two = evaluate_gate28a_h1_promotion(p_r10_ie_vs_two, trusted_clinical_store=r10_store)
# Duplicate identical RA rescue row in CMC -> fails closed with DUPLICATE_LOT_ID_IN_CMC_LEDGER!
r10_dup_ra_rows = copy.deepcopy(r10_resc1_rows) + [{
"lot_id": "RA", "mcb_id": "M0", "lot_type": "RESCUE_REPEAT_LOT",
"disposition": "RELEASED_INFUSED", "planned_doses_n": 1, "infused_doses_n": 1,
"rescued_recipient_id": "R00-0", "rescued_primary_lot_id": "L00",
"recipient_outcomes": {"R00-0": True},
}]
p_r10_dup_ra, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_resc1, cohort_id="COHORT-R10-RESC-DUP-RA",
lot_to_mcb_manifest={**r10_resc_bank_map, "RA": "M0"}, parallel_cmc_lot_ledger=r10_dup_ra_rows,
)
r_r10_dup_ra = evaluate_gate28a_h1_promotion(p_r10_dup_ra, trusted_clinical_store=r10_store)
if not (
r_r10_zero["status"] == "PROMOTE_H1_88_TO_90"
and r_r10_zero["promotion_authorized"] is True
and r_r10_one_ok["status"] == "PROMOTE_H1_88_TO_90"
and r_r10_one_ok["promotion_authorized"] is True
and r_r10_one_ok["parallel_cmc_ledger_verified"] is True
and r_r10_extra_rb["status"] == "HOLD_H1_AT_88PCT"
and r_r10_extra_rb["promotion_authorized"] is False
and r_r10_extra_rb["parallel_cmc_ledger_verified"] is False
and any("CMC_EXTRA_RESCUE_LOT_OMITTED_FROM_CLINICAL_COHORT" in fr for fr in r_r10_extra_rb["failure_reasons"])
and any("RESCUE_LOT_CARDINALITY_MISMATCH" in fr for fr in r_r10_extra_rb["failure_reasons"])
and r_r10_two_ok["status"] == "PROMOTE_H1_88_TO_90"
and r_r10_two_ok["promotion_authorized"] is True
and r_r10_two_ok["parallel_cmc_ledger_verified"] is True
and r_r10_two_ok["parallel_cmc_readiness_summary"]["attempted_lots_n"] == 17
and r_r10_two_ok["parallel_cmc_readiness_summary"]["rescue_lots_n"] == 2
and r_r10_two_vs_one["status"] == "HOLD_H1_AT_88PCT"
and r_r10_two_vs_one["promotion_authorized"] is False
and r_r10_two_vs_one["parallel_cmc_ledger_verified"] is False
and any("RESCUE_LOT_CARDINALITY_MISMATCH" in fr for fr in r_r10_two_vs_one["failure_reasons"])
and r_r10_ie_vs_two["status"] == "HOLD_H1_AT_88PCT"
and r_r10_ie_vs_two["promotion_authorized"] is False
and r_r10_ie_vs_two["parallel_cmc_ledger_verified"] is False
and any("CMC_EXTRA_RESCUE_LOT_OMITTED_FROM_CLINICAL_COHORT" in fr for fr in r_r10_ie_vs_two["failure_reasons"])
and r_r10_dup_ra["status"] == "HOLD_H1_AT_88PCT"
and r_r10_dup_ra["promotion_authorized"] is False
and r_r10_dup_ra["parallel_cmc_ledger_verified"] is False
and r_r10_dup_ra["lot_bank_hierarchy_valid"] is False
and r_r10_dup_ra["deff"] is None
):
raise ValueError(
f"R10 B1 exact rescue identity/cardinality checks failed: zero={r_r10_zero}, one={r_r10_one_ok}, "
f"extra_rb={r_r10_extra_rb}, two_ok={r_r10_two_ok}, two_vs_one={r_r10_two_vs_one}, "
f"ie_vs_two={r_r10_ie_vs_two}, dup_ra={r_r10_dup_ra}"
)
cases.append({"case": "b1_r10_gate28a_exact_bidirectional_rescue_identity_and_cardinality_0_1_2_enforced", "passed": True})
# 51. R10 B2a: Pass-0 unconditional clinical ancestry catches cross-MCB swap masked by missing followup_months
# (and missing met_c2b_criteria) and unconditionally clears ALL 4 flags + nullifies deff/n_eff/k_eff!
r10_obs_wcb = copy.deepcopy(r10_plain60)
for row_w in r10_obs_wcb:
if row_w["lot_id"] == "L00":
row_w["wcb_id"] = "W0"
r10_annot_rows = copy.deepcopy(r10_plain_rows)
r10_annot_rows[0]["wcb_id"] = "W0"
r10_swapped_rows = copy.deepcopy(r10_annot_rows)
for row_idx_s, old_rid, new_rid in ((0, "R00-0", "R05-0"), (5, "R05-0", "R00-0")):
srow = r10_swapped_rows[row_idx_s]
srow["recipient_outcomes"][new_rid] = srow["recipient_outcomes"].pop(old_rid)
srow["recipient_ids"] = [new_rid if rid_x == old_rid else rid_x for rid_x in srow["recipient_ids"]]
r10_both_nofu = copy.deepcopy(r10_obs_wcb)
r10_both_nofu[0]["followup_months"] = None
r10_both_nofu[20]["followup_months"] = None
p_r10_swap_nofu, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_both_nofu, cohort_id="COHORT-R10-SWAP-NOFU",
lot_to_mcb_manifest=r10_bank_map, lot_to_wcb_manifest={"L00": "W0"},
parallel_cmc_lot_ledger=r10_swapped_rows,
)
r_r10_swap_nofu = evaluate_gate28a_h1_promotion(p_r10_swap_nofu, trusted_clinical_store=r10_store)
r10_both_noc2b = copy.deepcopy(r10_obs_wcb)
r10_both_noc2b[0]["met_c2b_criteria"] = None
r10_both_noc2b[20]["intercurrent_event"] = "INVALID_IE"
p_r10_swap_noc2b, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_both_noc2b, cohort_id="COHORT-R10-SWAP-NOC2B",
lot_to_mcb_manifest=r10_bank_map, lot_to_wcb_manifest={"L00": "W0"},
parallel_cmc_lot_ledger=r10_swapped_rows,
)
r_r10_swap_noc2b = evaluate_gate28a_h1_promotion(p_r10_swap_noc2b, trusted_clinical_store=r10_store)
for lbl_sw10, res_sw10 in (("missing_followup", r_r10_swap_nofu), ("invalid_outcome_and_ie", r_r10_swap_noc2b)):
if not (
res_sw10["status"] == "HOLD_H1_AT_88PCT"
and res_sw10["promotion_authorized"] is False
and res_sw10["parallel_cmc_ledger_verified"] is False
and res_sw10["lot_bank_hierarchy_valid"] is False
and res_sw10["lot_to_mcb_manifest_verified"] is False
and res_sw10["lot_to_wcb_manifest_verified"] is False
and res_sw10["deff"] is None
and res_sw10["n_eff"] is None
and res_sw10["k_eff"] is None
and any("CMC_ROW_ANCESTRY_CONFLICTS_WITH_VERIFIED_MANIFEST" in fr for fr in res_sw10["failure_reasons"])
):
raise ValueError(f"R10 B2a cross-MCB swap ({lbl_sw10}) MUST invalidate all 4 flags + null cluster outputs: {res_sw10}")
cases.append({"case": "b2a_r10_gate28a_pass0_cross_mcb_swap_masked_by_missing_followup_invalidates_ancestry", "passed": True})
# 52. R10 B2b: Pass-0 catches conflicting duplicate clinical recipient rows (both conflicting bank M9 and cross-lot L05/M1)!
r10_dupe_m9 = copy.deepcopy(r10_obs_wcb)
r10_dupe_m9.append({**r10_dupe_m9[0], "mcb_id": "M9"})
p_r10_dupe_m9, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_dupe_m9, cohort_id="COHORT-R10-DUPE-M9",
lot_to_mcb_manifest=r10_bank_map, lot_to_wcb_manifest={"L00": "W0"},
parallel_cmc_lot_ledger=r10_annot_rows,
)
r_r10_dupe_m9 = evaluate_gate28a_h1_promotion(p_r10_dupe_m9, trusted_clinical_store=r10_store)
r10_dupe_crosslot = copy.deepcopy(r10_obs_wcb)
r10_dupe_crosslot.append({**r10_dupe_crosslot[0], "lot_id": "L05", "mcb_id": "M1", "wcb_id": None})
p_r10_dupe_xlot, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_dupe_crosslot, cohort_id="COHORT-R10-DUPE-XLOT",
lot_to_mcb_manifest=r10_bank_map, lot_to_wcb_manifest={"L00": "W0"},
parallel_cmc_lot_ledger=r10_annot_rows,
)
r_r10_dupe_xlot = evaluate_gate28a_h1_promotion(p_r10_dupe_xlot, trusted_clinical_store=r10_store)
for lbl_dp10, res_dp10 in (("same_lot_m9", r_r10_dupe_m9), ("cross_lot_l05_m1", r_r10_dupe_xlot)):
if not (
res_dp10["status"] == "HOLD_H1_AT_88PCT"
and res_dp10["promotion_authorized"] is False
and res_dp10["parallel_cmc_ledger_verified"] is False
and res_dp10["lot_bank_hierarchy_valid"] is False
and res_dp10["lot_to_mcb_manifest_verified"] is False
and res_dp10["lot_to_wcb_manifest_verified"] is False
and res_dp10["deff"] is None
and res_dp10["n_eff"] is None
and res_dp10["k_eff"] is None
and any("CONFLICTING_DUPLICATE_RECIPIENT_ANCESTRY" in fr for fr in res_dp10["failure_reasons"])
):
raise ValueError(f"R10 B2b conflicting duplicate clinical recipient ({lbl_dp10}) MUST invalidate all 4 flags + null cluster outputs: {res_dp10}")
cases.append({"case": "b2b_r10_gate28a_pass0_conflicting_duplicate_clinical_recipient_invalidates_ancestry", "passed": True})
# 53. R10 B2c: Pass-0-backed error-path audit catches cross-MCB mismatch masked by BOTH missing followup_months
# AND an unrelated CMC record-shape failure!
r10_bad_rows = copy.deepcopy(r10_plain_rows)
r10_bad_rows[0]["recipient_outcomes"].pop("R00-0")
r10_bad_rows[0]["recipient_outcomes"]["R05-0"] = True
r10_bad_rec = copy.deepcopy(r10_plain60)
r10_bad_rec[20]["followup_months"] = None
p_r10_mask_err, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_bad_rec, cohort_id="COHORT-R10-MASK-ERRPATH",
lot_to_mcb_manifest=r10_bank_map, parallel_cmc_lot_ledger=r10_bad_rows,
)
r_r10_mask_err = evaluate_gate28a_h1_promotion(p_r10_mask_err, trusted_clinical_store=r10_store)
if not (
r_r10_mask_err["status"] == "HOLD_H1_AT_88PCT"
and r_r10_mask_err["promotion_authorized"] is False
and r_r10_mask_err["parallel_cmc_ledger_verified"] is False
and r_r10_mask_err["lot_bank_hierarchy_valid"] is False
and r_r10_mask_err["lot_to_mcb_manifest_verified"] is False
and r_r10_mask_err["lot_to_wcb_manifest_verified"] is False
and r_r10_mask_err["deff"] is None
and r_r10_mask_err["n_eff"] is None
and r_r10_mask_err["k_eff"] is None
and any("CMC_ROW_ANCESTRY_CONFLICTS_WITH_VERIFIED_MANIFEST" in fr for fr in r_r10_mask_err["failure_reasons"])
):
raise ValueError(f"R10 B2c error-path audit masked by followup + CMC shape error MUST invalidate all 4 flags: {r_r10_mask_err}")
cases.append({"case": "b2c_r10_gate28a_pass0_error_path_audit_catches_swap_masked_by_followup_and_cmc_shape", "passed": True})
# 54. R10 M1: Infused CMC row MUST explicitly declare matching wcb_id whenever VERIFIED_LOT_TO_BANK_MANIFEST
# declares wcb_id for that lot (matched-wcb promotes; missing-infused-cmc-wcb fails closed!)
p_r10_wcb_match, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_obs_wcb, cohort_id="COHORT-R10-WCB-MATCH",
lot_to_mcb_manifest=r10_bank_map, lot_to_wcb_manifest={"L00": "W0"},
parallel_cmc_lot_ledger=r10_annot_rows,
)
r_r10_wcb_match = evaluate_gate28a_h1_promotion(p_r10_wcb_match, trusted_clinical_store=r10_store)
p_r10_wcb_omitted, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_obs_wcb, cohort_id="COHORT-R10-WCB-OMITTED",
lot_to_mcb_manifest=r10_bank_map, lot_to_wcb_manifest={"L00": "W0"},
parallel_cmc_lot_ledger=r10_plain_rows,
)
r_r10_wcb_omitted = evaluate_gate28a_h1_promotion(p_r10_wcb_omitted, trusted_clinical_store=r10_store)
if not (
r_r10_wcb_match["status"] == "PROMOTE_H1_88_TO_90"
and r_r10_wcb_match["promotion_authorized"] is True
and r_r10_wcb_match["parallel_cmc_ledger_verified"] is True
and r_r10_wcb_match["lot_to_wcb_manifest_verified"] is True
and r_r10_wcb_omitted["status"] == "HOLD_H1_AT_88PCT"
and r_r10_wcb_omitted["promotion_authorized"] is False
and r_r10_wcb_omitted["parallel_cmc_ledger_verified"] is False
and r_r10_wcb_omitted["lot_bank_hierarchy_valid"] is False
and r_r10_wcb_omitted["lot_to_mcb_manifest_verified"] is False
and r_r10_wcb_omitted["lot_to_wcb_manifest_verified"] is False