# lineage-specific diagnostics AND emit the CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT umbrella code # with full ancestry nullification across all 4 (clinical x CMC) row orderings! r17_m1_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", "icc_sensitivity_report_attached", "icc_sensitivity_report", "deff", "n_eff", "k_eff", "failure_reasons", ) for r17_m1_tag, r17_m1_key, r17_m1_val in ( ("MCB", "mcb_id", "M12-1"), ("WCB", "wcb_id", "WR-B"), ("PRIM-LOT", "rescued_primary_lot_id", "L12-01"), ): cmc_m1_same = copy.deepcopy(r13_cmc_ra) for row_m1 in cmc_m1_same: if row_m1.get("lot_type") == "RESCUE_REPEAT_LOT": row_m1[r17_m1_key] = r17_m1_val m1_same_views = [] for rev_rec in (False, True): for rev_cmc in (False, True): p_m1_s, _ = build_valid_gate28a_reference_bundle( r13_store, list(reversed(r13_clin_ra)) if rev_rec else r13_clin_ra, cohort_id=f"COHORT-R17-M1-SAMEID-{r17_m1_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(cmc_m1_same)) if rev_cmc else cmc_m1_same, ) res_m1_s = evaluate_gate28a_h1_promotion(p_m1_s, trusted_clinical_store=r13_store) m1_same_views.append({fk: res_m1_s.get(fk) for fk in r17_m1_fields}) if any(rv != m1_same_views[0] for rv in m1_same_views[1:]): raise ValueError(f"R17 M1 same-rescue-ID {r17_m1_tag} order dependence: {m1_same_views}") vm1 = m1_same_views[0] if not ( vm1["status"] == "HOLD_H1_AT_88PCT" and vm1["promotion_authorized"] is False and vm1["external_clinical_store_verified"] is False and vm1["lot_bank_hierarchy_valid"] is False and vm1["lot_to_mcb_manifest_verified"] is False and vm1["lot_to_wcb_manifest_verified"] is False and vm1["parallel_cmc_ledger_verified"] is False and vm1["icc_sensitivity_report_attached"] is False and vm1["icc_sensitivity_report"] is None and vm1["deff"] is None and vm1["n_eff"] is None and vm1["k_eff"] is None and any("CMC_ROW_ANCESTRY_CONFLICTS_WITH_VERIFIED_MANIFEST" in fr for fr in vm1["failure_reasons"]) and any("CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT" in fr for fr in vm1["failure_reasons"]) ): raise ValueError(f"R17 M1 same-rescue-ID {r17_m1_tag} umbrella conflict failed: {vm1}") cases.append({"case": "b1a_r13_gate28a_single_row_rescue_substitution_and_omission_full_nullification", "passed": True}) # 67. R13 B1b: Compound RA-vs-RB single-row substitution PLUS unrelated malformed split-lot planned_doses_n # MUST NOT mask rescue-identity diagnostics OR bypass full fail-closed ancestry nullification (both row orders)! r13_cmc_compound_fwd = copy.deepcopy(r13_cmc_rb) for row_sp in r13_cmc_compound_fwd: if row_sp.get("lot_id") == "L12-01": row_sp["planned_doses_n"] = 1 r13_cmc_compound_rev = list(reversed(copy.deepcopy(r13_cmc_compound_fwd))) p_r13_comp_fwd, _ = build_valid_gate28a_reference_bundle( r13_store, r13_clin_ra, cohort_id="COHORT-R13-B1-COMPOUND-FWD", lot_to_mcb_manifest=r13_mcb_full, lot_to_wcb_manifest=r13_wcb_full, parallel_cmc_lot_ledger=r13_cmc_compound_fwd, ) p_r13_comp_rev, _ = build_valid_gate28a_reference_bundle( r13_store, r13_clin_ra_rev, cohort_id="COHORT-R13-B1-COMPOUND-REV", lot_to_mcb_manifest=r13_mcb_full, lot_to_wcb_manifest=r13_wcb_full, parallel_cmc_lot_ledger=r13_cmc_compound_rev, ) r_r13_comp_fwd = evaluate_gate28a_h1_promotion(p_r13_comp_fwd, trusted_clinical_store=r13_store) r_r13_comp_rev = evaluate_gate28a_h1_promotion(p_r13_comp_rev, trusted_clinical_store=r13_store) if not ( r_r13_comp_fwd["status"] == "HOLD_H1_AT_88PCT" and r_r13_comp_fwd["promotion_authorized"] is False and r_r13_comp_fwd["parallel_cmc_ledger_verified"] is False and r_r13_comp_fwd["lot_bank_hierarchy_valid"] is False and r_r13_comp_fwd["lot_to_mcb_manifest_verified"] is False and r_r13_comp_fwd["lot_to_wcb_manifest_verified"] is False and r_r13_comp_fwd["deff"] is None and r_r13_comp_fwd["n_eff"] is None and r_r13_comp_fwd["k_eff"] is None and r_r13_comp_fwd["icc_sensitivity_report_attached"] is False and r_r13_comp_fwd["icc_sensitivity_report"] is None and any("CLINICAL_RESCUE_LOT_ID_MISMATCH_IN_CMC_LEDGER" in fr for fr in r_r13_comp_fwd["failure_reasons"]) and any("CMC_EXTRA_RESCUE_LOT_OMITTED_FROM_CLINICAL_COHORT" in fr for fr in r_r13_comp_fwd["failure_reasons"]) and any("CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT" in fr for fr in r_r13_comp_fwd["failure_reasons"]) and any("failed evaluate_cmc_attempted_lot_readiness" in fr for fr in r_r13_comp_fwd["failure_reasons"]) and r_r13_comp_rev["status"] == r_r13_comp_fwd["status"] and r_r13_comp_rev["promotion_authorized"] is False and r_r13_comp_rev["parallel_cmc_ledger_verified"] is False and r_r13_comp_rev["lot_bank_hierarchy_valid"] is False and r_r13_comp_rev["lot_to_mcb_manifest_verified"] is False and r_r13_comp_rev["lot_to_wcb_manifest_verified"] is False and r_r13_comp_rev["deff"] is None and r_r13_comp_rev["n_eff"] is None and r_r13_comp_rev["k_eff"] is None and r_r13_comp_rev["icc_sensitivity_report_attached"] is False and r_r13_comp_rev["failure_reasons"] == r_r13_comp_fwd["failure_reasons"] ): raise ValueError( f"R13 B1b compound rescue substitution + invalid split-lot check failed: " f"fwd={r_r13_comp_fwd}, rev={r_r13_comp_rev}" ) # Also verify missing rescued_primary_lot_id AND contradictory rescue recipient/outcome bindings # (both alone AND paired with unrelated malformed split-lot L12-01 planned_doses_n=1, forward & reversed)! for variant_lbl, mutate_kind in ( ("MISSING-PRIM", "missing_prim"), ("MISSING-PRIM-SHAPE", "missing_prim_shape"), ("CONF-RECIP-BIND", "conf_recip"), ("CONF-RECIP-BIND-SHAPE", "conf_recip_shape"), ("CONF-RECIP-RECS-SHAPE", "conf_recip_recs_shape"), ): cmc_var_fwd = copy.deepcopy(r13_cmc_ra) resc_var = next(row_v for row_v in cmc_var_fwd if row_v.get("lot_type") == "RESCUE_REPEAT_LOT") if mutate_kind.startswith("missing_prim"): resc_var.pop("rescued_primary_lot_id", None) elif mutate_kind.startswith("conf_recip_recs"): resc_var.pop("recipient_outcomes", None) resc_var["recipient_ids"] = ["R12-00-1"] resc_var["recipient_records"] = [{"recipient_id": "R12-00-1", "c2b_responder": 1}] elif mutate_kind.startswith("conf_recip"): resc_var["recipient_ids"] = ["R12-00-1"] resc_var["recipient_outcomes"] = {"R12-00-1": resc_var["recipient_outcomes"]["R12-00-0"]} if mutate_kind.endswith("shape"): for row_s in cmc_var_fwd: if row_s.get("lot_id") == "L12-01": row_s["planned_doses_n"] = 1 cmc_var_rev = list(reversed(copy.deepcopy(cmc_var_fwd))) p_vf, _ = build_valid_gate28a_reference_bundle( r13_store, r13_clin_ra, cohort_id=f"COHORT-R13-B1-{variant_lbl}-FWD", lot_to_mcb_manifest=r13_mcb_full, lot_to_wcb_manifest=r13_wcb_full, parallel_cmc_lot_ledger=cmc_var_fwd, ) p_vr, _ = build_valid_gate28a_reference_bundle( r13_store, r13_clin_ra_rev, cohort_id=f"COHORT-R13-B1-{variant_lbl}-REV", lot_to_mcb_manifest=r13_mcb_full, lot_to_wcb_manifest=r13_wcb_full, parallel_cmc_lot_ledger=cmc_var_rev, ) r_vf = evaluate_gate28a_h1_promotion(p_vf, trusted_clinical_store=r13_store) r_vr = evaluate_gate28a_h1_promotion(p_vr, trusted_clinical_store=r13_store) expected_tok = ( "CMC_RESCUE_LINKAGE_MISSING_OR_INVALID" if mutate_kind.startswith("missing_prim") else "CMC_RESCUE_RECIPIENT_BINDING_CONFLICT" ) if not ( r_vf["status"] == "HOLD_H1_AT_88PCT" and r_vf["promotion_authorized"] is False and r_vf["external_clinical_store_verified"] is False and r_vf["parallel_cmc_ledger_verified"] is False and r_vf["lot_bank_hierarchy_valid"] is False and r_vf["lot_to_mcb_manifest_verified"] is False and r_vf["lot_to_wcb_manifest_verified"] is False and r_vf["icc_sensitivity_report_attached"] is False and r_vf["icc_sensitivity_report"] is None and r_vf["deff"] is None and r_vf["n_eff"] is None and r_vf["k_eff"] is None and any(expected_tok in fr for fr in r_vf["failure_reasons"]) and r_vr["status"] == r_vf["status"] and r_vr["promotion_authorized"] is False and r_vr["external_clinical_store_verified"] is False and r_vr["parallel_cmc_ledger_verified"] is False and r_vr["lot_bank_hierarchy_valid"] is False and r_vr["lot_to_mcb_manifest_verified"] is False and r_vr["lot_to_wcb_manifest_verified"] is False and r_vr["icc_sensitivity_report_attached"] is False and r_vr["icc_sensitivity_report"] is None and r_vr["deff"] is None and r_vr["n_eff"] is None and r_vr["k_eff"] is None and r_vr["failure_reasons"] == r_vf["failure_reasons"] ): raise ValueError( f"R13 B1b pre-validation rescue linkage/binding check failed for {variant_lbl}: " f"fwd={r_vf}, rev={r_vr}" ) # Also verify Pass-0 clinical primary-lot claims vs raw CMC RELEASED_UNINFUSED / FAILED_RELEASE # dispositions BEFORE shape validation (alone AND combined with unrelated L29 planned_doses_n=0, # identically in forward & reverse row orders, while keeping matching 30-recipient control promoting)! r15_recips_30 = [ { "recipient_id": f"P{idx_p:02d}", "lot_id": f"L{idx_p:02d}", "mcb_id": f"M{idx_p // 3:02d}", "wcb_id": f"W{idx_p // 2:02d}-{idx_p // 3:02d}", "followup_months": 12, "met_c2b_criteria": True, "intercurrent_event": "NONE", } for idx_p in range(30) ] r15_mcb_30 = {row_p["lot_id"]: row_p["mcb_id"] for row_p in r15_recips_30} r15_wcb_30 = {row_p["lot_id"]: row_p["wcb_id"] for row_p in r15_recips_30} r15_base_cmc = _derive_reconciling_cmc_lot_ledger_from_recipients( r15_recips_30, r15_mcb_30, lot_to_wcb_manifest=r15_wcb_30 ) r15_disp_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", "icc_sensitivity_report_attached", "icc_sensitivity_report", "deff", "n_eff", "k_eff", "clopper_pearson_95_ci_scope", "failure_reasons", ) for disp_var, new_disp, add_shape in ( ("MATCHING", None, False), ("UNINFUSED", "RELEASED_UNINFUSED", False), ("FAILED", "FAILED_RELEASE", False), ("UNINFUSED-SHAPE", "RELEASED_UNINFUSED", True), ("FAILED-SHAPE", "FAILED_RELEASE", True), ): cmc_dv = copy.deepcopy(r15_base_cmc) if new_disp is not None: cmc_dv[0].update( disposition=new_disp, infused_doses_n=0, recipient_ids=[], recipient_outcomes={}, c2b_responder_doses_n=0, ) if add_shape: cmc_dv[-1]["planned_doses_n"] = 0 r15_views = [] for is_rev in (False, True): p_dv, _ = build_valid_gate28a_reference_bundle( r13_store, list(reversed(r15_recips_30)) if is_rev else r15_recips_30, cohort_id=f"COHORT-R15-DISP-{disp_var}-{int(is_rev)}", lot_to_mcb_manifest=r15_mcb_30, lot_to_wcb_manifest=r15_wcb_30, parallel_cmc_lot_ledger=list(reversed(cmc_dv)) if is_rev else cmc_dv, ) r_dv = evaluate_gate28a_h1_promotion(p_dv, trusted_clinical_store=r13_store) r15_views.append({fk: r_dv.get(fk) for fk in r15_disp_fields}) if r15_views[0] != r15_views[1]: raise ValueError(f"R15 primary-lot disposition order dependence for {disp_var}: {r15_views}") v0 = r15_views[0] if new_disp is None: if not ( v0["status"] == "PROMOTE_H1_88_TO_90" and v0["promotion_authorized"] is True and v0["lot_bank_hierarchy_valid"] is True and v0["parallel_cmc_ledger_verified"] is True and v0["icc_sensitivity_report_attached"] is True and abs(float(v0["deff"]) - 1.04) < 1e-6 and v0["clopper_pearson_95_ci_scope"] == "NOMINAL_IID_UNADJUSTED_RECIPIENT_COUNTS_ONLY_NOT_CLUSTER_ADJUSTED" and v0["failure_reasons"] == [] ): raise ValueError(f"R15 matching positive control failed: {v0}")