if prec is not None: tp = parse_utc_iso_ts(prec.get("recorded_at_utc")) if tp is not None and t_acq < tp: fails.append(f"FAIL_CHECK_D3B_ASSAY_ACQUIRED_BEFORE_{plbl}") if need_g31_a: bound_3a = d3b_ev.get("d3a_lot_receipt_sha256s") if not ( isinstance(bound_3a, list) and len(bound_3a) >= 3 and all(is_valid_sha256_hex(h) for h in bound_3a) and d3a_verified_hashes and set(bound_3a) == set(d3a_verified_hashes) ): fails.append("FAIL_CHECK_D3B_ASSEMBLED_MISSING_D3A_RECEIPT_DIGEST_BINDING") if d3a_max_recorded_ts is not None and t_acq < d3a_max_recorded_ts: fails.append("FAIL_CHECK_D3B_ASSAY_ACQUIRED_BEFORE_D3A_COMPLETION") tr_lot = str(d3b_ev.get("treated_lot_id", "")).strip() nt_lot = str(d3b_ev.get("nt_control_lot_id", "")).strip() if not tr_lot or not nt_lot or tr_lot != nt_lot or (lot_3b and tr_lot != lot_3b): fails.append("FAIL_CHECK_D3B_UNMATCHED_TREATED_VS_NT_LOT_ID") if not (is_strict_bool(d3b_ev.get("same_product_nt_sirna")) and d3b_ev["same_product_nt_sirna"]): fails.append("FAIL_CHECK_D3B_MISSING_SAME_PRODUCT_NT_SIRNA") if not (is_strict_bool(d3b_ev.get("parental_attribution_included")) and d3b_ev["parental_attribution_included"]): fails.append("FAIL_CHECK_D3B_MISSING_PARENTAL_ATTRIBUTION_ARM") req_c = SHIELD_COMPONENTS_BY_PRODUCT.get(prod_3b, frozenset()) f3_sh = d3b_ev.get("f3_sirna_shield_by_component") nt_sh = d3b_ev.get("nt_sirna_shield_by_component") par_sh = d3b_ev.get("parental_shield_by_component") if not (isinstance(f3_sh, Mapping) and isinstance(nt_sh, Mapping) and isinstance(par_sh, Mapping) and set(f3_sh.keys()) == req_c and set(nt_sh.keys()) == req_c and set(par_sh.keys()) == req_c): fails.append("FAIL_CHECK_D3B_INCOMPLETE_INTERVENTION_SHIELD_RECORDS") else: for cname in sorted(req_c): fv, nv, pv = f3_sh.get(cname), nt_sh.get(cname), par_sh.get(cname) if not (is_finite_num(fv) and is_finite_num(nv) and is_finite_num(pv) and float(nv) > 0.0 and float(pv) > 0.0): fails.append(f"FAIL_CHECK_D3B_INVALID_SHIELD_VALUE:{cname}") elif (100.0 * float(fv) / float(nv)) < 85.0: fails.append(f"FAIL_CHECK_D3B_SHIELD_PRESERVATION_BELOW_85PCT:{cname}") if spec_3b is not None: req_lin = REQUIRED_HOUR0_LINEAGES_IEC if d3b_scope == "IEC_ONLY_NON_ASSEMBLED" else REQUIRED_HOUR0_LINEAGES_FULL _validate_lineage_hour0_density( spec_3b, d3b_ev.get("hour0_density_by_lineage"), required_lineages=req_lin, fails=fails, prefix="CHECK_D3B", ) else: fails.append("FAIL_CHECK_D3B_INVALID_STATUS") verdict = "FAIL" if fails else ("HOLD" if holds else "PASS_DESCRIPTIVE_PILOT_ZERO_ODDS_GY037_WARN_RETAINED") return { "gate": "GATE-43", "verdict": verdict, "release_authorizing": False, "adoption_authority": False, "live_ledger_authenticated": False, "bank_registry_verified_live": False, "gy037_warn_retained": True, "gy037_revocation_eligible": False, "upstream_archive_verification": OFFLINE_ARCHIVE_NOTE, "live_odds_delta_pp": 0.0, "prospective_odds_delta_pp": 0.0, "failures": fails, "holds": holds, } # --------------------------------------------------------------------------- # Deterministic Positive Fixture Builders & 320/320 Adversarial Self-Tests # --------------------------------------------------------------------------- def _sign_receipt(body: dict[str, Any]) -> dict[str, Any]: out = dict(body) out["receipt_sha256"] = compute_receipt_sha256(out) return out def _mk_r8_coating(tag: str = "PFD-R3P") -> dict[str, str]: return { "coating_article_id": f"ART-{tag}-01", "coating_formulation_rev": "REV-1.0", "coating_lot_id": f"COAT-LOT-{tag}-001", "matched_blank_vehicle_lot_id": f"BLANK-VEH-{tag}-001", "exposure_protocol_id": f"EXP-SOP-{tag}-V1", "api_batch_id": f"API-BATCH-{tag}-2026A", } def _mk_r8_oq012( raw_cells: int = 1_000_000_000, f_clon: float = 0.50, eta: float = 0.80, n_eff: int = 400_000_000, k: int = 0, regrowth_ok: bool = True, ) -> dict[str, Any]: u95_f = float(recompute_clopper_pearson_u95_decimal_n_eff(max(1, n_eff))) return { "survivors_k": k, "raw_cells_tested": raw_cells, "clonogenic_fraction_f": f_clon, "detection_efficiency_eta": eta, "effective_trials_n_eff": n_eff, "regrowth_assay_verified": regrowth_ok, "clonogenic_escape_u95": u95_f, } def _mk_r8_switch_parity(ctrl_lot_id: str = "CTRL-LOT-001") -> dict[str, Any]: t24 = [99.94, 99.95, 99.93, 99.95, 99.94, 99.96] c24 = [99.93, 99.94, 99.93, 99.94, 99.93, 99.95] t72 = [99.994, 99.995, 99.994, 99.995, 99.994, 99.996] c72 = [99.993, 99.994, 99.994, 99.994, 99.993, 99.995] d24 = [t24[i] - c24[i] for i in range(6)] d72 = [t72[i] - c72[i] for i in range(6)] l24 = paired_t_summary(d24)[3] l72 = paired_t_summary(d72)[3] return _sign_receipt({ "comparator_control_lot_id": ctrl_lot_id, "block_ids": [f"SWB-{i+1}" for i in range(6)], "treated_24h_kill_pct_by_block": t24, "control_24h_kill_pct_by_block": c24, "treated_72h_kill_pct_by_block": t72, "control_72h_kill_pct_by_block": c72, "reported_l95_24h_delta_pp": round(l24, 8), "reported_l95_72h_delta_pp": round(l72, 8), "control_oq012_clonogenic_block": _mk_r8_oq012(), }) def _mk_r8_readout2( *, matched_comparator_id: Optional[str] = None, block_prefix: str = "BLK", meas_id: Optional[str] = None, lot_id: str = "LOT-Y-001", stored_u95_iu: float = 115.0, stored_max_iu: float = 122.0, gate0s_cleared: bool = False, gate0s_receipt: Optional[dict[str, Any]] = None, rule_s8: bool = False, rule_s8_k: int = 1, rule_s8_design: str = "SINGLE_PRESPECIFIED_PRIMARY", gate0m_applicable: bool = False, stage7_start_utc: str = "2026-10-01T00:00:00Z", sort_reaggregation_utc: str = "2026-10-15T00:00:00Z", assay_harvest_utc: Optional[str] = None, lot_jitter: float = 0.0, pure_endocrine_ocr: float = 3.15, registered_mixture_id: str = "REF_60_30_10", beta_cell_fraction: float = 0.60, alpha_cell_fraction: float = 0.30, delta_cell_fraction: float = 0.10, n_blocks: int = 6, dec084_receipt: Optional[dict[str, Any]] = None, post_sort_zm_regimen: str = "S7W0_ONLY_0UM_POST_SORT", post_sort_zm_uM: float = 0.0, vascular_iec_coassembled: bool = True, pre_coassembly_vasc_ok: bool = True, specimen_id: Optional[str] = None, intervention_cohort_id: Optional[str] = None, candidate_gene: Optional[str] = None, trace_collected_at_utc: Optional[str] = None, ) -> dict[str, Any]: def _mk_blocks(offset: float) -> list[dict[str, Any]]: blks: list[dict[str, Any]] = [] for i in range(n_blocks): d = 0.04 * (i - 2.5) eta_i = 0.84 z1_v = round(2.1 + offset * 0.25 + 0.12 * d + 0.02 * lot_jitter, 4) z2_v = round(1.8 + offset * 0.20 + 0.10 * d + 0.03 * lot_jitter, 4) # Peak1/Basal1 ~ 7.5-8.2x (Basal1/Peak1 ~ 0.125 <= 0.15) so Gate 0M fixtures cleanly clear Basal1/Peak1 <= 0.15! b1_val = round(0.40 + 0.005 * i + 0.004 * lot_jitter, 4) pk_ratio = round(7.6 + offset * 0.4 + d + 0.05 * lot_jitter, 4) pk1_val = round(b1_val * pk_ratio, 4) l1_val = round(0.42 + 0.005 * i + 0.004 * lot_jitter, 4) h1_val = round(l1_val + z1_v / eta_i, 6) l2_val = round(0.44 + 0.005 * i + 0.004 * lot_jitter, 4) h2_val = round(l2_val + z2_v / eta_i, 6) kcl_val = round(h2_val + 1.40 + 0.04 * i + 0.02 * lot_jitter, 6) row: dict[str, Any] = { "block_id": f"{block_prefix}-{offset:.0f}-{i+1}", "trace_id": f"TR-{block_prefix}-{lot_id}-{offset:.0f}-{i+1}", "pulse1_si": round(h1_val / l1_val, 4), "pulse1_peak_to_basal_ratio": pk_ratio, "pulse1_peak_time_min": round(5.2 - offset * 0.3 + 0.1 * i, 4), "basal1_value": b1_val, "peak1_value": pk1_val, "low1_value": l1_val, "high1_value": h1_val, "low2_value": l2_val, "high2_value": h2_val, "kcl_value": kcl_val, "eta_sort_viable_recovery": eta_i, "pulse2_si": round(h2_val / l2_val, 4), "z1_increment": round(eta_i * (h1_val - l1_val), 4), "z2_increment": round(eta_i * (h2_val - l2_val), 4), "ref_adult_z2_increment": round(2.3 + offset * 0.20 + 0.08 * d + 0.015 * lot_jitter, 4), "chamber_tau_min": round(0.36 - offset * 0.02 + 0.01 * i, 4), "tracer_response_valid": True, "tracer_time_aligned": True, "stepdown_low2_window_min": 15.0, "stepdown_t50_min": round(1.3 - offset * 0.1 + 0.02 * i, 4), "stepdown_t90_min": round(2.6 - offset * 0.1 + 0.03 * i, 4), "glucagon_fold": round(2.5 + offset * 0.2 + d, 4), "glucose_threshold_mM": round(4.9 + 0.05 * i, 4), "ucn3_fraction": round(0.82 + 0.01 * i, 4), "counterregulation_index": round(0.90 + 0.01 * i, 4), } if matched_comparator_id is not None: mcz2 = round(z2_v / (0.97 + 0.004 * (i - 2.5)), 4) row["matched_control_z2_increment"] = mcz2 row["matched_control_output_ratio"] = round(z2_v / mcz2, 6) if rule_s8: row["rule_s8_comparator_z2_increment"] = round(z2_v / (0.94 + 0.005 * (i - 2.5)), 4) blks.append(row) return blks out: dict[str, Any] = { "canonical_readout2_producer_sha256": "1" * 64, "shared_measurement_record_id": meas_id or f"MEAS-R2-{block_prefix}-{matched_comparator_id or 'STD'}", "independent_blocks_n": n_blocks, "is_non_reference_mixture": (registered_mixture_id != "REF_60_30_10"), "registered_mixture_id": registered_mixture_id, "beta_cell_fraction": beta_cell_fraction, "alpha_cell_fraction": alpha_cell_fraction, "delta_cell_fraction": delta_cell_fraction, "preparation_process_mode": "SORTED_REAGGREGATED", "sorting_performed": True, "dual_clocks_utc": { "stage7_start_utc": stage7_start_utc, "sort_reaggregation_utc": sort_reaggregation_utc, "assay_harvest_utc": assay_harvest_utc or ("2026-11-05T00:00:00Z" if rule_s8 else "2026-10-22T00:00:00Z"), }, "alk5i_free_maturation_applied": True, "stage7_t3_10nM_and_nac_1mM_retained": True, "post_sort_endocrine_zm447439_regimen": post_sort_zm_regimen, "post_sort_zm447439_uM": post_sort_zm_uM, "vascular_iec_coassembled": vascular_iec_coassembled, "pre_coassembly_iec_vascular_function_verified": pre_coassembly_vasc_ok, "zm447439_washout_lcms_uM": 0.002, "zm447439_wash_cycles": 3, "zm447439_spike_recovery_pct": 96.0, "eta_sort_viable_recovery_pct": 84.0, "implanted_dose_ieq": 500_000.0, "mature_insulin_inventory_iu_per_dose": 108.0, "insulin_inventory_assay_specificity": "MATURE_INSULIN_SPECIFIC_LOW_PROINSULIN_CROSSREACTIVITY", "assay_cumulative_secreted_iu_equiv": 12.5, "stored_insulin_per_lot_iu": [round(min(stored_u95_iu, stored_max_iu) - 9.0 + 0.5 * i, 3) for i in range(n_blocks)], "proinsulin_to_cpeptide_content_ratio_per_lot": [round(0.042 + 0.002 * i, 4) for i in range(n_blocks)], "within_lot_technical_var_z2": 0.008, "stored_insulin_u95_iu": stored_u95_iu, "stored_insulin_max_lot_iu": stored_max_iu, "gate0s_escalation_cleared": gate0s_cleared, "gate0m_applicable": gate0m_applicable, "z_increment_units": "uIU_per_1000_IEQ_min", "z_min_floor": 1.0, "o2_40_mmhg": {"blocks": _mk_blocks(0.0)}, "o2_100_mmhg": {"blocks": _mk_blocks(1.0)}, "gate_resp1_inlet_po2_mmhg": 35.65,