OpenIslet

scripts/verify_iip0057_foundry_v2_shield_invvax_insl82i_cuffv2.py

W6-C3 (Provisional Next-Free IIP-0057 / DEC-138 / GATE-36 / GY-035; staging slot iip0057,

script Release v0.8.0 gen-eb955f8266035aba 412 KB · 32 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0057_foundry_v2_shield_invvax_insl82i_cuffv2.py · SHA-256: 1c63dcf649c42be4…

        )

        sh_75_conf, st_75 = _reseal_module_mode(
            "shield",
            lambda c: c.update({"off_target_kd_l95_um": 7.5}),
            store_key_mode=lk_mode,
            parent_mutator=lambda p: p.update({"off_target_kd_l95_um": 7.5}),
        )
        r_r12_75_conf = evaluate_gate34_shield_sel(sh_75_conf, arm_manifest, trusted_evidence_store=st_75)
        require_cond(
            r_r12_75_conf["decision"] == "FAIL"
            and r_r12_75_conf["promotion_authorized"] is False
            and all(r_r12_75_conf[k] is None for k in shield_official_stat_keys)
            and r_r12_75_conf["shield_statistics_derivation_source"] == "WITHHELD_INTERNAL_ARCHIVE_CONFLICT",
            f"R12 SHIELD inconsistent 7.5 uM archive ({lk_mode}) must NOT emit 7.5366%, got {r_r12_75_conf}",
        )

        ins_no_sid, st_ins_no_sid = _reseal_module_mode(
            "ins",
            lambda c: c.pop("study_id", None),
            store_key_mode=lk_mode,
        )
        r_r12_ins_no_sid = evaluate_gate34_ins_l82i_elisa_pe2max(ins_no_sid, arm_manifest, trusted_evidence_store=st_ins_no_sid)
        require_cond(
            r_r12_ins_no_sid["decision"] == "HOLD"
            and r_r12_ins_no_sid["promotion_authorized"] is False
            and r_r12_ins_no_sid["unique_hla_donors_verified"] is None
            and r_r12_ins_no_sid["total_reactive_donors"] is None
            and r_r12_ins_no_sid["exact_one_sided_95pct_u95_pct"] is None
            and r_r12_ins_no_sid["ins_statistics_derivation_source"] == "UNVERIFIED_HOLD_INCOMPLETE_ARCHIVE",
            f"R12 INS omitted archived study_id ({lk_mode}) must HOLD with null official stats, got {r_r12_ins_no_sid}",
        )

    _rec("r12_shield_omitted_archived_study_id_null_stats_hold", r_r12_no_sid)
    _rec("r12_shield_omitted_archived_study_id_independent_fail_withheld", r_r12_no_sid_fail)
    _rec("r12_shield_archived_trough_gt_peak_null_stats_fail", r_r12_tgp)
    _rec("r12_shield_archived_regimen_interval_conflict_null_stats_fail", r_r12_reg)
    _rec("r12_shield_archived_7p5uM_metric_conflict_null_stats_fail", r_r12_75_conf)
    _rec("r12_ins_omitted_archived_study_id_null_stats_hold", r_r12_ins_no_sid)

    # Round-13 Audit R12-07: (1) SHIELD omitted archived peak_free_nm returns HOLD (NEVER false trough-substituted RO conflict FAIL!);
    # (2) INS missing/unauthenticated/incomplete archive + independent FAIL NEVER emits *_HOLD_* derivation source!
    ins_official_stat_keys = (
        "unique_hla_donors_verified",
        "pooled_allele_panel_observations",
        "total_hla_donors_verified",
        "total_reactive_donors",
        "exact_one_sided_95pct_u95_pct",
    )
    for lk_mode in ("record_id", "archive_sha256", "both"):
        sh_no_peak, st_no_peak = _reseal_module_mode(
            "shield",
            lambda c: c.pop("peak_free_nm", None),
            store_key_mode=lk_mode,
        )
        r_r13_sh_no_peak = evaluate_gate34_shield_sel(sh_no_peak, arm_manifest, trusted_evidence_store=st_no_peak)
        require_cond(
            r_r13_sh_no_peak["decision"] == "HOLD"
            and r_r13_sh_no_peak["verdict"] == "HOLD"
            and r_r13_sh_no_peak["promotion_authorized"] is False
            and all(r_r13_sh_no_peak[k] is None for k in shield_official_stat_keys)
            and r_r13_sh_no_peak["shield_statistics_derivation_source"] == "UNVERIFIED_HOLD_INCOMPLETE_ARCHIVE"
            and not any("REPORTED_OFF_TARGET_RO_DEVIATES" in r for r in r_r13_sh_no_peak["reasons"]),
            f"R13 SHIELD omitted archived peak_free_nm ({lk_mode}) must HOLD without false conflict: {r_r13_sh_no_peak}",
        )

        ins_base_r13, st_base_r13 = make_authenticated_gate34_fixture_and_store(
            "ins", arm_manifest=arm_manifest, store_key_mode=lk_mode
        )
        ins_no_arch_fail = copy.deepcopy(ins_base_r13)
        ins_no_arch_fail.pop("current_assay_evidence_record")
        ins_no_arch_fail["gsis_si"] = 1.0
        r_r13_ins_no_arch_fail = evaluate_gate34_ins_l82i_elisa_pe2max(
            ins_no_arch_fail, arm_manifest, trusted_evidence_store=st_base_r13
        )
        require_cond(
            r_r13_ins_no_arch_fail["decision"] == "FAIL"
            and r_r13_ins_no_arch_fail["promotion_authorized"] is False
            and all(r_r13_ins_no_arch_fail[k] is None for k in ins_official_stat_keys)
            and r_r13_ins_no_arch_fail["ins_statistics_derivation_source"] == "WITHHELD_NO_AUTHENTICATED_ARCHIVE_WITH_INDEPENDENT_FAIL"
            and "_HOLD_" not in r_r13_ins_no_arch_fail["ins_statistics_derivation_source"],
            f"R13 INS missing archive + caller FAIL ({lk_mode}) paired FAIL with HOLD label: {r_r13_ins_no_arch_fail}",
        )

        ins_nostore_fail = copy.deepcopy(ins_base_r13)
        ins_nostore_fail["hla_allele_panel_records"]["HLA-DRB1*04:01"]["reactive_donor_ids"] = ["T1D_DON_001"]
        ins_nostore_fail["hla_allele_panel_records"]["HLA-DRB1*04:01"]["reactive_donors"] = 1
        r_r13_ins_nostore_fail = evaluate_gate34_ins_l82i_elisa_pe2max(
            ins_nostore_fail, arm_manifest, trusted_evidence_store=None
        )
        require_cond(
            r_r13_ins_nostore_fail["decision"] == "FAIL"
            and r_r13_ins_nostore_fail["promotion_authorized"] is False
            and all(r_r13_ins_nostore_fail[k] is None for k in ins_official_stat_keys)
            and r_r13_ins_nostore_fail["ins_statistics_derivation_source"] == "WITHHELD_NO_AUTHENTICATED_ARCHIVE_WITH_INDEPENDENT_FAIL"
            and "_HOLD_" not in r_r13_ins_nostore_fail["ins_statistics_derivation_source"],
            f"R13 INS missing store + caller FAIL ({lk_mode}) paired FAIL with HOLD label: {r_r13_ins_nostore_fail}",
        )

        cur_k_r13 = ins_base_r13["current_assay_evidence_record"]["archive_sha256" if lk_mode == "archive_sha256" else "record_id"]
        st_tamp_r13 = copy.deepcopy(st_base_r13)
        st_tamp_r13[cur_k_r13]["gsis_si"] = 9.9
        r_r13_ins_tamp_fail = evaluate_gate34_ins_l82i_elisa_pe2max(
            ins_base_r13, arm_manifest, trusted_evidence_store=st_tamp_r13
        )
        require_cond(
            r_r13_ins_tamp_fail["verdict"] == "FAIL"
            and r_r13_ins_tamp_fail["decision"] == "FAIL_EVIDENCE_STORE_MISMATCH"
            and r_r13_ins_tamp_fail["promotion_authorized"] is False
            and all(r_r13_ins_tamp_fail[k] is None for k in ins_official_stat_keys)
            and r_r13_ins_tamp_fail["ins_statistics_derivation_source"] == "WITHHELD_NO_AUTHENTICATED_ARCHIVE_WITH_INDEPENDENT_FAIL"
            and "_HOLD_" not in r_r13_ins_tamp_fail["ins_statistics_derivation_source"],
            f"R13 INS tampered store FAIL ({lk_mode}) paired FAIL with HOLD label: {r_r13_ins_tamp_fail}",
        )

        def _strip_ins_issuer(rec: dict[str, Any]) -> None:
            for ifld in INS_DONOR_ISSUER_FIELDS:
                rec["hla_allele_panel_records"].pop(ifld, None)

        ins_no_iss_fail, st_no_iss_fail = _reseal_module_mode(
            "ins",
            _strip_ins_issuer,
            store_key_mode=lk_mode,
            parent_mutator=lambda p: p.__setitem__("gsis_si", 1.0),
        )
        r_r13_ins_no_iss_fail = evaluate_gate34_ins_l82i_elisa_pe2max(
            ins_no_iss_fail, arm_manifest, trusted_evidence_store=st_no_iss_fail
        )
        require_cond(
            r_r13_ins_no_iss_fail["decision"] == "FAIL"
            and r_r13_ins_no_iss_fail["promotion_authorized"] is False
            and all(r_r13_ins_no_iss_fail[k] is None for k in ins_official_stat_keys)
            and r_r13_ins_no_iss_fail["ins_statistics_derivation_source"] == "WITHHELD_INCOMPLETE_ARCHIVE_WITH_INDEPENDENT_FAIL"
            and "_HOLD_" not in r_r13_ins_no_iss_fail["ins_statistics_derivation_source"],
            f"R13 INS missing archived issuer + caller FAIL ({lk_mode}) paired FAIL with HOLD label: {r_r13_ins_no_iss_fail}",
        )

    _rec("r13_shield_omitted_archived_peak_null_stats_hold", r_r13_sh_no_peak)
    _rec("r13_ins_missing_archive_independent_fail_withheld", r_r13_ins_no_arch_fail)
    _rec("r13_ins_missing_store_independent_fail_withheld", r_r13_ins_nostore_fail)
    _rec("r13_ins_tampered_store_fail_withheld", r_r13_ins_tamp_fail)
    _rec("r13_ins_missing_archived_issuer_independent_fail_withheld", r_r13_ins_no_iss_fail)

    # Round-14 Review Closure:
    # (1) Reject live GATE-32 role collision on upstream_lot_evidence_record across ALL 4 modules (require GATE-34);
    # (2) Enforce collision-free GATE-36-<MODULE> current-assay gate_sources;
    # (3) Require live GATE-32 (DEC-130 / GY-010) whole-islet-debris recall co-prerequisite on SHIELD!
    for lk_mode in ("record_id", "archive_sha256", "both"):
        sh_r14, st_r14 = make_authenticated_gate34_fixture_and_store("shield", arm_manifest=arm_manifest, store_key_mode=lk_mode)
        r_r14_ok = evaluate_gate34_shield_sel(sh_r14, arm_manifest, trusted_evidence_store=st_r14)
        require_cond(
            r_r14_ok["decision"] == "PASS"
            and r_r14_ok["promotion_authorized"] is True
            and sh_r14["upstream_lot_evidence_record"]["gate_source"] == "GATE-34"
            and sh_r14["current_assay_evidence_record"]["gate_source"] == "GATE-36-SHIELD"
            and sh_r14["live_gate32_debris_recall_record"]["gate_source"] == "GATE-32",
            f"R14 valid GATE-34 + GATE-36-SHIELD + live GATE-32 ({lk_mode}) failed: {r_r14_ok}",
        )

        # Missing live_gate32_debris_recall_record -> HOLD (HOLD_MISSING_LIVE_GATE32_WHOLE_DEBRIS_RECALL)
        sh_no_g32 = copy.deepcopy(sh_r14)
        sh_no_g32.pop("live_gate32_debris_recall_record")
        r_r14_missing = evaluate_gate34_shield_sel(sh_no_g32, arm_manifest, trusted_evidence_store=st_r14)
        require_cond(
            r_r14_missing["decision"] == "HOLD"
            and r_r14_missing["promotion_authorized"] is False
            and "HOLD_MISSING_LIVE_GATE32_WHOLE_DEBRIS_RECALL" in r_r14_missing["reasons"]
            and all(r_r14_missing[k] is None for k in shield_official_stat_keys)
            and r_r14_missing["shield_statistics_derivation_source"] == "UNVERIFIED_HOLD_NO_AUTHENTICATED_ARCHIVE",
            f"R14 missing live_gate32_debris_recall_record ({lk_mode}) failed: {r_r14_missing}",
        )

        # Missing live_gate32_debris_recall_record + independent FAIL -> FAIL (NEVER *_HOLD_* derivation source!)
        sh_no_g32_fail = copy.deepcopy(sh_no_g32)
        sh_no_g32_fail["off_target_kd_l95_um"] = 7.5
        r_r14_missing_fail = evaluate_gate34_shield_sel(sh_no_g32_fail, arm_manifest, trusted_evidence_store=st_r14)
        require_cond(
            r_r14_missing_fail["decision"] == "FAIL"
            and r_r14_missing_fail["promotion_authorized"] is False
            and all(r_r14_missing_fail[k] is None for k in shield_official_stat_keys)
            and r_r14_missing_fail["shield_statistics_derivation_source"] == "WITHHELD_NO_AUTHENTICATED_ARCHIVE_WITH_INDEPENDENT_FAIL"
            and "_HOLD_" not in r_r14_missing_fail["shield_statistics_derivation_source"],
            f"R14 missing live_gate32 + independent FAIL ({lk_mode}) failed: {r_r14_missing_fail}",
        )

        # Coherent partial-epitope-coverage HOLD_PARTIAL_EPITOPE_COVERAGE_GRADED_CAP -> HOLD, promotion_authorized=False
        sh_part = copy.deepcopy(sh_r14)
        g32_part = copy.deepcopy(sh_part["live_gate32_debris_recall_record"])
        g32_part.update({
            "decision": "HOLD_PARTIAL_EPITOPE_COVERAGE_GRADED_CAP",
            "authority_scope": "REJECTED_OR_HELD",
            "bank_qualified": False,
            "promotion_authorized": False,
            "debris_recall_verdict": "HOLD_PARTIAL_EPITOPE_COVERAGE_GRADED_CAP",
            "debris_recall_l95_suppressed_frac": 0.55,
            "residual_class2_recall_u95_frac": 0.45,
            "unrelated_recall_preserved": True,
        })
        sh_part["live_gate32_debris_recall_record"] = seal_evidence_record(g32_part)
        st_part = build_trusted_store_for_obs(sh_part, store_key_mode=lk_mode)
        r_r14_part = evaluate_gate34_shield_sel(sh_part, arm_manifest, trusted_evidence_store=st_part)
        require_cond(
            r_r14_part["decision"] == "HOLD"
            and r_r14_part["promotion_authorized"] is False
            and "HOLD_LIVE_GATE32_PARTIAL_EPITOPE_COVERAGE_GRADED_CAP" in r_r14_part["reasons"],
            f"R14 partial-coverage live GATE-32 ({lk_mode}) failed: {r_r14_part}",
        )

        # Below-threshold L95 < 0.70, residual > 0.30, unrelated_recall_preserved=False -> FAIL!
        for mut_name, g32_upd, exp_code in (
            ("l95_low", {"debris_recall_l95_suppressed_frac": 0.69}, "LIVE_GATE32_DEBRIS_RECALL_L95_BELOW_0P70_FAIL"),
            ("residual_high", {"residual_class2_recall_u95_frac": 0.31}, "LIVE_GATE32_RESIDUAL_CLASS2_RECALL_U95_GT_0P30_FAIL"),
            ("unrelated_false", {"unrelated_recall_preserved": False}, "LIVE_GATE32_UNRELATED_RECALL_NOT_PRESERVED_FAIL"),
        ):
            sh_bad = copy.deepcopy(sh_r14)
            g32_bad = copy.deepcopy(sh_bad["live_gate32_debris_recall_record"])
            g32_bad.update(g32_upd)
            sh_bad["live_gate32_debris_recall_record"] = seal_evidence_record(g32_bad)
            st_bad = build_trusted_store_for_obs(sh_bad, store_key_mode=lk_mode)
            r_bad = evaluate_gate34_shield_sel(sh_bad, arm_manifest, trusted_evidence_store=st_bad)
            require_cond(
                r_bad["decision"] == "FAIL"
                and r_bad["promotion_authorized"] is False
                and any(exp_code in r for r in r_bad["reasons"]),
                f"R14 live GATE-32 {mut_name} ({lk_mode}) failed: {r_bad}",
            )
            if mut_name == "l95_low":
                r_r14_l95_fail = r_bad
            elif mut_name == "residual_high":
                r_r14_res_fail = r_bad
            else:
                r_r14_unrel_fail = r_bad

        # Live GATE-32 role collision on upstream_lot_evidence_record -> explicit FAIL across ALL 4 modules!
        sh_coll = copy.deepcopy(sh_r14)
        up_coll = copy.deepcopy(sh_coll["upstream_lot_evidence_record"])
        up_coll["gate_source"] = "GATE-32"
        sh_coll["upstream_lot_evidence_record"] = seal_evidence_record(up_coll)
        st_coll = build_trusted_store_for_obs(sh_coll, store_key_mode=lk_mode)
        r_r14_coll = evaluate_gate34_shield_sel(sh_coll, arm_manifest, trusted_evidence_store=st_coll)
        require_cond(
            r_r14_coll["decision"] == "FAIL"
            and r_r14_coll["promotion_authorized"] is False
            and any("LIVE_GATE32_ROLE_COLLISION_REJECTED" in r for r in r_r14_coll["reasons"]),
            f"R14 upstream GATE-32 role collision ({lk_mode}) failed: {r_r14_coll}",
        )

    _rec("r14_shield_live_gate32_debris_recall_full_credit_pass", r_r14_ok)
    _rec("r14_shield_missing_live_gate32_debris_recall_hold", r_r14_missing)
    _rec("r14_shield_missing_live_gate32_plus_independent_fail_withheld", r_r14_missing_fail)