require_cond(err_s24_part < 1e-12 and s24["c1=0|c2=0|c3=partial|c4=0"]["modular_pct"] == r_c3_noinv["modular_pct"], "states_24 C3 partial drift") require_cond(err_s24_full < 1e-12 and s24["c1=0|c2=0|c3=full|c4=0"]["modular_pct"] == r_c3_full["modular_pct"], "states_24 C3 full drift") for reg in ("Conservative", "Central", "Upper"): p_full = ev[reg]["priors"]["p_c3_none_partial_full"][2] require_cond(0.10 <= p_full <= 0.17, f"InvVax Stage-0 prior out of [0.10, 0.17] for {reg}: {p_full}") max_unrounded_err = max(err_l1, err_hon, err_noinv, err_full, err_cap89, err_s24_part, err_s24_full) # Illustrative H3 channel-budget omega sensitivity (ZERO ABT-199, ZERO CCL22 double-count) F_a, F_b, F_c = 6.5, 2.5, 2.0 omega_grid = (0.0, 0.10, 0.25, 0.50, 0.75, 0.90, 1.00) sweep_noinv = [] sweep_full = [] for om in omega_grid: da_n = subadditive_channel_reduction(F_a, [1.8 / F_a, 0.6 / F_a, 0.9 / F_a], om) da_f = subadditive_channel_reduction(F_a, [2.8 / F_a, 1.8 / F_a, 0.6 / F_a, 0.9 / F_a], om) db = 1.15 dc = 0.85 raw_n = round(89.0 + da_n + db + dc, 3) raw_f = round(89.0 + da_f + db + dc, 3) sweep_noinv.append({ "omega": om, "ch_a_pp": round(da_n, 3), "ch_b_pp": db, "ch_c_pp": dc, "raw_c3_pct": raw_n, "capped_c3_pct": min(93.0, raw_n), }) sweep_full.append({ "omega": om, "ch_a_pp": round(da_f, 3), "ch_b_pp": db, "ch_c_pp": dc, "raw_c3_pct": raw_f, "capped_c3_pct": min(94.2, raw_f), }) require_cond(sweep_noinv[3]["raw_c3_pct"] >= 93.0 and sweep_full[3]["raw_c3_pct"] >= 94.2, "Clean central omega=0.50 must support 93.0%/94.2%") require_cond(all(sweep_full[i]["raw_c3_pct"] >= sweep_full[i + 1]["raw_c3_pct"] for i in range(len(omega_grid) - 1)), "Omega sweep must be monotonically non-increasing") tak101_hl_min = round((7.0 * 24.0) / 4.9, 1) tak101_hl_max = round((7.0 * 24.0) / 2.0, 1) kan101_geomean_hl = round((7.0 * 1440.0) / 31.72, 1) require_cond(tak101_hl_min == 34.3 and tak101_hl_max == 84.0, f"TAK-101 7d half-lives mismatch: {tak101_hl_min}..{tak101_hl_max}") require_cond(abs(kan101_geomean_hl - 317.8) < 0.2, f"KAN-101 geomean half-lives mismatch: {kan101_geomean_hl}") return { "invvax_evidence_fidelity": { "schedule_days": [-28, -21, -7], "prospective_clearance_requirement": "Measured pre-transplant Day -4 plasma (< plasma_llod <= 1.0 ng/mL) and tissue (< tissue_llod <= 1.0 ng/g) clearance is a PROSPECTIVE Gate-34 requirement (not yet observed).", "unsourced_cnp103_1p5h_claim_removed": True, "cnp103_sponsor_antigen_panel": ["preproinsulin", "GAD65", "IGRP", "ZnT8"], "tak101_sister_nanoparticle_free_gliadin_t_half_h_range": [2.0, 4.9], "tak101_7day_half_lives_range": [tak101_hl_min, tak101_hl_max], "tak101_provenance": "Kelly et al. 2021 Gastroenterology (PMID:33722583 / PMC9053078): celiac sister-study nanoparticle-free gliadin plasma measurement; does NOT certify CNP-103 plasma or tissue clearance.", "kan101_celiac_geomean_t_half_min": 31.72, "kan101_7day_geomean_half_lives": kan101_geomean_hl, "kan101_caveats": "Murray et al. 2023 (PMID:37329900) geometric mean with high inter-individual variability (not worst-case T1D bound); Phase 2 NCT06001177 primary histological outcome was NOT statistically significant.", "cnp103_trial_scope": "NCT06783309 enrolls newly diagnosed T1D patients (NOT islet transplant recipients), has NO posted results, and provides zero human C-peptide graft efficacy readouts.", "pvt201_and_blimp1_scope_corrections": { "PVT201_NCT06798454": "PBC/PSC clinical program (NOT T1D).", "Garnica_2025_PMID_40066448": "Mouse CNS (EAE) BLIMP-1 TR1 study (NOT human T1D).", }, "hla_enrollment_vs_efficacy_note": "HLA-unrestricted trial enrollment does NOT guarantee 100% clinical efficacy across all HLA genotypes; zero-AE guarantee removed.", "human_t1d_cpeptide_readouts_count": 0, "honest_solo_c3_lift_pp_range": [2.5, 3.0], "honest_solo_c3_lift_pp_central": 2.8, "stage0_prior_strictly_bounded_pct": [10.0, 17.0], "master_contract_invvax_priors_pct": { "Conservative": round(ev["Conservative"]["priors"]["p_c3_none_partial_full"][2] * 100.0, 2), "Central": round(ev["Central"]["priors"]["p_c3_none_partial_full"][2] * 100.0, 2), "Upper": round(ev["Upper"]["priors"]["p_c3_none_partial_full"][2] * 100.0, 2), }, }, "clinical_trials_verified_snapshot": PINNED_CLINICAL_TRIALS_SNAPSHOT, "h3_channel_sensitivity_disclosure": ( "Illustrative channel-budget sensitivity ONLY: arm-specific H3 marginals and the shared H3 common cap " "(c3: 89.0% -> 93.0% No-InvVax / 94.2% Full) are explicit scenario assumptions preceding the illustrative omega sweep. " "Holding the shared common H3 cap fixed at 89.0% shifts standalone full modular success from 63.2079% to 60.9698% " "(a 2.2381 pp common-cap scenario effect). Phantom ABT-199 (+0.25 pp) and CCL22 double-counting are removed." ), "h3_scenario_input_ledger": { "shared_common_h3_cap_baseline_pct": 89.0, "shared_common_h3_cap_noinv_pct": 93.0, "shared_common_h3_cap_full_pct": 94.2, "common_cap_scenario_effect_exact_pp": common_cap_effect_exact, "common_cap_scenario_effect_pct_pp": round(common_cap_effect_exact, 4), "arm_level_inputs_and_gates": [ {"arm": "A", "h3_base": 0.57, "h3_noinv": 0.57, "h3_full": 0.57, "adjunct_exposure": "NONE (frozen; pre-existing catalase hydrogel only)", "qualifying_gates": ["FROZEN_INVARIANT"]}, {"arm": "B", "h3_base": 0.64, "h3_noinv": 0.70, "h3_full": 0.73, "adjunct_exposure": "SHIELD + INS L82I + Cuff v2.0 (+ prospective InvVax in Full)", "qualifying_gates": ["Gate 34-SHIELD-SEL", "Gate 34-INS-L82I-ELISA-PE2MAX", "Gate 34-CUFF-V2-DISULFIDE-C5B9", "Gate 34-INVVAX-RECALL"]}, {"arm": "X", "h3_base": 0.73, "h3_noinv": 0.78, "h3_full": 0.80, "adjunct_exposure": "SHIELD + INS L82I + Cuff v2.0 (+ prospective InvVax in Full)", "qualifying_gates": ["Gate 34-SHIELD-SEL", "Gate 34-INS-L82I-ELISA-PE2MAX", "Gate 34-CUFF-V2-DISULFIDE-C5B9", "Gate 34-INVVAX-RECALL"]}, {"arm": "Y", "h3_base": 0.80, "h3_noinv": 0.83, "h3_full": 0.85, "adjunct_exposure": "SHIELD + INS L82I + Cuff v2.0 (+ prospective InvVax in Full)", "qualifying_gates": ["Gate 34-SHIELD-SEL", "Gate 34-INS-L82I-ELISA-PE2MAX", "Gate 34-CUFF-V2-DISULFIDE-C5B9", "Gate 34-INVVAX-RECALL"]}, {"arm": "D", "h3_base": 0.70, "h3_noinv": 0.75, "h3_full": 0.77, "adjunct_exposure": "SHIELD + INS L82I + Cuff v2.0 (+ prospective InvVax in Full)", "qualifying_gates": ["Gate 34-SHIELD-SEL", "Gate 34-INS-L82I-ELISA-PE2MAX", "Gate 34-CUFF-V2-DISULFIDE-C5B9", "Gate 34-INVVAX-RECALL"]}, ], }, "clean_subadditive_omega_sweep_no_invvax": sweep_noinv, "clean_subadditive_omega_sweep_with_invvax": sweep_full, "exact_2pow20_parity_wave6_master_contract": { "external_master_contract_verified": True, "external_master_contract_sha256": contract_sha256, "external_arm_manifest_sha256": manifest_sha256, "unrounded_parity_tolerance": 1e-12, "max_unrounded_parity_error_all_c3_scenarios": max_unrounded_err, "design_a_strictly_frozen_tuple": [0.88, 0.78, 0.57, 0.69], "L1_shipped_IIP0035_phi0": r_l1_phi0, "L1_honest_monoculture_phi_inc_0.50": r_l1_honest, "W6_C3_noinv_standalone_A_frozen": { **r_c3_noinv, "delta_vs_honest_l1_exact_pp": delta_noinv_exact, "delta_vs_honest_l1_pct_pp": round(delta_noinv_exact, 4), }, "W6_C3_full_standalone_A_frozen": { **r_c3_full, "delta_vs_honest_l1_exact_pp": delta_full_exact, "delta_vs_honest_l1_pct_pp": round(delta_full_exact, 4), }, "Sens_C3_full_c3cap_held_0.89": { **r_c3_cap89, "delta_vs_honest_l1_exact_pp": delta_cap89_exact, "delta_vs_honest_l1_pct_pp": round(delta_cap89_exact, 4), }, }, } # --------------------------------------------------------------------------- # PART E: STRICT Fail-Closed Gate 34 Evaluators (R2-01, R2-06, R2-07, R2-18 Closed!) # --------------------------------------------------------------------------- def _require_exact_bool(val: Any, name: str) -> bool: if type(val) is not bool: raise ValueError(f"{name} must be exact bool (str/int rejected), got {type(val).__name__}") return val def _require_exact_int(val: Any, name: str, *, lo: int | None = None, hi: int | None = None) -> int: if isinstance(val, bool) or not isinstance(val, int): raise ValueError(f"{name} must be exact int (float/bool/str rejected), got {type(val).__name__}") if abs(val) > 10 ** 300: raise ValueError(f"{name} overflowing integer rejected") if lo is not None and val < lo: raise ValueError(f"{name} out of physical bounds (< {lo}): {val}") if hi is not None and val > hi: raise ValueError(f"{name} out of physical bounds (> {hi}): {val}") return val def _require_bounded_float( val: Any, name: str, *, lo: float | None = None, hi: float | None = None, strict_lo: bool = False ) -> float: if isinstance(val, bool) or not isinstance(val, (int, float)): raise ValueError(f"{name} must be finite numeric (bool/str rejected), got {type(val).__name__}") if isinstance(val, int) and abs(val) > 10 ** 300: raise ValueError(f"{name} overflowing integer rejected before float conversion") fval = float(val) if not math.isfinite(fval) or abs(fval) > 1e300: raise ValueError(f"{name} non-finite or overflowing") if lo is not None: if (strict_lo and fval <= lo) or (not strict_lo and fval < lo): raise ValueError(f"{name} out of physical bounds ({'<=' if strict_lo else '<'} {lo}): {fval}") if hi is not None and fval > hi: raise ValueError(f"{name} out of physical bounds (> {hi}): {fval}") return fval def _require_nonempty_str(val: Any, name: str) -> str: if not isinstance(val, str) or not val.strip(): raise ValueError(f"{name} must be non-empty string, got {type(val).__name__}") return val.strip() def _is_strict_canonical_ascii_id(raw: str) -> bool: """Enforce strict canonical ASCII identifier grammar: ^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$, ASCII-only, NFKC-invariant, zero C*/Z*/M* chars.""" if not isinstance(raw, str) or not raw: return False if not raw.isascii(): return False if unicodedata.normalize("NFKC", raw) != raw: return False if any(unicodedata.category(ch)[0] in ("C", "Z", "M") for ch in raw): return False return CANONICAL_DONOR_ID_RE.fullmatch(raw) is not None def _require_canonical_ascii_id( val: Any, name: str, *, rtag: str, fail_reasons: list[str], ) -> str: """Validate strict canonical ASCII identifier grammar on Gate 34 assay/study/lot/analyte IDs without silent whitespace normalization.""" if not isinstance(val, str) or not val.strip(): raise ValueError(f"{name} must be non-empty string, got {type(val).__name__}") if not _is_strict_canonical_ascii_id(val): fail_reasons.append(f"{rtag}NONCANONICAL_ASCII_IDENTIFIER_REJECTED:{name}:{val[:64]!r}") return val.strip() return val def _scrub_donor_id_casefold(raw: str) -> str: """Apply NFKD, strip Unicode C*/Z*/M* chars, map Unicode dashes to '-', normalize digits & NFKC, and casefold.""" def _clean_pass(text: str) -> str: out_chars: list[str] = [] for ch in text: cat = unicodedata.category(ch) if cat[0] in ("C", "Z", "M"): continue if cat == "Pd" or ch in _UNICODE_DASH_CHARS: out_chars.append("-") elif cat == "Nd": out_chars.append(str(unicodedata.digit(ch))) else: out_chars.append(ch) return "".join(out_chars) nfkd_clean = _clean_pass(unicodedata.normalize("NFKD", raw)) nfkc_clean = _clean_pass(unicodedata.normalize("NFKC", nfkd_clean)) return _DONOR_INVISIBLE_OR_SPACE_RE.sub("", nfkc_clean).casefold() def _canonical_donor_identity_key(raw: str) -> str: """Compute strictly ordered separator-first -> numeric-padding-second canonical donor identity key (Audit R8-06). Order invariant: 1. NFKD -> strip C*/Z*/M* -> map Unicode dashes (`\\u2010-\\u2015`, `\\u2212`, etc.) to '-' -> NFKC -> casefold 2. Strip ALL ASCII separators (`._:-`) and any non-alphanumeric punctuation FIRST 3. Normalize every contiguous ASCII digit run by stripping leading zeros (preserving single '0') SECOND """ scrubbed = _scrub_donor_id_casefold(raw) no_sep = _ASCII_DONOR_SEPARATOR_RE.sub("", scrubbed) alnum = "".join(ch for ch in no_sep if ch.isalnum()) return re.sub(r"[0-9]+", lambda m: m.group(0).lstrip("0") or "0", alnum) def _extract_and_validate_issuer_ids( obj: dict[str, Any], *, location: str, rtag: str, fail_reasons: list[str], ) -> tuple[list[str], list[str], bool, bool]: """Validate donor/registry issuer identity fields on `obj` under strict canonical ASCII grammar (Audit R9-04). Returns (all_nonempty_issuers, valid_canonical_issuers, has_noncanonical, saw_empty_str). - Non-string values raise ValueError (FAIL_MALFORMED_INPUT). - Omitted or None fields are absent (never treated as agreeing with another absent issuer). - Exact empty strings ("") set saw_empty_str=True (missing/unestablished; fails if mixed with a non-empty issuer). - Any non-empty string violating strict canonical ASCII grammar (including whitespace-only, invisible chars, or non-ASCII chars) records INS_NONCANONICAL_DONOR_ISSUER_ID_REJECTED (FAIL). """ nonempty: list[str] = [] valid_canon: list[str] = [] has_noncanonical = False saw_empty_str = False for fld in INS_DONOR_ISSUER_FIELDS: if fld not in obj or obj[fld] is None: continue raw_val = obj[fld]