or ('obs_nkg2a_lysis_pct' in validated_stage0 and validated_stage0['obs_nkg2a_lysis_pct'] <= 8.0 and nkg2a_lysis_upper95 > 8.0) or ('obs_kir_nkg2a_neg_nk_lysis_pct' in validated_stage0 and validated_stage0['obs_kir_nkg2a_neg_nk_lysis_pct'] <= 8.0 and kir_nkg2a_neg_upper95 > 8.0) or ('obs_nkg2c_adaptive_nk_lysis_pct' in validated_stage0 and validated_stage0['obs_nkg2c_adaptive_nk_lysis_pct'] <= 8.0 and nkg2c_adaptive_upper95 > 8.0) or ('obs_il12_il18_sirpa_low_nk_lysis_pct' in validated_stage0 and validated_stage0['obs_il12_il18_sirpa_low_nk_lysis_pct'] <= 10.0 and il12_il18_sirpa_low_upper95 > 10.0) or ('obs_nkg2a_neg_kir2dl_neg_nkg2c_pos_nk_lysis_pct' in validated_stage0 and validated_stage0['obs_nkg2a_neg_kir2dl_neg_nkg2c_pos_nk_lysis_pct'] <= 8.0 and receptor_neg_nkg2c_upper95 > 8.0) or ('obs_phagocytosis_index_pct' in validated_stage0 and validated_stage0['obs_phagocytosis_index_pct'] <= 5.0 and phagocytosis_upper95 > 5.0) or ('obs_complement_c3b_opsonized_phagocytosis_pct' in validated_stage0 and validated_stage0['obs_complement_c3b_opsonized_phagocytosis_pct'] <= 5.0 and c3b_phagocytosis_upper95 > 5.0) ) receptor_neg_nkg2c_nk_failed = bool( ( 'obs_nkg2a_neg_kir2dl_neg_nkg2c_pos_nk_lysis_pct' in validated_stage0 and receptor_neg_nkg2c_upper95 > 8.0 ) or ( 'obs_nkp46_innate_nk_lysis_pct' in validated_stage0 and _upper95('obs_nkp46_innate_nk_lysis_pct') > 8.0 ) ) post_stress_nkg2d_dnam1_lysis_failed = bool( 'obs_post_stress_nkg2d_dnam1_attributed_lysis_pct' in validated_stage0 and _upper95('obs_post_stress_nkg2d_dnam1_attributed_lysis_pct') > 5.0 ) s1_promoted = bool( ( serpinb9_h0_lower95 < 0.30 or lysis_2h_upper95 > 8.0 or _upper95('obs_12pulse_unprimed_hypoxic_serial_lysis_pct', 5.0) > 8.0 or receptor_neg_nkg2c_nk_failed or post_stress_nkg2d_dnam1_lysis_failed or _upper95('obs_serpinb9_si', 1.2) > 1.5 or _lower95('obs_serpinb9_half_life_h', 6.0) < 4.0 or _lower95('obs_serpinb9_kass_M_s', 5e6) < 1e6 or _lower95('obs_serpinb9_log10_kass', 6.7) < 6.0 or observations.get('s1_gzmb_kass_or_pdl1_scar_failed') is True ) and lysis_2h_upper95 <= 25.0 ) catastrophic_nkg2a_lysis_exceeds_arm1x = bool( 'obs_nkg2a_lysis_pct' in validated_stage0 and ( validated_stage0['obs_nkg2a_lysis_pct'] > 15.0 or nkg2a_lysis_upper95 > 15.0 ) ) # Uncertainty-aware upper95 KIR+NKG2A- (<= 8.0%) and IL-12/IL-18 SIRPa-low (<= 10.0%) escape routing & fail-closed Track-2 B'-SCT vs HLA-G1 split (IIP-0022; DEC-101): # Preserves provisional core_14_panel compatibility when subset endpoints are unmeasured while preventing raw-mean <= 8.0% with upper95 > 8.0% from misrouting to S2 Arm 1X. kir_nkg2a_neg_nk_exceeded_raw = bool( ('obs_kir_nkg2a_neg_nk_lysis_pct' in validated_stage0 and (validated_stage0['obs_kir_nkg2a_neg_nk_lysis_pct'] > 8.0 or kir_nkg2a_neg_upper95 > 8.0)) or ('obs_il12_il18_sirpa_low_nk_lysis_pct' in validated_stage0 and (validated_stage0['obs_il12_il18_sirpa_low_nk_lysis_pct'] > 10.0 or il12_il18_sirpa_low_upper95 > 10.0)) ) _t2_route = observations.get('track2_rescue_route') if isinstance(_t2_route, str): _t2_route = _t2_route.strip() _legacy_conflated_t2 = observations.get('track2_b_sct_or_hlag1_lilrb1_rescue_qualified') is True _bsct_flag = observations.get('track2_b_sct_kir_rescue_qualified') is True _hlag1_flag = observations.get('track2_hlag1_lilrb1_rescue_qualified') is True _bsct_quant_present = any( _k in validated_stage0 for _k in ('obs_track2_bsct_kir_nkg2a_neg_nk_lysis_pct', 'obs_track2_bsct_donor_count', 'obs_track2_bsct_failing_donor_count') ) _hlag1_quant_present = any( _k in validated_stage0 for _k in ('obs_track2_hlag1_lilrb1_neg_kir_nk_lysis_pct', 'obs_track2_hlag1_donor_count', 'obs_track2_hlag1_failing_donor_count') ) _bsct_quant_cleared = bool( 'obs_track2_bsct_kir_nkg2a_neg_nk_lysis_pct' in validated_stage0 and se_provenance_by_mean.get('obs_track2_bsct_kir_nkg2a_neg_nk_lysis_pct') == 'EXPLICIT_SE_SUPPLIED' and _upper95('obs_track2_bsct_kir_nkg2a_neg_nk_lysis_pct') <= 8.0 and 'obs_track2_bsct_donor_count' in validated_stage0 and abs(validated_stage0['obs_track2_bsct_donor_count'] - round(validated_stage0['obs_track2_bsct_donor_count'])) <= 1e-9 and int(round(validated_stage0['obs_track2_bsct_donor_count'])) >= 6 and 'obs_track2_bsct_failing_donor_count' in validated_stage0 and abs(validated_stage0['obs_track2_bsct_failing_donor_count'] - round(validated_stage0['obs_track2_bsct_failing_donor_count'])) <= 1e-9 and int(round(validated_stage0['obs_track2_bsct_failing_donor_count'])) == 0 ) _hlag1_quant_cleared_uniform_8pct = bool( 'obs_track2_hlag1_lilrb1_neg_kir_nk_lysis_pct' in validated_stage0 and se_provenance_by_mean.get('obs_track2_hlag1_lilrb1_neg_kir_nk_lysis_pct') == 'EXPLICIT_SE_SUPPLIED' and _upper95('obs_track2_hlag1_lilrb1_neg_kir_nk_lysis_pct') <= 8.0 and 'obs_track2_hlag1_donor_count' in validated_stage0 and abs(validated_stage0['obs_track2_hlag1_donor_count'] - round(validated_stage0['obs_track2_hlag1_donor_count'])) <= 1e-9 and int(round(validated_stage0['obs_track2_hlag1_donor_count'])) >= 6 and 'obs_track2_hlag1_failing_donor_count' in validated_stage0 and abs(validated_stage0['obs_track2_hlag1_failing_donor_count'] - round(validated_stage0['obs_track2_hlag1_failing_donor_count'])) <= 1e-9 and int(round(validated_stage0['obs_track2_hlag1_failing_donor_count'])) == 0 ) # Deprecated conflated alias preserves legacy B'-SCT fallback candidate promotion ONLY when neither HLA-G1 route nor failing B'-SCT quant panel is present; never auto-clears HLA-G1! track2_bsct_route_promoted = bool( kir_nkg2a_neg_nk_exceeded_raw and not _hlag1_flag and _t2_route != 'TRACK2_HLAG1_LILRB1_CHALLENGER_HELD' and ( (_bsct_flag and (not _bsct_quant_present or _bsct_quant_cleared)) or (_legacy_conflated_t2 and not _bsct_flag and _t2_route is None and not _bsct_quant_present) ) ) track2_hlag1_route_attempted = bool( _hlag1_flag or _t2_route == 'TRACK2_HLAG1_LILRB1_CHALLENGER_HELD' or _hlag1_quant_present ) track2_kir_or_hlag1_fallback_promoted = bool(track2_bsct_route_promoted) kir_nkg2a_neg_nk_failed = bool( kir_nkg2a_neg_nk_exceeded_raw and not track2_bsct_route_promoted ) # S10 triggers on one-sided 95% bounds (CMV-imprinted NKG2C+NKG2A-CD57+ adaptive NK lysis upper95 > 8% OR receptor-negative NKG2A-KIR2DL-NKG2C+ NK lysis upper95 > 8% OR covalent-SCT NKG2C/NKG2A KD selectivity ratio lower95 < 4.0) or any failing S10 v3 functional/comparator panel (AUDIT-REF & IIP-0016; DEC-042/046/094): _s10_v3_active = bool( any(observations.get(_mk) is not None for _mk in STAGE0_S10_V3_METADATA_KEYS if _mk != 'current_lot_id') or any(observations.get(_bk) is not None for _bk in STAGE0_S10_V3_BOOLEAN_KEYS) or any(_ek in validated_stage0 for _ek in STAGE0_S10_V3_MEAN_KEYS) ) _has_explicit_s10_obs = bool( _s10_v3_active or 'obs_nkg2c_adaptive_nk_lysis_pct' in validated_stage0 or 'obs_nkg2a_neg_kir2dl_neg_nkg2c_pos_nk_lysis_pct' in validated_stage0 or 'obs_hlae_nkg2c_over_nkg2a_kd_ratio' in validated_stage0 or observations.get('s10_sct_selectivity_coupon_cleared_kc_ka_ge_4_and_lysis_le_8pct') is not None ) s10_v3_eval: dict | None = None s10_v3_hold_status: str | None = None if _s10_v3_active: _v3_obs = dict(observations) for _mk_v, _val_v in validated_stage0.items(): _v3_obs[_mk_v] = _val_v for _sk_v, _sval_v in validated_stage0_se.items(): _v3_obs[_sk_v] = _sval_v s10_v3_eval = evaluate_s10_functional_and_replacement_gate_v3( _v3_obs, STAGE0_S10_V3_CONSTRUCT_REGISTRY, defaulted_se_keys=defaulted_se_set, ) if not s10_v3_eval['gate_pass']: s10_v3_hold_status = str(s10_v3_eval['status']) s10_kd_ratio_lower95_sub4 = bool(_lower95('obs_hlae_nkg2c_over_nkg2a_kd_ratio', 4.5) < 4.0) s10_nkg2c_triggered = bool( ('obs_nkg2c_adaptive_nk_lysis_pct' in validated_stage0 and nkg2c_adaptive_upper95 > 8.0) or receptor_neg_nkg2c_nk_failed or s10_kd_ratio_lower95_sub4 or (_s10_v3_active and s10_v3_eval is not None and not s10_v3_eval['gate_pass']) ) s10_coupon_cleared_legacy = bool( observations.get('s10_sct_selectivity_coupon_cleared_kc_ka_ge_4_and_lysis_le_8pct') is True and not receptor_neg_nkg2c_nk_failed and ('obs_nkg2c_adaptive_nk_lysis_pct' not in validated_stage0 or nkg2c_adaptive_upper95 <= 8.0) ) # Unified S10 clearance binding: when S10 v3 panel/metadata is active, clearance is strictly bound to s10_v3_eval['gate_pass'] (defeating spoofed legacy coupon=True); bare legacy coupon=True unmasks S2 screening only and cannot clear lot_release_readiness_tier without v3 LOT_RELEASE_25K qualification (IIP-0016; DEC-094): s10_coupon_cleared = bool( s10_v3_eval['gate_pass'] if (_s10_v3_active and s10_v3_eval is not None) else s10_coupon_cleared_legacy ) s10_v3_release_qualified = bool( _s10_v3_active and s10_v3_eval is not None and s10_v3_eval['gate_pass'] is True and str(observations.get('s10_hlae_floor_mode', 'GATE_0A_SCREENING_15K')).strip() == 'LOT_RELEASE_25K' and not receptor_neg_nkg2c_nk_failed and ('obs_nkg2c_adaptive_nk_lysis_pct' not in validated_stage0 or nkg2c_adaptive_upper95 <= 8.0) ) # S2 triggers on low resting HLA-E (<15,000 molecules/cell) OR moderate CD94/NKG2A+ NK lysis in (8.0%, 15.0%], strictly when neither catastrophic (>15%) NKG2A+ lysis nor CD94-independent KIR+NKG2A- / IL-12/IL-18 SIRPa-low NK failure nor uncleared S10 NKG2C peptide-selectivity failure is active (MW-R5-S2-F01/F02 & AUDIT-REF; DEC-048/049): s2_arm1b_failed = bool( ( _lower95('obs_hlae_hour0_molecules', 20000.0) < 15000.0 or (8.0 < validated_stage0.get('obs_nkg2a_lysis_pct', 2.0) <= 15.0) ) and not catastrophic_nkg2a_lysis_exceeds_arm1x and not kir_nkg2a_neg_nk_exceeded_raw and not (s10_nkg2c_triggered and not s10_coupon_cleared) ) has_all_3_dxs_endpoints = bool( 'obs_dxs_locus4_joint_retention_fraction' in validated_stage0 and 'obs_dxs_cd47low_icasp9low_fraction' in validated_stage0 and 'obs_dxs_ap1903_cd47high_escape_fraction' in validated_stage0 ) has_explicit_dxs_clonogenic_factors = bool( 'obs_dxs_screened_cell_count' in validated_stage0 and 'obs_dxs_clonogenic_fraction' in validated_stage0 and 'obs_dxs_spike_in_detection_efficiency' in validated_stage0 ) dxs_screened_n = validated_stage0.get('obs_dxs_screened_cell_count', 0.0) dxs_f_clonogenic = validated_stage0.get('obs_dxs_clonogenic_fraction', 0.0) dxs_eta_detection = validated_stage0.get('obs_dxs_spike_in_detection_efficiency', 0.0) dxs_effective_clonogenic_n = ( dxs_screened_n * dxs_f_clonogenic * dxs_eta_detection if has_explicit_dxs_clonogenic_factors else 0.0 ) # Rare-event DX-S verification ALWAYS requires explicit obs_dxs_screened_cell_count, explicit obs_dxs_clonogenic_fraction (> 0), explicit obs_dxs_spike_in_detection_efficiency (>= 0.30), and effective clonogenic trial count >= 299,573,228 (no silent f=1.0, eta=1.0 defaults; MW-R5-S2-F03; DEC-048): dxs_explicit_se_or_cell_count_supplied = bool( has_all_3_dxs_endpoints and has_explicit_dxs_clonogenic_factors and dxs_f_clonogenic > 0.0 and dxs_eta_detection >= 0.30 and dxs_effective_clonogenic_n >= 299573228.0 ) dxs_retention_lower95 = ( min( validated_stage0['obs_dxs_locus4_joint_retention_fraction'] - 1.645 * validated_stage0_se.get('obs_dxs_locus4_joint_retention_se', 0.0), 1.0 - _poisson_exact_upper95_rate( (1.0 - validated_stage0['obs_dxs_locus4_joint_retention_fraction']) * dxs_effective_clonogenic_n, dxs_effective_clonogenic_n, ) if dxs_effective_clonogenic_n > 0.0 else 1.0, ) if 'obs_dxs_locus4_joint_retention_fraction' in validated_stage0 else 0.0 ) dxs_double_loss_upper95 = ( max( validated_stage0['obs_dxs_cd47low_icasp9low_fraction'] + 1.645 * validated_stage0_se.get('obs_dxs_cd47low_icasp9low_se', 0.0), _poisson_exact_upper95_rate( validated_stage0['obs_dxs_cd47low_icasp9low_fraction'] * dxs_effective_clonogenic_n, dxs_effective_clonogenic_n, ) if dxs_effective_clonogenic_n > 0.0 else 0.0, ) if 'obs_dxs_cd47low_icasp9low_fraction' in validated_stage0 else 1.0 ) dxs_escape_upper95 = ( max( validated_stage0['obs_dxs_ap1903_cd47high_escape_fraction'] + 1.645 * validated_stage0_se.get('obs_dxs_ap1903_cd47high_escape_se', 0.0), _poisson_exact_upper95_rate( validated_stage0['obs_dxs_ap1903_cd47high_escape_fraction'] * dxs_effective_clonogenic_n, dxs_effective_clonogenic_n, ) if dxs_effective_clonogenic_n > 0.0 else 0.0, ) if 'obs_dxs_ap1903_cd47high_escape_fraction' in validated_stage0 else 1.0 ) is_family_a_or_unspecified = bool( product_def is None or str(product_def.get('family', 'A')).upper().startswith('A') ) dxs_joint_retention_verified = bool( is_family_a_or_unspecified and has_all_3_dxs_endpoints and dxs_explicit_se_or_cell_count_supplied and validated_stage0['obs_dxs_locus4_joint_retention_fraction'] >= 0.9999 and dxs_retention_lower95 >= 0.9999 and validated_stage0['obs_dxs_cd47low_icasp9low_fraction'] <= 1e-6 and dxs_double_loss_upper95 <= 1e-6 and validated_stage0['obs_dxs_ap1903_cd47high_escape_fraction'] <= 1e-8