evaluate_stage0_d1b_auto_v2_gates_iip0035( { **base_obs, "d1_auto_locus1_donor_arm": ["UNHASHABLE_ARRAY"], "obs_d1_04_ap1903_survivor_count_k": 1, }, product_def=p_l1a, evaluated_lot_id="MCB_AUTO_LOT_01", repo_root=repo_root, ), "FAIL_HARD_STOP_D1_04_AP1903_SURVIVOR_DETECTED", ), ( "d1_08_c0304_pos_missing_positive_control_HOLD", evaluate_stage0_d1b_auto_v2_gates_iip0035( { k: v for k, v in {**base_obs, "d1_auto_locus1_donor_arm": "D1AUTO_V2_L1A_IL1RN_CD64T_PRIMARY"}.items() if k != "d1_08_hlac0304_positive_control_valid" }, product_def=p_l1a, evaluated_lot_id="MCB_AUTO_LOT_01", repo_root=repo_root, ), "HOLD_D1_08_HLAC0304_POSITIVE_CONTROL_VALIDITY_REQUIRED", ), ( "d1_08_c0304_pos_invalid_positive_control_FAIL", evaluate_stage0_d1b_auto_v2_gates_iip0035( { **base_obs, "d1_auto_locus1_donor_arm": "D1AUTO_V2_L1A_IL1RN_CD64T_PRIMARY", "d1_08_hlac0304_positive_control_valid": False, }, product_def=p_l1a, evaluated_lot_id="MCB_AUTO_LOT_01", repo_root=repo_root, ), "FAIL_D1_08_HLAC0304_POSITIVE_CONTROL_INVALID", ), ( "d1_08_non_c0304_alternate_matched_allele_branch_PASS", evaluate_stage0_d1b_auto_v2_gates_iip0035( { **{ k: v for k, v in base_obs.items() if k not in ( "d1_08_hlac0304_positive_control_valid", "obs_d1_08_hlac0304_tcell_lysis_u95_pct", "obs_d1_08_hlac0304_lysed_events_k", "obs_d1_08_hlac0304_scored_targets_n", ) }, "d1_auto_locus1_donor_arm": "D1AUTO_V2_L1A_IL1RN_CD64T_PRIMARY", "d1_08_patient_carries_hlac0304": False, "d1_08_matched_allele_positive_control_valid": True, "d1_08_non_c0304_matched_allele_screen_passed": True, }, product_def=p_l1a, evaluated_lot_id="MCB_AUTO_LOT_01", repo_root=repo_root, ), "REFERENCE_CRITERIA_MET_EMPIRICAL_RELEASE_PENDING", ), ( "d1_08_missing_carrier_status_HOLD", evaluate_stage0_d1b_auto_v2_gates_iip0035( { k: v for k, v in {**base_obs, "d1_auto_locus1_donor_arm": "D1AUTO_V2_L1A_IL1RN_CD64T_PRIMARY"}.items() if k != "d1_08_patient_carries_hlac0304" }, product_def=p_l1a, evaluated_lot_id="MCB_AUTO_LOT_01", repo_root=repo_root, ), "HOLD_D1_08_HLAC0304_CARRIER_STATUS_REQUIRED", ), ] gate_results: List[Dict[str, Any]] = [] for cname, res, exp_st in gate_cases: if res["status"] != exp_st: raise ValueError(f"Gate matrix case {cname} returned {res['status']!r}, expected {exp_st!r}") if res.get("clinical_or_batch_release_authorized") is not False: raise ValueError(f"Gate matrix case {cname} must never authorize clinical or batch release") if res.get("controlling_contract_sha256") != EXPECTED_DEC114_DECISION_TREE_SHA256: raise ValueError(f"Gate matrix case {cname} missing controlling DEC-114 SHA-256") if res.get("controlling_playbook_sec4120_sha256") != EXPECTED_DEC114_PLAYBOOK_SEC4120_SHA256: raise ValueError(f"Gate matrix case {cname} missing controlling Playbook §4.1.20 SHA-256") gate_results.append({"case": cname, **res}) return { "arithmetic_precision": ( "decimal.Decimal prec=80 strictly sound directed outward bounds (ln/exp at ordinary arguments " "and paired alternating Taylor -expm1 enclosure at small x < 1e-6; bounded 2M-bit exact rational " "decider + 260-digit outward enclosure; alpha_eta >= 0.05 when eta < 1.0)" ), "count_subgate_framing": ( "All zero-event rare-event thresholds (D1-04 AP1903 U95 <= 1.0e-8 at N_eff = 299,573,226 PASS vs 299,573,225 HOLD; " "D1-08 HLA-C*03:04 & C5b-9 U95 <= 5.0% at N = 59 PASS [4.9508% display] vs N = 58 HOLD [5.0339% display / 5.0340% conservative ceil]) " "represent mathematical count subgate arithmetic only, conditional on validated recovery/eligible-fraction calibration, " "and supply no empirical safety clearance." ), "clopper_pearson_boundary_cases": cp_results, "standalone_stage0_gate_reference_matrix": gate_results, } def _resolve_and_verify_d1b_auto_v2_registry(repo_root: Path) -> tuple[Dict[str, Any], Dict[str, Dict[str, Any]]]: """Load product_contract, verify FASTA & 5 full_record_sha256s, 45-cell typed contract & CommonMark Playbook §4.1.20.""" contracts = pc.load_product_contracts(repo_root, require_staged_fastas=True) by_id: Dict[str, Dict[str, Any]] = {p["product_variant_id"]: p for p in contracts["products"]} # 1. Verify DEC-114 stage0_decision_tree_v1.json canonical SHA-256 dt_path = repo_root / DECISION_TREE_REL_PATH if not dt_path.is_file(): raise ValueError(f"Missing Stage-0 decision tree: {dt_path}") dt_doc = _load_json_strict(dt_path) dec114_blk = dt_doc.get("autologous_d1b_auto_c_v2_vanguard_gates_iip_0035") if not isinstance(dec114_blk, dict): raise ValueError("Missing DEC-114 block autologous_d1b_auto_c_v2_vanguard_gates_iip_0035 in stage0_decision_tree_v1.json") dec114_sha = hashlib.sha256( json.dumps(dec114_blk, sort_keys=True, ensure_ascii=False, separators=(",", ":")).encode("utf-8") ).hexdigest() if dec114_sha != EXPECTED_DEC114_DECISION_TREE_SHA256: raise ValueError( f"DEC-114 decision-tree block SHA-256 mismatch: found {dec114_sha}, expected {EXPECTED_DEC114_DECISION_TREE_SHA256}" ) # 2. Parse Playbook with CommonMark 0.31.2 parser & require EXACTLY 1 rendered 4.1.20 heading + end-marker pb_info = _verify_playbook_sec4120(repo_root, require_canonical_sha=True) all_headings = pb_info["all_headings"] matched_4120 = pb_info["matched_4120"] h4120 = pb_info["h4120"] pb_sec_full = pb_info["pb_sec_full"] pb_sha = pb_info["pb_sha"] # 3. Verify EXACT admitted ISLET1_D1_* namespace (no unpinned synthetic entries!) + roles, non-executable state & ROUTE_3P binding d1_namespace_ids = {p for p in by_id if p.startswith("ISLET1_D1_")} if d1_namespace_ids != set(pc.STAGED_D1B_AUTO_V2_PRODUCT_IDS): raise ValueError( f"ISLET1_D1_* namespace must contain ONLY the exact 5 pinned IIP-0035 IDs: " f"found {sorted(d1_namespace_ids)}, expected {sorted(pc.STAGED_D1B_AUTO_V2_PRODUCT_IDS)}" ) resolved_fullstack_ids: List[str] = [] resolved_excluded_ids: List[str] = [] resolved_route_codes: set[str] = set() for pvid in sorted(pc.STAGED_D1B_AUTO_V2_PRODUCT_IDS): if pvid not in by_id: raise ValueError(f"Loaded product registry missing staged D1b-Auto-C v2 record {pvid}") prod = by_id[pvid] if prod.get("execution_supported") is not False: raise ValueError(f"Loaded product {pvid} must keep execution_supported=False") phys_route = prod.get("physical_route_id") mapped_code = PHYSICAL_ROUTE_TO_PORTFOLIO_CODE.get(str(phys_route)) if mapped_code != "R3P": raise ValueError(f"Staged D1b-Auto-C v2 record {pvid} must bind strictly to ROUTE_3P_MODULAR_PLANAR_ENVELOPE, got {phys_route!r}") resolved_route_codes.add(mapped_code) binding = prod.get("staged_d1b_auto_v2_donor_binding") or {} role = str(binding.get("role") or "") gates_str = str(binding.get("stage0_promotion_gates") or "") if role in D1B_FULLSTACK_CANDIDATE_ROLES: if "EXCLUDED_FROM_FULLSTACK_CLEARANCE" in gates_str: raise ValueError(f"Full-product candidate {pvid} must not be marked excluded from full-stack clearance") resolved_fullstack_ids.append(pvid) else: if "EXCLUDED_FROM_FULLSTACK_CLEARANCE" not in gates_str: raise ValueError(f"Component donor {pvid} ({role}) must be marked EXCLUDED_FROM_FULLSTACK_CLEARANCE") resolved_excluded_ids.append(pvid) # 4. Validate authoritative 45-cell typed product_by_gate_contract (ALL 13 fields checked semantically!) pbg = dec114_blk.get("product_by_gate_contract") if not isinstance(pbg, dict) or pbg.get("cell_count") != 45 or not isinstance(pbg.get("cells"), list) or len(pbg["cells"]) != 45: raise ValueError("DEC-114 product_by_gate_contract must define exactly 45 typed product-by-gate cells") cell_map: Dict[tuple[str, str], Dict[str, Any]] = {} for cell in pbg["cells"]: if not isinstance(cell, dict) or set(cell.keys()) != REQUIRED_CELL_KEYS: raise ValueError(f"Malformed typed cell in product_by_gate_contract: {cell!r}") if any(not isinstance(v, str) or not v.strip() or _PLACEHOLDER_TOKEN_RE.search(v) for v in cell.values()): raise ValueError(f"Empty, non-string, or placeholder field in typed cell {cell.get('product_variant_id')}:{cell.get('gate_id')}") if cell["operator"] not in VALID_CELL_OPERATORS: raise ValueError(f"Unrecognized typed cell operator {cell['operator']!r} on {cell['product_variant_id']}:{cell['gate_id']}") if cell["disposition"] not in VALID_CELL_DISPOSITIONS: raise ValueError(f"Unrecognized typed cell disposition {cell['disposition']!r} on {cell['product_variant_id']}:{cell['gate_id']}") key = (cell["product_variant_id"], cell["gate_id"]) if key in cell_map: raise ValueError(f"Duplicate product-by-gate cell: {key}") cell_map[key] = cell expected_pairs = {(p, g) for p in pc.STAGED_D1B_AUTO_V2_PRODUCT_IDS for g in EXPECTED_45_GATES} if set(cell_map.keys()) != expected_pairs: raise ValueError("Typed 45-cell product_by_gate_contract does not match exact 5 products x 9 gates Cartesian set") expected_l1a_exact_thresholds: Dict[str, str] = { "D1-01": "two_field_HLA_ABC_plus_KIR_genotyping==True;hlac_sp3c4c_class==ELIGIBLE_VL9_COMPETENT_HLAC;exclude_SP3C_SP4C_C07_C17_C1801_homozygotes_and_compound_heterozygotes", "D1-02": "OFFGRID_GUARD_011_reject_le_2mm_to_HLAC_E==True;min_mm_to_HLAC_E_valid_range_0_to_25;wt_hlac_retention_pct>=99.0;bystander_ct_pct<0.5;chr6p21_interlocus_del_pct==0.0", "D1-03": "cipsc_source_in_{ADSC_SUN_PROTECTED_CIPSC,BLOOD_ERYTHROID_CIPSC_HEAD_TO_HEAD};head_to_head_adsc_vs_blood_comparator_attested==True;TP53_BCOR_PPM1D_20q11.21_1q32.1_MDM4_hits==0;chrm_numt_amplicon_depth_x>=1000.0;chrm_novel_nonsyn_het_pct<1.0", "D1-04": "chr13_clybl_independent_from_chr19==True(distinct_chromosomes_joint_failure_unmeasured);G0_beta_htmpk_leak_pct<=0.1;hlac07_ryafsgvay_elispot_above_bg_pct<=0.1;AP1903_k>=1_is_FAIL_HARD_STOP;AP1903_k==0_exact_80digit_sound_Decimal_U95<=1.0e-8(math_count_subgate_only:exact_binomial_N_eff=299573226_PASS_vs_299573225_HOLD;Poisson_ceiling=299573228);azt_kill_measured_after_forced_chr19_loss==True;AZT_dividing_log10_kill>=4.0(admissible_range_0_to_10)", "D1-05": "L3_stage7_day28_retention_pct>=80.0;L4_stage7_day28_retention_pct>=80.0;min_L3_L4_stage7_day28_retention_pct>=80.0;RSL3_fsp1_ferroptosis_survival_pct>=80.0", "D1-06": "kir3dl1_missing_bw4_autologous_nk_lysis_pct<=8.0", "D1-07": "vtcn1_nrd1_soluble_sb7h4_shedding_pct<=10.0", "D1-08": "d1_08_patient_carries_hlac0304_bool_or_derived_from_patient_hla_c_alleles(omitted_derives_from_raw_alleles_requiring_both_alleles_in_23_allele_Lin2023_Table1_inventory_for_negative_derivation;contradiction_FAIL;null_or_UNAVAILABLE_or_unlisted_allele_blocks_negative_derivation_HOLD);if_C0304_pos:hlac0304_positive_control_valid==True_and_HLAC0304_assay;if_C0304_neg:matched_allele_positive_control_valid==True_and_matched_allele_cd8_screen_passed==True;HLAC0304_k>=1_is_FAIL_HARD_STOP;HLAC0304_k==0_exact_80digit_sound_Decimal_U95<=5.0%;T1D_serum_C5b9_k>=1_is_FAIL_HARD_STOP;T1D_serum_C5b9_k==0_exact_80digit_sound_Decimal_U95<=5.0%(math_count_subgate_only:N=59_PASS_4.9508%_vs_N=58_HOLD_5.0340%_conservative_ceiling);reported_u95_pct_mandatory_ge_unrounded_exact_bound_and_le_5.0%(missing_reported_u95_HOLD;n<59_returns_denominator_HOLD_unless_underreported_le_5.0%)", "D1-09": "autologous_sequential_6locus_gmp_turnaround_weeks<=41.0(admissible_range_1_to_104_weeks);modeled_realistic_range_29_to_41_weeks;L1A_primary_Gate0V_viral_receptor_clean", } expected_l1b_exact_thresholds: Dict[str, str] = { **expected_l1a_exact_thresholds, "D1-09": "autologous_sequential_6locus_gmp_turnaround_weeks<=41.0(admissible_range_1_to_104_weeks);structured_global_gate0v_record_required_with_mcb_lot_id==evaluated_lot_id;Gate0V_day14_log10_reduction>=3.0;Gate0V_day14_log10_reduction_l95>=3.0;Gate0V_cvb4_72h_early_titer_log10_pfu_u95<=2.0;Gate0V_day28_VP1_IE1_k>=1_is_FAIL_HARD_STOP;Gate0V_day28_VP1_IE1_k==0_U95<=0.0005(n>=5990);Gate0V_verdict==PASS;never_bare_caller_boolean;standalone_subcheck_not_live_LIMS_ledger_clearance;any_Gate0V_fail_routes_to_L1A_IL1RN", } expected_component_exact_specs: Dict[tuple[str, str], tuple[str, str]] = { ("ISLET1_D1_AUTO_V2_L2_CXCL10_SERPINB9_PDL1", "D1-08"): ( "COMPOUND_ALL_PASS", "EXCLUDED_FROM_FULLSTACK_CLEARANCE;L2_d1_08_patient_carries_hlac0304_bool_or_derived_from_patient_hla_c_alleles(omitted_derives_from_raw_alleles;contradiction_FAIL;null_or_UNAVAILABLE_blocks_derivation_HOLD);if_C0304_pos:hlac0304_positive_control_valid==True_and_L2_HLAC0304_k>=1_is_FAIL_HARD_STOP_and_L2_HLAC0304_k==0_exact_80digit_sound_Decimal_U95<=5.0%_and_reported_u95_pct_ge_unrounded_exact_bound_and_le_5.0%;if_C0304_neg:matched_allele_positive_control_valid==True_and_matched_allele_cd8_screen_passed==True_and_any_HLAC0304_k>=1_is_FAIL_HARD_STOP;optional_adverse_T1D_serum_C5b9_k>=1_triggers_FAIL_HARD_STOP_without_requiring_C5b9_interval_in_L2_subgate;full_product_D1-08_requires_assembled_L1A_or_L1B_stack", ), ("ISLET1_D1_AUTO_V2_L3_AAVS1_VTCN1_UCOE2S_ICASP9", "D1-04"): ( "COMPOUND_ALL_PASS", "EXCLUDED_FROM_FULLSTACK_CLEARANCE;L3_chr19_AAVS1_AP1903_k>=1_is_FAIL_HARD_STOP;L3_chr19_AAVS1_AP1903_k==0_exact_80digit_sound_Decimal_U95<=1.0e-8(math_count_subgate_only:exact_binomial_N_eff=299573226_PASS_vs_299573225_HOLD;Poisson_ceiling=299573228);L4_AZT_switch_requires_L4_and_assembled_stack", ), ("ISLET1_D1_AUTO_V2_L3_AAVS1_VTCN1_UCOE2S_ICASP9", "D1-05"): ( ">=", "EXCLUDED_FROM_FULLSTACK_CLEARANCE;L3_stage7_day28_retention_pct>=80.0;L4_retention_and_RSL3_require_L4_and_assembled_stack", ), ("ISLET1_D1_AUTO_V2_L3_AAVS1_VTCN1_UCOE2S_ICASP9", "D1-07"): ( "<=", "EXCLUDED_FROM_FULLSTACK_CLEARANCE;L3_vtcn1_nrd1_soluble_sb7h4_shedding_pct<=10.0", ), ("ISLET1_D1_AUTO_V2_L4_CLYBL_TANDEM_TUBA1B_FSP1_CHS4_CDK1_HTMPK_F105Y", "D1-04"): ( "COMPOUND_ALL_PASS", "EXCLUDED_FROM_FULLSTACK_CLEARANCE;L4_chr13_clybl_independent_from_chr19==True(distinct_chromosomes_joint_failure_unmeasured);L4_G0_beta_htmpk_leak_pct<=0.1;L4_hlac07_ryafsgvay_elispot_above_bg_pct<=0.1;L4_azt_kill_measured_after_forced_chr19_loss==True;L4_AZT_dividing_log10_kill>=4.0(admissible_range_0_to_10);L3_AP1903_switch_requires_L3_and_assembled_stack", ), ("ISLET1_D1_AUTO_V2_L4_CLYBL_TANDEM_TUBA1B_FSP1_CHS4_CDK1_HTMPK_F105Y", "D1-05"): ( "COMPOUND_ALL_PASS", "EXCLUDED_FROM_FULLSTACK_CLEARANCE;L4_stage7_day28_retention_pct>=80.0;L4_RSL3_fsp1_ferroptosis_survival_pct>=80.0;L3_retention_requires_L3_and_assembled_stack", ), } for pvid in sorted(pc.STAGED_D1B_AUTO_V2_PRODUCT_IDS): for gid in EXPECTED_45_GATES: cell = cell_map[(pvid, gid)] if pvid == "ISLET1_D1_AUTO_V2_L1A_CIITA_CD64T_IL1RN": exp_op, exp_disp = EXPECTED_L1A_GATE_OPERATORS[gid], "REQUIRED_EXACT_PRODUCT" exp_ext_ref = f"DEC-114:{gid}" exp_thr = expected_l1a_exact_thresholds[gid] elif pvid == "ISLET1_D1_AUTO_V2_L1B_CIITA_CD64T_CD46WT_COMPARATOR": exp_op = EXPECTED_L1B_GATE_OPERATORS[gid] exp_disp = "REQUIRED_EXACT_PRODUCT_WITH_LOT_MATCHED_GATE0V" if gid == "D1-09" else "REQUIRED_EXACT_PRODUCT" exp_ext_ref = "DEC-114:D1-09+DEC-103:GATE0V" if gid == "D1-09" else f"DEC-114:{gid}" exp_thr = expected_l1b_exact_thresholds[gid] else: if gid in COMPONENT_APPLICABLE_GATES[pvid]: exp_op, exp_thr = expected_component_exact_specs[(pvid, gid)] exp_disp = "COMPONENT_EVIDENCE_ONLY_EXCLUDED_FROM_FULLSTACK" exp_ext_ref = f"DEC-114:{gid}:COMPONENT_ONLY" else: exp_op, exp_disp = "NOT_APPLICABLE", "NOT_APPLICABLE_EXCLUDED_FROM_FULLSTACK" exp_ext_ref = f"DEC-114:{gid}:COMPONENT_NOT_APPLICABLE" exp_thr = "NOT_APPLICABLE;EXCLUDED_FROM_FULLSTACK_CLEARANCE" if cell["operator"] != exp_op or cell["disposition"] != exp_disp: raise ValueError( f"Typed cell operator/disposition mismatch on {pvid}:{gid}: " f"got ({cell['operator']!r}, {cell['disposition']!r}), expected ({exp_op!r}, {exp_disp!r})" ) # Enforce exact gate-scoped external_ref (never points to a different gate!) if cell["external_ref"] != exp_ext_ref: