"prior_qualification_authentication": None, "legacy_result_summary": None, "gate0v_result_summary": None, "authenticated_bank_qualification_record": None, }, 2, ) except (OSError, UnicodeDecodeError, json.JSONDecodeError, TypeError, ValueError, OverflowError, RecursionError) as exc: err_holds = ["HOLD_INVALID_INPUT_JSON", f"HOLD_COMPOSITE_MALFORMED_LOT_JSON:{type(exc).__name__}"] if isinstance(exc, RecursionError): err_holds.insert(1, "HOLD_COMPOSITE_AMBIGUOUS_OR_NONCANONICAL_LOT_JSON:JSON_DEPTH_OR_RECURSION_LIMIT_EXCEEDED") return ( { "composite_verdict": "HOLD_COMPOSITE_RELEASE", "release_authorizing": False, "bank_qualification_authorized": False, "qualification_scope": QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL, "physical_qualification_complete": False, "operational_tier": None, "hard_stops": [], "holds": err_holds, "lot_binding": None, "tested_vs_inherited_scope": None, "prior_qualification_authentication": None, "legacy_result_summary": None, "gate0v_result_summary": None, "authenticated_bank_qualification_record": None, }, 2, ) res = evaluate_composite_clinical_release( doc, legacy_evaluator=legacy_evaluator, gate0v_evaluator=gate0v_evaluator, trusted_qualification_store=trusted_qualification_store, openislet_root=openislet_root, nw08_ocr_json_path=nw08_ocr_json_path, ) verdict = res["composite_verdict"] if verdict in PASS_VERDICTS: return res, 0 if verdict == "FAIL_HARD_STOP_COMPOSITE_RELEASE": return res, 3 return res, 2 def build_legacy_complete_stage0_observations( *, lot_id: str, mcb_id: str, product_variant_id: str | None = None, product_variant: str | None = None, beta_only_cells_scored: float = 5990.0, ) -> Dict[str, Any]: """ Real Stage-0 observation set using canonical `wetlab_endpoint_contract_v0.8.0.json` metadata keys (`product_variant_id`, `current_lot_id`, `mcb_id`) that clears live OpenIslet `scripts/wetlab_contract.py` to `READY_FOR_ENCAPSULATION_COMPLETE_STAGE0_EVIDENCE` for `execution_supported: true` products even with beta-only Gate 0V n = 5,990 — proving why the executable composite wrapper is mandatory! """ pvid = ( product_variant_id if product_variant_id is not None else (product_variant if product_variant is not None else "ISLET1_A4_ARM1B") ) return { "current_lot_id": lot_id, "mcb_id": mcb_id, "product_variant_id": pvid, "obs_icasp9_log10_kill": 4.6, "obs_tp53_ppm1d_bcor_vaf": 0.0, "obs_castseq_translocation_freq": 0.0, "obs_chop_coincidence_fold": 1.15, "obs_hc10_surface_fold_wt": 1.05, "obs_gate0m_shutoff_t90_min": 2.2, "obs_basal_insulin_frac_peak": 0.09, "obs_glucose_threshold_mM": 5.1, "obs_hlae_hour0_molecules": 18000.0, "obs_cd47_hour0_molecules": 220000.0, "obs_nkg2a_lysis_pct": 5.5, "obs_serpinb9_hour0_uM": 0.35, "obs_regimeII_lysis_2h_pct": 5.0, "obs_lot_ocr_ratio": 1.02, "obs_hlae_hour0_molecules_se": 200.0, "obs_cd47_hour0_molecules_se": 1000.0, "obs_stage7_yield_ratio": 0.985, "obs_stage7_yield_se": 0.01, "obs_cd47_fold": 8.0, "obs_cd47_fold_se": 0.01, "obs_serpinb9_log10_kass": 6.4, "obs_serpinb9_log10_kass_se": 0.01, "obs_icasp9_log10_kill_se": 0.05, "obs_pouch_min_po2_mmhg": 23.0, "obs_pouch_min_po2_se": 0.01, "obs_pouch_max_h2o2_uM": 2.0, "obs_pouch_max_h2o2_se": 0.01, "obs_pouch_max_ph": 7.40, "obs_pouch_max_ph_se": 0.001, "obs_ifng_hla_dr_dq_negative_pct": 99.99, "obs_ifng_hla_dr_dq_negative_se": 0.001, "obs_tp53_ppm1d_bcor_duplex_depth": 62958.0, "obs_castseq_duplex_or_amplicon_depth": 62958.0, "obs_mcb_effective_clonogenic_trials": 299573228.0, "obs_mcb_clonogenic_survivor_count_k": 0, "obs_nkg2a_lysis_se": 0.5, "obs_nkg2c_adaptive_nk_lysis_pct": 5.0, "obs_nkg2c_adaptive_nk_lysis_se": 0.5, "obs_kir_nkg2a_neg_nk_lysis_pct": 5.5, "obs_kir_nkg2a_neg_nk_lysis_se": 0.5, "obs_phagocytosis_index_pct": 3.5, "obs_phagocytosis_index_se": 0.5, "obs_chronic_capsule_thickness_um": 9.5, "obs_outer_band_kperf_s_inv": 0.1358, "obs_indirect_apc_cd4_ifng_si": 1.4, "obs_indirect_apc_dq2_dq8_cd4_stimulation_index": 1.2, "obs_gate0d_activated_cd4_fasl_apoptosis_pct": 85.0, "obs_gate0d_transwell_beta_annexin_v_pct": 6.0, "obs_exogenous_b2m_w632_surface_fold_isotype": 1.05, "obs_exogenous_b2m_t1d_ctl_lysis_pct": 2.0, "obs_gate0m_glucagon_2mM_fold_increase": 2.4, "obs_residual_psc_effective_fraction": 1.0e-10, "obs_residual_psc_effective_trials": 299573228.0, "obs_20q11_bcl2l1_cnv_ratio": 2.00, "obs_20q11_bcl2l1_single_cell_mosaic_fraction": 0.002, "obs_hazard_state_prolif_survivor_count_k": 0.0, "obs_hazard_state_prolif_effective_trials": 299573228.0, "obs_cd47_p10_single_cell_molecules": 210000.0, "obs_cd47_p10_single_cell_se": 2000.0, "obs_hypoxic_72h_cd47_p10_single_cell_molecules": 182000.0, "obs_hypoxic_72h_cd47_p10_single_cell_se": 500.0, "obs_hypoxic_72h_hlae_p10_single_cell_molecules": 15200.0, "obs_hypoxic_72h_hlae_p10_single_cell_se": 50.0, "obs_hypoxic_72h_cd47_retention_molecules": 183354.0, "obs_hypoxic_72h_cd47_retention_se": 500.0, "obs_hypoxic_72h_hlae_retention_molecules": 15250.0, "obs_hypoxic_72h_hlae_retention_se": 50.0, "obs_periimplant_fluid_film_um": 35.0, "obs_explant_en_bloc_recovery_fraction": 0.995, "obs_explant_en_bloc_recovery_se": 0.001, "obs_gate0s_ap1903_supernatant_insulin_dump_fraction_24h": 0.08, "obs_gate0s_ap1903_1h_insulin_burst_iu": 1.8, "obs_ap1903_pulsed_pk_log10_kill": 4.6, "obs_ap1903_monotherapy_pulsed_pk_log10_kill": 4.5, "obs_ap1903_step1_sublethal_survivor_count_k": 0.0, "obs_ap1903_step1_effective_trials": 29957323.0, "obs_hypoxic_15mmhg_f_isr_translation_ratio": 0.78, "obs_iec_cd47_p10_molecules": 195000.0, "obs_iec_cd47_p10_se": 2000.0, "obs_iec_abo_ab_antigen_mfi_ratio": 1.01, "obs_iec_abo_ab_antigen_mfi_se": 0.005, "obs_post_stress_nkg2d_dnam1_attributed_lysis_pct": 2.5, "obs_senescent_p16_sasp_positive_cell_pct": 0.3, "obs_nkg2a_neg_kir2dl_neg_nkg2c_pos_nk_lysis_pct": 5.2, "obs_nkg2a_neg_kir2dl_neg_nkg2c_pos_nk_lysis_se": 0.5, "obs_il12_il18_sirpa_low_nk_lysis_pct": 6.4, "obs_il12_il18_sirpa_low_nk_lysis_se": 0.6, "obs_cd47_cc2c6_over_b6h12_ratio": 0.94, "obs_complement_c3b_opsonized_phagocytosis_pct": 3.2, "obs_complement_c3b_opsonized_phagocytosis_se": 0.4, "obs_iec_vascular_support_viability_pct": 91.5, "obs_recipient_insulin_clearance_tau_min": 6.5, "obs_12pulse_unprimed_hypoxic_serial_lysis_pct": 5.8, "obs_hlae_nkg2c_over_nkg2a_kd_ratio": 4.8, "obs_immaturity_corner_min_glucose_mM": 3.85, "obs_alpha_counterregulatory_gain_ratio": 0.92, "obs_ucn3_maturity_ratio": 0.88, "obs_combined_stress_embodiment_a_star_lysis_pct": 5.8, "obs_combined_stress_comp_r4_lysis_pct": 5.2, "obs_combined_stress_comp_r4_gsis_si": 2.9, "obs_combined_stress_comp_r4_viable_beta_mass_pct": 91.0, "obs_combined_stress_comp_r4_shutoff_t90_min": 2.1, "obs_combined_stress_comp_r4_max_h2o2_uM": 2.8, "obs_combined_stress_comp_r4_max_ph": 7.38, "obs_gate0v_cvb_day14_log10_viral_reduction": 4.2, "obs_gate0v_day28_persistent_vp1_ie1_positive_cell_pct": 0.0, "obs_gate0v_day28_persistent_vp1_ie1_cells_scored": beta_only_cells_scored, "obs_post_stress_20q11_bcl2l1_outgrowth_fold": 0.92, "obs_assembled_cassette_chandler_loop_sc5b9_fold": 1.25, "obs_assembled_cassette_chandler_loop_platelet_retention_pct": 86.0, "obs_hypoxic_72h_five_transgene_joint_above_threshold_fraction": 0.95, "obs_apoptotic_effero_clearance_retention_pct_of_wt": 92.0, "obs_nutlin3a_p21_mdm2_fold_induction": 8.4, "obs_vascular_pericyte_ng2_pdgfrb_coverage_pct": 78.0, "obs_assembled_cluster_slc18a1_enterochromaffin_pct": 0.3, "obs_assembled_cluster_ins_gcg_polyhormonal_pct": 0.8, "obs_assembled_cluster_ki67_progenitor_pct": 0.1, "obs_post_stress_mafa_nkx61_beta_identity_retention_pct": 91.0, } def _make_composite_bundle( lot_id: str, mcb_id: str, product_variant_id: str, legacy_obs: Dict[str, Any], gate0v_obs: Dict[str, Any], *, prior_bank_qual_record: Dict[str, Any] | None = None, nw08_route_id: str | None = None, nw08_measurement_evidence_sha256: str | None = None, nw08_measurement_not_before_utc: str | None = None, require_trusted_nw08_ocr_record: bool | None = None, ) -> Dict[str, Any]: doc: Dict[str, Any] = { "lot_id": lot_id, "mcb_id": mcb_id, "product_variant_id": product_variant_id, "legacy_stage0_observations": legacy_obs, "gate0v_wholegraft_payload": gate0v_obs, } if prior_bank_qual_record is not None: doc["prior_bank_qualification_record"] = prior_bank_qual_record if nw08_route_id is not None: doc["nw08_route_id"] = nw08_route_id if nw08_measurement_evidence_sha256 is not None: doc["nw08_measurement_evidence_sha256"] = nw08_measurement_evidence_sha256 if nw08_measurement_not_before_utc is not None: doc["nw08_measurement_not_before_utc"] = nw08_measurement_not_before_utc if require_trusted_nw08_ocr_record is not None: doc["require_trusted_nw08_ocr_record"] = require_trusted_nw08_ocr_record doc["payload_sha256"] = compute_composite_payload_sha256(doc) return doc def run_differential_self_test(openislet_root: Path) -> Dict[str, Any]: """ Execute the Round-02 differential test suite importing REAL read-only OpenIslet/scripts/wetlab_contract.py AND verify_iip0043_wholegraft_gate0v_and_calibration.py, proving B1 (external trusted store), B2 (canonical product/lot/MCB reconciliation), B6 (adverse supplemental data adjudication & tier-distinct PASS codes), and CLI fail-closed HOLD. """ wc_path = openislet_root / "scripts" / "wetlab_contract.py" wc_sha_before = hashlib.sha256(wc_path.read_bytes()).hexdigest() wc = _load_module("openislet_wetlab_contract_ro", wc_path) v38 = _get_v38_module() leg_fn = wc.evaluate_stage0_decision_tree g0v_fn = v38.evaluate_wholegraft_gate0v_and_stress_ap1903 bank_lot_id = "BANK-2026-MCB01-Q01" clin_lot_id = "LOT-2026-CLIN-001" mcb_id = "MCB-ISLET1-A-001" pv_lead = "ISLET1_A4_ARM1B" cases: List[Dict[str, Any]] = [] def _run_case(