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…
{
"lot_id": "U01", "mcb_id": "M0", "wcb_id": "W0", "working_cell_bank_id": "W9",
"lot_type": "SINGLE_RECIPIENT", "disposition": "RELEASED_UNINFUSED",
"planned_doses_n": 1, "infused_doses_n": 0,
},
"CONFLICTING_WCB_ALIAS",
),
):
p_al9, _ = build_valid_gate28a_reference_bundle(
r09_store,
r08_bal60,
cohort_id=f"COHORT-R09-B1-ALIAS-{lbl_al9.upper()}",
lot_to_mcb_manifest=r09_mcb_u01,
lot_to_wcb_manifest=r08_wcb_map,
parallel_cmc_lot_ledger=copy.deepcopy(r09_base_cmc) + [extra_row_al9],
)
r_al9 = evaluate_gate28a_h1_promotion(p_al9, trusted_clinical_store=r09_store)
if not (
r_al9["status"] == "HOLD_H1_AT_88PCT"
and r_al9["promotion_authorized"] is False
and r_al9["parallel_cmc_ledger_verified"] is False
and r_al9["lot_bank_hierarchy_valid"] is False
and r_al9["lot_to_mcb_manifest_verified"] is False
and r_al9["lot_to_wcb_manifest_verified"] is False
and r_al9["deff"] is None
and r_al9["n_eff"] is None
and r_al9["k_eff"] is None
and any(exp_tok_al9 in fr for fr in r_al9["failure_reasons"])
):
raise ValueError(f"R09 B1b raw CMC alias conflict ({lbl_al9}) MUST invalidate hierarchy: {r_al9}")
cases.append({"case": "b1b_r09_gate28a_raw_cmc_mcb_and_wcb_alias_conflict_on_noninfused_row_invalidates_hierarchy", "passed": True})
# 47. R09 B1c: Compound non-ancestry mask attack, duplicate JSON keys in raw CMC bytes, AND recipient lot_id
# swap within same MCB ALL invalidate hierarchy and nullify deff/n_eff/k_eff!
cmc_r09_mask = copy.deepcopy(r09_base_cmc) + [
{
"lot_id": "F01", "mcb_id": "M1", "wcb_id": "W0",
"lot_type": "SINGLE_RECIPIENT", "disposition": "FAILED_RELEASE",
"planned_doses_n": 1, "infused_doses_n": 0,
}
]
cmc_r09_mask[0]["planned_doses_n"] = 0 # non-ancestry CMC error preceding WCB conflict
p_r09_mask, _ = build_valid_gate28a_reference_bundle(
r09_store,
r08_bal60,
cohort_id="COHORT-R09-B1-COMPOUND-MASK",
lot_to_mcb_manifest=r08_mcb_map,
lot_to_wcb_manifest=r08_wcb_map,
parallel_cmc_lot_ledger=cmc_r09_mask,
)
r_r09_mask = evaluate_gate28a_h1_promotion(p_r09_mask, trusted_clinical_store=r09_store)
# Duplicate JSON key in raw PARALLEL_CMC_READINESS_LEDGER bytes stored hash-pinned in trusted_clinical_store
dup_cmc_json_str = (
'{"cohort_id":"COHORT-R09-B1-DUPJSON","issuer_authority_id":"OPENISLET_CLINICAL_ADJUDICATION_BOARD_V1",'
'"lot_ledger":[{"disposition":"RELEASED_UNINFUSED","infused_doses_n":0,"lot_id":"U01","lot_type":"SINGLE_RECIPIENT",'
'"mcb_id":"M0","mcb_id":"M1","planned_doses_n":1}],"record_type":"PARALLEL_CMC_READINESS_LEDGER"}\n'
)
dup_cmc_bytes = dup_cmc_json_str.encode("utf-8")
dup_cmc_sha = sha256_bytes(dup_cmc_bytes)
p_r09_dup = {
"cohort_id": "COHORT-R09-B1-DUPJSON",
**GATE_28A_COMPATIBILITY_TARGET,
"includes_reichman": False,
"rho_lot": GATE_28A_RHO_LOT_MIN,
"rho_bank": GATE_28A_RHO_BANK_MIN,
"primary_peer_reviewed_full_text_verified": True,
"parallel_cmc_readiness_ledger_disclosed": True,
"parallel_cmc_readiness_ledger_sha256": dup_cmc_sha,
"lot_to_mcb_manifest": copy.deepcopy(r08_mcb_map),
"lot_to_wcb_manifest": copy.deepcopy(r08_wcb_map),
"recipients": copy.deepcopy(r08_bal60),
}
dup_canon = compute_gate28a_cohort_canonical_sha256(p_r09_dup)
dup_prespec = build_gate28a_prespecification_attestation(cohort_id="COHORT-R09-B1-DUPJSON", cohort_canonical_sha256=dup_canon)
dup_source = build_gate28a_source_verification_attestation(
cohort_id="COHORT-R09-B1-DUPJSON", cohort_canonical_sha256=dup_canon, parallel_cmc_readiness_ledger_sha256=dup_cmc_sha
)
dup_mrec = build_gate28a_verified_lot_to_bank_manifest(
cohort_id="COHORT-R09-B1-DUPJSON", lot_to_mcb_manifest=r08_mcb_map, lot_to_wcb_manifest=r08_wcb_map
)
write_gate28a_trusted_clinical_store(
r09_store,
prespecification_attestations=[dup_prespec],
source_verification_attestations=[dup_source],
verified_lot_to_bank_manifests=[dup_mrec],
parallel_cmc_readiness_ledgers=[dup_cmc_bytes],
)
p_r09_dup["clinical_store_refs"] = {
"prespecification_attestation_sha256": dup_prespec["record_sha256"],
"source_verification_attestation_sha256": dup_source["record_sha256"],
"verified_lot_to_bank_manifest_sha256": dup_mrec["record_sha256"],
"parallel_cmc_readiness_ledger_sha256": dup_cmc_sha,
}
r_r09_dup = evaluate_gate28a_h1_promotion(p_r09_dup, trusted_clinical_store=r09_store)
# Recipient lot_id swap within same MCB M0 (R08-00-0 <-> R08-01-0 between L00 and L01)
cmc_r09_lotswap = copy.deepcopy(r09_base_cmc)
row_l00 = next(x for x in cmc_r09_lotswap if x["lot_id"] == "L00")
row_l01 = next(x for x in cmc_r09_lotswap if x["lot_id"] == "L01")
row_l00["recipient_outcomes"].pop("R08-00-0")
row_l00["recipient_outcomes"]["R08-01-0"] = 1
row_l00["recipient_ids"] = sorted(row_l00["recipient_outcomes"].keys())
row_l01["recipient_outcomes"].pop("R08-01-0")
row_l01["recipient_outcomes"]["R08-00-0"] = 1
row_l01["recipient_ids"] = sorted(row_l01["recipient_outcomes"].keys())
p_r09_lotswap, _ = build_valid_gate28a_reference_bundle(
r09_store,
r08_bal60,
cohort_id="COHORT-R09-B1-LOTSWAP",
lot_to_mcb_manifest=r08_mcb_map,
lot_to_wcb_manifest=r08_wcb_map,
parallel_cmc_lot_ledger=cmc_r09_lotswap,
)
r_r09_lotswap = evaluate_gate28a_h1_promotion(p_r09_lotswap, trusted_clinical_store=r09_store)
for lbl_c9, res_c9 in (("compound_mask", r_r09_mask), ("dup_json_key", r_r09_dup), ("lot_swap", r_r09_lotswap)):
if not (
res_c9["status"] == "HOLD_H1_AT_88PCT"
and res_c9["promotion_authorized"] is False
and res_c9["parallel_cmc_ledger_verified"] is False
and res_c9["lot_bank_hierarchy_valid"] is False
and res_c9["lot_to_mcb_manifest_verified"] is False
and res_c9["lot_to_wcb_manifest_verified"] is False
and res_c9["deff"] is None
and res_c9["n_eff"] is None
and res_c9["k_eff"] is None
):
raise ValueError(f"R09 B1c ({lbl_c9}) MUST fail closed with null cluster outputs: {res_c9}")
if not any("Duplicate JSON object key" in fr for fr in r_r09_dup["failure_reasons"]):
raise ValueError(f"R09 B1c duplicate JSON key reason missing: {r_r09_dup}")
cases.append({"case": "b1c_r09_gate28a_compound_mask_duplicate_json_key_and_recipient_lot_mismatch_invalidate_hierarchy", "passed": True})
# 48. R09 B1d: Ordinary non-ancestry clinical HOLD (54/60 responders, valid manifest & reconciling CMC)
# holds promotion WHILE preserving valid hierarchy flags and exact cluster outputs!
r09_hold_60 = copy.deepcopy(r08_bal60)
for i_fail in range(6):
r09_hold_60[i_fail * 10]["met_c2b_criteria"] = False
cmc_r09_hold = _derive_reconciling_cmc_lot_ledger_from_recipients(r09_hold_60, r08_mcb_map)
for row_h in cmc_r09_hold:
if row_h["lot_id"] == "L00":
row_h["wcb_id"] = "W0"
p_r09_hold, _ = build_valid_gate28a_reference_bundle(
r09_store,
r09_hold_60,
cohort_id="COHORT-R09-B1-ORD-HOLD",
lot_to_mcb_manifest=r08_mcb_map,
lot_to_wcb_manifest=r08_wcb_map,
parallel_cmc_lot_ledger=cmc_r09_hold,
)
r_r09_hold = evaluate_gate28a_h1_promotion(p_r09_hold, trusted_clinical_store=r09_store)
if not (
r_r09_hold["status"] == "HOLD_H1_AT_88PCT"
and r_r09_hold["promotion_authorized"] is False
and r_r09_hold["lot_bank_hierarchy_valid"] is True
and r_r09_hold["lot_to_mcb_manifest_verified"] is True
and r_r09_hold["lot_to_wcb_manifest_verified"] is True
and r_r09_hold["parallel_cmc_ledger_verified"] is True
and abs(r_r09_hold["deff"] - 1.53) < 1e-6
and abs(r_r09_hold["n_eff"] - 39.215686) < 1e-5
and abs(r_r09_hold["k_eff"] - 35.294118) < 1e-5
):
raise ValueError(f"R09 B1d ordinary non-ancestry clinical HOLD regression failed: {r_r09_hold}")
cases.append({"case": "b1d_r09_gate28a_ordinary_clinical_hold_preserves_valid_hierarchy_and_cluster_outputs", "passed": True})
# 49. R09 M3: Separate variance-component ICC bounds (0 <= rho_lot, 0 <= rho_bank, rho_lot + rho_bank <= 1.0)
# fail closed on sum > 1.0 or negative/below-floor ICC, accept sum == 1.0 boundary, and verify sensitivity!
p_icc_over, _ = build_valid_gate28a_reference_bundle(
r09_store, r08_bal60, cohort_id="COHORT-R09-ICC-OVER", lot_to_mcb_manifest=r08_mcb_map,
lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=r09_base_cmc, rho_lot=0.7, rho_bank=0.5,
)
r_icc_over = evaluate_gate28a_h1_promotion(p_icc_over, trusted_clinical_store=r09_store)
p_icc_eps, _ = build_valid_gate28a_reference_bundle(
r09_store, r08_bal60, cohort_id="COHORT-R09-ICC-EPS", lot_to_mcb_manifest=r08_mcb_map,
lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=r09_base_cmc, rho_lot=0.6, rho_bank=0.400001,
)
r_icc_eps = evaluate_gate28a_h1_promotion(p_icc_eps, trusted_clinical_store=r09_store)
p_icc_neg, _ = build_valid_gate28a_reference_bundle(
r09_store, r08_bal60, cohort_id="COHORT-R09-ICC-NEG", lot_to_mcb_manifest=r08_mcb_map,
lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=r09_base_cmc, rho_lot=-0.05, rho_bank=0.02,
)
r_icc_neg = evaluate_gate28a_h1_promotion(p_icc_neg, trusted_clinical_store=r09_store)
p_icc_eq1, _ = build_valid_gate28a_reference_bundle(
r09_store, r08_bal60, cohort_id="COHORT-R09-ICC-EQ1", lot_to_mcb_manifest=r08_mcb_map,
lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=r09_base_cmc, rho_lot=0.6, rho_bank=0.4,
)
r_icc_eq1 = evaluate_gate28a_h1_promotion(p_icc_eq1, trusted_clinical_store=r09_store)
p_icc_mod, _ = build_valid_gate28a_reference_bundle(
r09_store, r08_bal60, cohort_id="COHORT-R09-ICC-MOD", lot_to_mcb_manifest=r08_mcb_map,
lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=r09_base_cmc, rho_lot=0.10, rho_bank=0.05,
)
r_icc_mod = evaluate_gate28a_h1_promotion(p_icc_mod, trusted_clinical_store=r09_store)
p_icc_hi, _ = build_valid_gate28a_reference_bundle(
r09_store, r08_bal60, cohort_id="COHORT-R09-ICC-HI", lot_to_mcb_manifest=r08_mcb_map,
lot_to_wcb_manifest=r08_wcb_map, parallel_cmc_lot_ledger=r09_base_cmc, rho_lot=0.15, rho_bank=0.10,
)
r_icc_hi = evaluate_gate28a_h1_promotion(p_icc_hi, trusted_clinical_store=r09_store)
if not (
r_icc_over["promotion_authorized"] is False
and r_icc_over["deff"] is None
and r_icc_over["n_eff"] is None
and r_icc_over["k_eff"] is None
and any("INVALID_ICC_SUM_EXCEEDS_ONE" in fr for fr in r_icc_over["failure_reasons"])
and r_icc_eps["promotion_authorized"] is False
and r_icc_eps["deff"] is None
and any("INVALID_ICC_SUM_EXCEEDS_ONE" in fr for fr in r_icc_eps["failure_reasons"])
and r_icc_neg["promotion_authorized"] is False
and r_icc_neg["deff"] is None
and any("INVALID_ICC_DOMAIN" in fr for fr in r_icc_neg["failure_reasons"])
and r_icc_eq1["promotion_authorized"] is False
and r_icc_eq1["deff"] is not None
and abs(r_icc_eq1["deff"] - 10.4) < 1e-6
and not any("INVALID_ICC" in fr for fr in r_icc_eq1["failure_reasons"])
and r_icc_mod["promotion_authorized"] is True
and abs(r_icc_mod["deff"] - 2.25) < 1e-6
and abs(r_icc_mod["n_eff"] - 26.666667) < 1e-5
and r_icc_hi["promotion_authorized"] is False
and abs(r_icc_hi["deff"] - 3.35) < 1e-6
and abs(r_icc_hi["n_eff"] - 17.910448) < 1e-5
):
raise ValueError(
f"R09 M3 ICC sum/sensitivity checks failed: over={r_icc_over}, eps={r_icc_eps}, "
f"neg={r_icc_neg}, eq1={r_icc_eq1}, mod={r_icc_mod}, hi={r_icc_hi}"
)
cases.append({"case": "m3_r09_gate28a_icc_variance_component_sum_le_1_enforced_and_sensitivity_verified", "passed": True})
# --- R10 B1, B2, M1, M2: Exact bidirectional rescue identity & cardinality (0/1/2), Pass-0 unconditional
# clinical ancestry extraction independent of follow-up/outcome/duplicate/CMC-shape errors, explicit
# infused CMC WCB attestation, and Reichman cryptococcal death context ---
r10_store = tmp_dir_p / "r10_gate28a_store.json"
r10_plain60 = [
{
"recipient_id": f"R{lot:02d}-{rep}",
"lot_id": f"L{lot:02d}",
"mcb_id": f"M{lot // 5}",
"followup_months": 12,
"met_c2b_criteria": True,
"intercurrent_event": "NONE",
}
for lot in range(15)
for rep in range(4)
]
r10_bank_map = {r["lot_id"]: r["mcb_id"] for r in r10_plain60}
r10_plain_rows = _derive_reconciling_cmc_lot_ledger_from_recipients(r10_plain60, r10_bank_map)
# 50. R10 B1: Exact bidirectional rescue identity & cardinality reconciliation (0, 1, 2 rescues + extra/missing/duplicate rejections)
p_r10_zero, _ = build_valid_gate28a_reference_bundle(
r10_store, r10_plain60, cohort_id="COHORT-R10-RESC-0",
lot_to_mcb_manifest=r10_bank_map, parallel_cmc_lot_ledger=r10_plain_rows,
)