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…
else:
if not (
v0["status"] == "HOLD_H1_AT_88PCT"
and v0["promotion_authorized"] is False
and v0["external_clinical_store_verified"] is False
and v0["lot_bank_hierarchy_valid"] is False
and v0["lot_to_mcb_manifest_verified"] is False
and v0["lot_to_wcb_manifest_verified"] is False
and v0["parallel_cmc_ledger_verified"] is False
and v0["icc_sensitivity_report_attached"] is False
and v0["icc_sensitivity_report"] is None
and v0["deff"] is None
and v0["n_eff"] is None
and v0["k_eff"] is None
and any(
"CLINICAL_PRIMARY_LOT_CMC_DISPOSITION_CONFLICT" in fr and new_disp in fr
for fr in v0["failure_reasons"]
)
and ((not add_shape) or any("Lot 'L29'" in fr for fr in v0["failure_reasons"]))
):
raise ValueError(f"R15 primary-lot disposition nullification failed for {disp_var}: {v0}")
# R16: Contradictory duplicate recipient ancestry (P00/L00 missing follow-up + P00/L01 valid L01 bank IDs)
# MUST NEVER suppress raw CMC primary-lot disposition audit (single bad lot OR both bad lots + L29 shape error),
# identically across BOTH recipient orders AND BOTH CMC row orders!
r16_dup_recips = copy.deepcopy(r15_recips_30)
r16_dup_recips[0]["followup_months"] = None
r16_dup_recips.append({
"recipient_id": "P00",
"lot_id": "L01",
"mcb_id": r15_mcb_30["L01"],
"wcb_id": r15_wcb_30["L01"],
"followup_months": 12,
"met_c2b_criteria": True,
"intercurrent_event": "NONE",
})
for r16_lbl, l00_disp, l01_disp in (
("DUP-L00-FAILED", "FAILED_RELEASE", None),
("DUP-L00-UNINFUSED", "RELEASED_UNINFUSED", None),
("DUP-BOTH-FAILED-UNINFUSED", "FAILED_RELEASE", "RELEASED_UNINFUSED"),
("DUP-L01-FAILED", None, "FAILED_RELEASE"),
):
cmc_r16 = copy.deepcopy(r15_base_cmc)
if l00_disp is not None:
cmc_r16[0].update(
disposition=l00_disp,
infused_doses_n=0,
recipient_ids=[],
recipient_outcomes={},
c2b_responder_doses_n=0,
)
if l01_disp is not None:
cmc_r16[1].update(
disposition=l01_disp,
infused_doses_n=0,
recipient_ids=[],
recipient_outcomes={},
c2b_responder_doses_n=0,
)
cmc_r16[-1]["planned_doses_n"] = 0
r16_views = []
for rev_rec in (False, True):
for rev_cmc in (False, True):
p_r16, _ = build_valid_gate28a_reference_bundle(
r13_store,
list(reversed(r16_dup_recips)) if rev_rec else r16_dup_recips,
cohort_id=f"COHORT-R16-{r16_lbl}-{int(rev_rec)}-{int(rev_cmc)}",
lot_to_mcb_manifest=r15_mcb_30,
lot_to_wcb_manifest=r15_wcb_30,
parallel_cmc_lot_ledger=list(reversed(cmc_r16)) if rev_cmc else cmc_r16,
)
r_r16 = evaluate_gate28a_h1_promotion(p_r16, trusted_clinical_store=r13_store)
r16_views.append({fk: r_r16.get(fk) for fk in r15_disp_fields})
if any(rv != r16_views[0] for rv in r16_views[1:]):
raise ValueError(f"R16 duplicate-recipient + CMC disposition order dependence for {r16_lbl}: {r16_views}")
rv0 = r16_views[0]
if not (
rv0["status"] == "HOLD_H1_AT_88PCT"
and rv0["promotion_authorized"] is False
and rv0["external_clinical_store_verified"] is False
and rv0["lot_bank_hierarchy_valid"] is False
and rv0["lot_to_mcb_manifest_verified"] is False
and rv0["lot_to_wcb_manifest_verified"] is False
and rv0["parallel_cmc_ledger_verified"] is False
and rv0["icc_sensitivity_report_attached"] is False
and rv0["icc_sensitivity_report"] is None
and rv0["deff"] is None
and rv0["n_eff"] is None
and rv0["k_eff"] is None
and any("CONFLICTING_DUPLICATE_RECIPIENT_ANCESTRY" in fr for fr in rv0["failure_reasons"])
and any("Lot 'L29'" in fr for fr in rv0["failure_reasons"])
and (
l00_disp is None
or any(
"CLINICAL_PRIMARY_LOT_CMC_DISPOSITION_CONFLICT" in fr
and "'P00'" in fr and "'L00'" in fr and l00_disp in fr
for fr in rv0["failure_reasons"]
)
)
and (
l01_disp is None
or any(
"CLINICAL_PRIMARY_LOT_CMC_DISPOSITION_CONFLICT" in fr
and "'P00'" in fr and "'L01'" in fr and l01_disp in fr
for fr in rv0["failure_reasons"]
)
)
):
raise ValueError(f"R16 duplicate-recipient + CMC disposition audit failed for {r16_lbl}: {rv0}")
cases.append({"case": "b1b_r13_gate28a_compound_rescue_substitution_plus_invalid_split_lot_no_masking", "passed": True})
# 68. R13 M1: Undocumented *rescue*lot* alias keys rejected BY KEY PRESENCE even when value is
# None/null/""/[] or on a qualifying recipient with intercurrent_event="NONE"!
r13_m1_results = []
for idx_m1, (bad_k, bad_v) in enumerate((
("rescue_repeat_lot_id", None),
("rescue_repeat_lot_ids", None),
("rescue_repeat_lot_id", ""),
("rescue_repeat_lot_ids", []),
("alt_rescue_lot_ref", None),
)):
rec_m1_null = copy.deepcopy(r12_120)
rec_m1_null[0][bad_k] = bad_v
p_m1_null, _ = build_valid_gate28a_reference_bundle(
r13_store, rec_m1_null, cohort_id=f"COHORT-R13-M1-PRESENCE-{idx_m1}",
)
res_m1_null = evaluate_gate28a_h1_promotion(p_m1_null, trusted_clinical_store=r13_store)
r13_m1_results.append((bad_k, bad_v, res_m1_null))
if not (
res_m1_null["status"] == "HOLD_H1_AT_88PCT"
and res_m1_null["promotion_authorized"] is False
and res_m1_null["parallel_cmc_ledger_verified"] is False
and any("UNRECOGNIZED_CLINICAL_RESCUE_LOT_ALIAS" in fr for fr in res_m1_null["failure_reasons"])
):
raise ValueError(
f"R13 M1 by-presence undocumented rescue key check failed for {bad_k}={bad_v!r}: {res_m1_null}"
)
cases.append({"case": "m1_r13_gate28a_null_undocumented_rescue_alias_rejected_by_presence", "passed": True})
# 69. R17 B1: Paired initial-lot raw CMC outcome (0 vs 1 with updated c2b_responder_doses_n) on a matched
# 120-recipient cohort with one declared & matched rescue across ALL 4 (recipient x CMC) row orders:
# - CMC=0 vs clinical=0 -> PROMOTE_H1_88_TO_90, parallel_cmc_ledger_verified=True, 119/120, zero failures
# - CMC=1 vs clinical=0 -> HOLD_H1_AT_88PCT, parallel_cmc_ledger_verified=False, CMC_OUTCOME_MISMATCH!
r17_rid0 = r13_clin_ra[0]["recipient_id"]
r17_lot0 = r13_clin_ra[0]["lot_id"]
r17_cmc_raw0 = copy.deepcopy(r13_cmc_ra)
r17_cmc_raw1 = copy.deepcopy(r13_cmc_ra)
for row_r17 in r17_cmc_raw1:
if row_r17.get("lot_id") == r17_lot0:
row_r17["recipient_outcomes"][r17_rid0] = 1
row_r17["c2b_responder_doses_n"] = sum(row_r17["recipient_outcomes"].values())
r17_cmc_raw1_recs = copy.deepcopy(r17_cmc_raw1)
for row_r17r in r17_cmc_raw1_recs:
if row_r17r.get("lot_id") == r17_lot0:
out_map = row_r17r.pop("recipient_outcomes")
row_r17r["recipient_records"] = [
{"recipient_id": k_r, "c2b_responder": bool(v_r)}
for k_r, v_r in sorted(out_map.items())
]
r17_compare_fields = (
"status", "promotion_authorized", "external_clinical_store_verified",
"lot_bank_hierarchy_valid", "lot_to_mcb_manifest_verified", "lot_to_wcb_manifest_verified",
"parallel_cmc_ledger_verified", "k", "n", "deff", "n_eff", "k_eff", "failure_reasons",
)
for r17_tag, r17_cmc_rows, expect_promote in (
("RAW0-MATCH", r17_cmc_raw0, True),
("RAW1-MISMATCH", r17_cmc_raw1, False),
("RAW1-RECS-MISMATCH", r17_cmc_raw1_recs, False),
):
r17_views = []
for rev_rec in (False, True):
for rev_cmc in (False, True):
p_r17, _ = build_valid_gate28a_reference_bundle(
r13_store,
list(reversed(r13_clin_ra)) if rev_rec else r13_clin_ra,
cohort_id=f"COHORT-R17-B1-{r17_tag}-{int(rev_rec)}-{int(rev_cmc)}",
lot_to_mcb_manifest=r13_mcb_full,
lot_to_wcb_manifest=r13_wcb_full,
parallel_cmc_lot_ledger=list(reversed(r17_cmc_rows)) if rev_cmc else r17_cmc_rows,
)
res_r17 = evaluate_gate28a_h1_promotion(p_r17, trusted_clinical_store=r13_store)
r17_views.append({fk: res_r17.get(fk) for fk in r17_compare_fields})
if any(rv != r17_views[0] for rv in r17_views[1:]):
raise ValueError(f"R17 B1 rescue raw CMC outcome order dependence for {r17_tag}: {r17_views}")
v17 = r17_views[0]
if expect_promote:
if not (
v17["status"] == "PROMOTE_H1_88_TO_90"
and v17["promotion_authorized"] is True
and v17["external_clinical_store_verified"] is True
and v17["parallel_cmc_ledger_verified"] is True
and v17["k"] == 119
and v17["n"] == 120
and v17["failure_reasons"] == []
):
raise ValueError(f"R17 B1 rescue CMC=0 control failed: {v17}")
else:
if not (
v17["status"] == "HOLD_H1_AT_88PCT"
and v17["promotion_authorized"] is False
and v17["external_clinical_store_verified"] is False
and v17["parallel_cmc_ledger_verified"] is False
and v17["k"] == 119
and v17["n"] == 120
and any(
"CMC_OUTCOME_MISMATCH" in fr
and repr(r17_rid0) in fr
and "clinical=0 != cmc=1" in fr
for fr in v17["failure_reasons"]
)
):
raise ValueError(f"R17 B1 rescue raw CMC=1 mismatch failed to HOLD ({r17_tag}): {v17}")
cases.append({"case": "b1_r17_gate28a_raw_cmc_rescue_primary_outcome_reconciliation_all_4_orders", "passed": True})
# 70. R18 B1: Contradictory primary recipient bindings on CMC lot L01 (4 recipients in recipient_outcomes
# vs 3 in recipient_records, or 4 in recipient_outcomes vs 3 in recipient_ids) MUST nullify ALL ancestry,
# manifest, ICC, and cluster fields fail-closed across all 4 (clinical x CMC) row orderings — BOTH alone
# AND when paired with an earlier malformed split-lot count on L00 (planned_doses_n=1) — while a consistent
# 3-recipient control on L01 promotes cleanly!
r18_recips_4 = [
{
"recipient_id": f"R18-{lot_i:02d}-{rep_i}",
"lot_id": f"L{lot_i:02d}",
"mcb_id": f"M{lot_i // 3:02d}",
"wcb_id": f"W{lot_i // 2:02d}-M{lot_i // 3:02d}",
"followup_months": 12,
"met_c2b_criteria": True,
"intercurrent_event": "NONE",
}
for lot_i in range(30)
for rep_i in range(4)
]
r18_mcb = {row_x["lot_id"]: row_x["mcb_id"] for row_x in r18_recips_4}
r18_wcb = {row_x["lot_id"]: row_x["wcb_id"] for row_x in r18_recips_4}
r18_base_cmc_4 = _derive_reconciling_cmc_lot_ledger_from_recipients(
r18_recips_4, r18_mcb, lot_to_wcb_manifest=r18_wcb
)
# (a) 4 recipients in recipient_outcomes vs 3 in recipient_records on L01
r18_cmc_4v3_recs = copy.deepcopy(r18_base_cmc_4)
for row_18 in r18_cmc_4v3_recs:
if row_18.get("lot_id") == "L01":
row_18["recipient_records"] = [
{"recipient_id": f"R18-01-{rep_i}", "c2b_responder": True}
for rep_i in range(3)
]
# (b) Same 4-vs-3 contradiction on L01 PLUS earlier malformed split-lot count on L00 (planned_doses_n=1)
r18_cmc_4v3_recs_shape = copy.deepcopy(r18_cmc_4v3_recs)
for row_18 in r18_cmc_4v3_recs_shape:
if row_18.get("lot_id") == "L00":