OpenIslet

scripts/verify_iip0043_wholegraft_gate0v_and_calibration.py

IIP-0043 / DEC-122 (CAND-034 / EXP-031 — Bucket 1 Closure, Stage S3-R2 Remediated)

script Release v0.8.0 gen-eb955f8266035aba 1008 KB · 76 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_iip0043_wholegraft_gate0v_and_calibration.py · SHA-256: 20706180ed1ed6a2…

    # 30. R06-B1b: Indirect-only marginal payload WITH conclusive adverse caspase blockade STILL emits FAIL_HARD_STOP!
    p_ind_adv = build_passing_reference_payload(use_direct_infected_veh_survivor_mode=False, openislet_root=resolved_root)
    p_ind_adv["gate0v_kill_stress_ap1903"]["active_or_persistent_hcmv_infection"]["plvap_iec"]["caspase9_3_activity_fold_over_vehicle"] = "1.2"
    _record(
        "r06_b1_indirect_only_with_adverse_caspase_preserves_hard_stop",
        "FAIL_HARD_STOP",
        _seal(p_ind_adv),
        "VIRAL_CASPASE_BLOCKADE_REQUIRES_NON_CASPASE_BACKUP_SWITCH",
    )

    # 31. R06-B2a & B2b: Exact component-probability ratio boundary in live Gate 0V evaluator:
    #     veh = 51/100, treated = 0/90402 -> u_ratio = 0.00010000201070... > 0.0001 -> HOLD!
    #     veh = 51/100, treated = 0/90404 -> u_ratio <= 0.0001 -> PASS!
    p_b2_hold = build_passing_reference_payload(openislet_root=resolved_root)
    arm_b2_h = p_b2_hold["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["alpha"]
    arm_b2_h["veh_72h_viable_n"] = 51
    arm_b2_h["veh_72h_input_n"] = 100
    arm_b2_h["ap1903_72h_input_n"] = 90402
    arm_b2_h["ap1903_72h_viable_survivors_k"] = 0
    reconcile_fixture_per_unit_counts(p_b2_hold)
    _record(
        "r06_b2_exact_component_ratio_veh51of100_0of90402_held",
        "HOLD_INCOMPLETE_OR_UNDERPOWERED",
        _seal(p_b2_hold),
        "72H_UNDERPOWERED_N_EFF_ER_STRESS_TG_OR_TM_ALPHA",
    )

    p_b2_pass = copy.deepcopy(p_b2_hold)
    p_b2_pass["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["alpha"]["ap1903_72h_input_n"] = 90404
    reconcile_fixture_per_unit_counts(p_b2_pass)
    _record(
        "r06_b2_exact_component_ratio_veh51of100_0of90404_passes",
        "PASS_WHOLEGRAFT_BANK_QUALIFICATION",
        _seal(p_b2_pass),
    )

    # 32. R06-B3a & B3b: Indeterminate straddling intervals under concurrent vehicle-control HOLD
    #     MUST return HOLD_INCOMPLETE_OR_UNDERPOWERED (NEVER FAIL_HARD_STOP and NEVER PASS!):
    #     (a) 24-h 1/5,000 vs 0.001 (L_ideal ≈ 5.06e-6 <= 0.001 < U_ideal ≈ 1.11e-3)
    #     (b) 72-h 1/20,000 vs 0.0001 (L_ideal ≈ 1.27e-6 <= 0.0001 < U_ideal ≈ 2.79e-4)
    p_strad_24 = build_passing_reference_payload(openislet_root=resolved_root)
    arm_s24 = p_strad_24["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["alpha"]
    arm_s24["veh_24h_viable_n"] = 50
    arm_s24["veh_24h_input_n"] = 1000
    arm_s24["ap1903_24h_input_n"] = 5000
    arm_s24["ap1903_24h_viable_survivors_k"] = 1
    reconcile_fixture_per_unit_counts(p_strad_24)
    _record(
        "r06_b3_24h_1of5000_straddling_under_low_veh_returns_hold_not_hard_stop",
        "HOLD_INCOMPLETE_OR_UNDERPOWERED",
        _seal(p_strad_24),
        "INDETERMINATE_INTERVAL_STRADDLING_CAP_UNDER_CONTROL_HOLD",
    )

    p_strad_72 = build_passing_reference_payload(openislet_root=resolved_root)
    arm_s72 = p_strad_72["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["delta"]
    arm_s72["veh_72h_viable_n"] = 40
    arm_s72["veh_72h_input_n"] = 1000
    arm_s72["ap1903_72h_input_n"] = 20000
    arm_s72["ap1903_72h_viable_survivors_k"] = 1
    reconcile_fixture_per_unit_counts(p_strad_72)
    _record(
        "r06_b3_72h_1of20000_straddling_under_low_veh_returns_hold_not_hard_stop",
        "HOLD_INCOMPLETE_OR_UNDERPOWERED",
        _seal(p_strad_72),
        "INDETERMINATE_INTERVAL_STRADDLING_CAP_UNDER_CONTROL_HOLD",
    )

    # 33. R06-B3c & B3d: Conclusively adverse counts under concurrent vehicle-control HOLD
    #     (L_ideal > cap!) MUST preserve FAIL_HARD_STOP:
    #     (c) 24-h 30/5,000 (L_ideal ≈ 0.00405 > 0.001) -> FAIL_HARD_STOP
    #     (d) 72-h 10/20,000 (L_ideal ≈ 0.00024 > 0.0001) -> FAIL_HARD_STOP
    p_conc_24 = copy.deepcopy(p_strad_24)
    p_conc_24["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["alpha"]["ap1903_24h_viable_survivors_k"] = 30
    reconcile_fixture_per_unit_counts(p_conc_24)
    _record(
        "r06_b3_24h_30of5000_conclusive_l_gt_cap_under_low_veh_hard_stop",
        "FAIL_HARD_STOP",
        _seal(p_conc_24),
        "AP1903_24H_KILL_BELOW_99P9PCT_ER_STRESS_TG_OR_TM_ALPHA",
    )

    p_conc_72 = copy.deepcopy(p_strad_72)
    p_conc_72["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"]["delta"]["ap1903_72h_viable_survivors_k"] = 10
    reconcile_fixture_per_unit_counts(p_conc_72)
    _record(
        "r06_b3_72h_10of20000_conclusive_l_gt_cap_under_low_veh_hard_stop",
        "FAIL_HARD_STOP",
        _seal(p_conc_72),
        "AP1903_72H_PK_KILL_BELOW_4LOG10_ER_STRESS_TG_OR_TM_DELTA",
    )

    # 34. R06-B4: Archived bank payload full canonical structure, self-digest, nested-identity reconciliation,
    #     and live Gate-0V re-verification across BOTH store layouts (embedded registry JSON & directory store)!
    with tempfile.TemporaryDirectory() as td_b4:
        td_b4_p = Path(td_b4)
        base_bank_p = build_passing_reference_payload(
            lot_id="BANK-R06B4-001",
            mcb_id="MCB-ISLET1-A-001",
            product_variant_id="ISLET1_A4_ARM1B",
            qualification_tier="BANK_QUALIFICATION",
            openislet_root=resolved_root,
        )

        def _check_bad_archive_both_layouts(tag: str, bad_arch: Dict[str, Any], rec_bank_sha: str, expected_subtoken: str | None = None) -> None:
            bad_rec = build_authenticated_bank_qualification_record(
                mcb_id="MCB-ISLET1-A-001",
                product_variant_id="ISLET1_A4_ARM1B",
                bank_lot_id="BANK-R06B4-001",
                bank_payload_sha256=rec_bank_sha,
            )
            p_surr_b4 = build_passing_reference_payload(
                lot_id="LOT-R06B4-SURR-001",
                mcb_id="MCB-ISLET1-A-001",
                product_variant_id="ISLET1_A4_ARM1B",
                qualification_tier="LOT_RELEASE_SURROGATE",
                bridged_mcb_qualification_sha256=bad_rec["sha256"],
                openislet_root=resolved_root,
            )
            reg_st = td_b4_p / f"reg_{tag}.json"
            reg_st.write_text(
                json.dumps({
                    "schema_version": TRUSTED_STORE_SCHEMA_VERSION,
                    "store_authority_id": "OPENISLET_QA_RELEASE_BOARD_V1",
                    "bank_qualifications": {bad_rec["sha256"]: bad_rec},
                    "process_qualifications": {},
                    "archived_payloads": {rec_bank_sha: bad_arch},
                }),
                encoding="utf-8",
            )
            dir_st = td_b4_p / f"dir_{tag}"
            write_record_to_trusted_qualification_store(dir_st, bad_rec, category="bank_qualifications", archived_payload=None)
            (dir_st / "archived_payloads").mkdir(parents=True, exist_ok=True)
            (dir_st / "archived_payloads" / f"{rec_bank_sha}.json").write_text(json.dumps(bad_arch), encoding="utf-8")

            both_ok = True
            last_holds: List[str] = []
            for st_layout in (reg_st, dir_st):
                r_l = evaluate_wholegraft_gate0v_and_stress_ap1903(
                    p_surr_b4, trusted_qualification_store=st_layout, openislet_root=resolved_root
                )
                last_holds = r_l["holds"]
                auth = r_l["lot_binding"]["prior_qualification_authentication"]
                if not (
                    r_l["verdict"] == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
                    and "HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD" in r_l["holds"]
                    and auth.get("archived_bank_payload_verified") is False
                    and (expected_subtoken is None or any(expected_subtoken in h for h in r_l["holds"]))
                ):
                    both_ok = False
            cases.append({
                "case": f"r06_b4_both_store_layouts_{tag}_held",
                "expected_verdict": "HOLD_INCOMPLETE_OR_UNDERPOWERED",
                "actual_verdict": "HOLD_INCOMPLETE_OR_UNDERPOWERED" if both_ok else "UNEXPECTED_PASS_OR_MISSING_TOKEN",
                "expected_token": expected_subtoken or "HOLD_MISSING_OR_INVALID_ARCHIVED_BANK_PAYLOAD",
                "hard_stops": [],
                "holds": last_holds[:4],
                "passed": both_ok,
            })

        # (i) Metadata-only stub archive
        stub_arch = {
            "lot_id": "BANK-R06B4-001",
            "mcb_id": "MCB-ISLET1-A-001",
            "product_variant_id": "ISLET1_A4_ARM1B",
            "qualification_tier": "BANK_QUALIFICATION",
            "antiviral_genotype_stratum": "TYK2_WT__IFIH1_WT_OR_A946T",
        }
        stub_sha = compute_canonical_lot_sha256(stub_arch)
        stub_arch["payload_sha256"] = stub_sha
        _check_bad_archive_both_layouts("metadata_only_stub_archive", stub_arch, stub_sha)

        # (ii) Tampered internal payload_sha256 self-digest on complete bank payload
        tampered_self_arch = copy.deepcopy(base_bank_p)
        tampered_self_sha = compute_canonical_lot_sha256(tampered_self_arch)
        tampered_self_arch["payload_sha256"] = hashlib.sha256(b"TAMPERED_SELF_DIGEST").hexdigest()
        _check_bad_archive_both_layouts(
            "tampered_internal_payload_sha256", tampered_self_arch, tampered_self_sha, "ARCHIVED_PAYLOAD_SELF_DIGEST_MISMATCH"
        )

        # (iii) Contradictory nested mcb_id inside composite bank archive
        contra_g0v = build_passing_reference_payload(
            lot_id="BANK-R06B4-001",
            mcb_id="MCB-CONTRADICTORY-999",
            product_variant_id="ISLET1_A4_ARM1B",
            qualification_tier="BANK_QUALIFICATION",
            openislet_root=resolved_root,
        )
        contra_comp = {
            "lot_id": "BANK-R06B4-001",
            "mcb_id": "MCB-ISLET1-A-001",
            "product_variant_id": "ISLET1_A4_ARM1B",
            "legacy_stage0_observations": {
                "current_lot_id": "BANK-R06B4-001",
                "mcb_id": "MCB-ISLET1-A-001",
                "product_variant_id": "ISLET1_A4_ARM1B",
                "obs_icasp9_log10_kill": 4.6,
                "obs_tp53_ppm1d_bcor_vaf": 0.0,
                "obs_mcb_effective_clonogenic_trials": 299573228.0,
                "obs_gate0v_day28_persistent_vp1_ie1_cells_scored": 5990.0,
            },
            "gate0v_wholegraft_payload": contra_g0v,
        }
        contra_comp_sha = compute_canonical_lot_sha256(contra_comp)
        contra_comp["payload_sha256"] = contra_comp_sha
        _check_bad_archive_both_layouts("contradictory_nested_mcb_id", contra_comp, contra_comp_sha)

        # (iii-b) Contradictory nested antiviral_genotype_stratum & tampered nested gate0v payload_sha256 inside composite archive
        contra_geno_comp = copy.deepcopy(contra_comp)
        contra_geno_comp["antiviral_genotype_stratum"] = "TYK2_WT__IFIH1_WT_OR_A946T"
        contra_geno_comp["gate0v_wholegraft_payload"] = build_passing_reference_payload(
            lot_id="BANK-R06B4-001",
            mcb_id="MCB-ISLET1-A-001",
            product_variant_id="ISLET1_A4_ARM1B",
            qualification_tier="BANK_QUALIFICATION",
            antiviral_genotype_stratum="TYK2_WT__IFIH1_PROTECTIVE_LOF",
            openislet_root=resolved_root,
        )
        contra_geno_sha = compute_canonical_lot_sha256(contra_geno_comp)
        contra_geno_comp["payload_sha256"] = contra_geno_sha
        _check_bad_archive_both_layouts(
            "contradictory_nested_genotype_stratum",
            contra_geno_comp,
            contra_geno_sha,
            "HOLD_UNVERIFIED_OR_MISMATCHED_BANK_GENOTYPE_STRATUM",
        )

        tampered_nested_comp = copy.deepcopy(contra_comp)
        tampered_nested_g0v = copy.deepcopy(base_bank_p)
        tampered_nested_g0v["payload_sha256"] = hashlib.sha256(b"TAMPERED_NESTED_G0V_DIGEST").hexdigest()
        tampered_nested_comp["gate0v_wholegraft_payload"] = tampered_nested_g0v
        tampered_nested_sha = compute_canonical_lot_sha256(tampered_nested_comp)
        tampered_nested_comp["payload_sha256"] = tampered_nested_sha
        _check_bad_archive_both_layouts(
            "tampered_nested_gate0v_payload_sha256",
            tampered_nested_comp,
            tampered_nested_sha,
            "ARCHIVED_NESTED_GATE0V_SELF_DIGEST_MISMATCH",
        )

        # (iv) Structurally complete archived bank payload that FAILS BANK_QUALIFICATION (confirmed viral positive k2=1)
        failing_bank_arch = copy.deepcopy(base_bank_p)
        failing_bank_arch["gate0v_b_infectious_challenge"]["pathogens"]["cvb4_e2"]["day28_persistence_by_lineage"]["pericyte"]["stage2_confirmed_infectious_k"] = 1
        failing_bank_arch["gate0v_b_infectious_challenge"]["pathogens"]["cvb4_e2"]["day28_persistence_by_lineage"]["pericyte"]["stage2_sorted_for_confirmation_n"] = 2
        _seal(failing_bank_arch)
        _check_bad_archive_both_layouts(
            "structurally_complete_failing_bank_archive",
            failing_bank_arch,
            failing_bank_arch["payload_sha256"],