OpenIslet

scripts/evaluate_gate0v_composite_release.py

IIP-0043 / DEC-122 (CAND-034 / EXP-031) Executable Dual-Evaluator Composite Release Wrapper

script Release v0.8.0 gen-eb955f8266035aba 357 KB · 28 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/evaluate_gate0v_composite_release.py · SHA-256: 2be0252340222fe4…

        ok_79 = True
        r_79_dir_last: Dict[str, Any] = {}
        rc_79_dir_last = -1
        for st_b3 in (reg_b3, dir_b3):
            r_79_dir_last, rc_79_dir_last = evaluate_composite_lot_file(
                f_bank_req_ocr,
                legacy_evaluator=leg_fn,
                gate0v_evaluator=g0v_fn,
                trusted_qualification_store=st_b3,
                openislet_root=openislet_root,
                nw08_ocr_json_path=f_bank_ocr_rec,
            )
            r_79_arch, rc_79_arch = evaluate_composite_lot_file(
                f_dep_b3,
                legacy_evaluator=leg_fn,
                gate0v_evaluator=g0v_fn,
                trusted_qualification_store=st_b3,
                openislet_root=openislet_root,
            )
            pqa_79 = r_79_arch.get("prior_qualification_authentication") or {}
            if not (
                rc_79_dir_last == 2
                and r_79_dir_last["composite_verdict"] == "HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION"
                and r_79_dir_last["release_authorizing"] is False
                and r_79_dir_last["bank_qualification_authorized"] is False
                and "HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION" in r_79_dir_last["holds"]
                and (r_79_dir_last.get("nw08_measured_ocr_dispatch_result") or {}).get("solver_executed") is False
                and rc_79_arch == 2
                and r_79_arch["release_authorizing"] is False
                and "HOLD_ARCHIVED_BANK_ENVELOPE_MISMATCH" in r_79_arch["holds"]
                and "HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION" in r_79_arch["holds"]
                and pqa_79.get("archived_bank_payload_live_revalidation_passed") is False
                and pqa_79.get("archived_bank_payload_live_g0v_revalidation_passed") is False
                and pqa_79.get("archived_bank_payload_live_legacy_revalidation_passed") is False
                and pqa_79.get("archived_bank_payload_live_composite_revalidation_passed") is False
            ):
                ok_79 = False
        cases.append({
            "case": "r13_b3_bank_require_trusted_nw08_ocr_rejected_direct_and_archived_replay_both_stores",
            "expected_verdict": "HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION",
            "actual_verdict": r_79_dir_last.get("composite_verdict"),
            "operational_tier": r_79_dir_last.get("operational_tier"),
            "legacy_passed": (r_79_dir_last.get("legacy_result_summary") or {}).get("legacy_evaluator_passed"),
            "legacy_tier": (r_79_dir_last.get("legacy_result_summary") or {}).get("lot_release_readiness_tier"),
            "legacy_resolved_pvid": (r_79_dir_last.get("legacy_result_summary") or {}).get("resolved_product_variant_id"),
            "gate0v_passed": (r_79_dir_last.get("gate0v_result_summary") or {}).get("gate0v_evaluator_passed"),
            "gate0v_verdict": (r_79_dir_last.get("gate0v_result_summary") or {}).get("verdict"),
            "expected_token": "HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION",
            "exit_code": rc_79_dir_last,
            "hard_stops": [],
            "holds": (r_79_dir_last.get("holds") or [])[:3],
            "passed": ok_79,
        })

        # 80. R13-B4: Live composite PASS responses across ALL 3 tiers (Bank, Clinical Surrogate
        #     across BOTH store layouts, and Autologous Process Qual) MUST attach explicit
        #     `qualification_scope = "CONDITIONAL_ON_MODELED_ASSUMPTIONS_PENDING_PHYSICAL_QUALIFICATION"`
        #     and `physical_qualification_complete = False` on BOTH Python API and file/CLI intake!
        r_80_clin_reg, rc_80_cr = evaluate_composite_lot_file(
            clin_r2_f,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=reg_r13,
            openislet_root=openislet_root,
        )
        r_80_clin_dir, rc_80_cd = evaluate_composite_lot_file(
            clin_r2_f,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=dir_r13,
            openislet_root=openislet_root,
        )
        pq_80 = v38.build_authenticated_process_qualification_record(
            product_variant_id="ISLET1_D1_AUTO_V2_L1A_CIITA_CD64T_IL1RN",
            process_qual_id="PQ-COMP-R13-80",
        )
        v38.write_record_to_trusted_qualification_store(reg_r13, pq_80, category="process_qualifications")
        g0v_auto_80 = v38.build_passing_reference_payload(
            lot_id="AUTO-COMP-R13-80",
            mcb_id="MCB-AUTO-COMP-R13-80",
            product_variant_id="ISLET1_D1_AUTO_V2_L1A_CIITA_CD64T_IL1RN",
            qualification_tier="AUTOLOGOUS_D1B_PROCESS_QUAL",
            process_qualification_ref_sha256=pq_80["sha256"],
            openislet_root=openislet_root,
        )
        leg_auto_80 = build_legacy_complete_stage0_observations(
            lot_id="AUTO-COMP-R13-80",
            mcb_id="MCB-AUTO-COMP-R13-80",
            product_variant_id="ISLET1_D1_AUTO_V2_L1A_CIITA_CD64T_IL1RN",
        )
        auto_80_bundle = _make_composite_bundle(
            "AUTO-COMP-R13-80", "MCB-AUTO-COMP-R13-80", "ISLET1_D1_AUTO_V2_L1A_CIITA_CD64T_IL1RN", leg_auto_80, g0v_auto_80
        )

        def _promoted_auto_legacy_stub(obs: Dict[str, Any], **_kw: Any) -> Dict[str, Any]:
            return {
                "lot_release_readiness_tier": LEGACY_PASS_TIER,
                "safety_kill_s9_triggered": False,
                "resolved_architecture_assignments": {
                    "product_variant_id": obs.get("product_variant_id"),
                    "product_execution_supported": True,
                    "lot_release_readiness_tier": LEGACY_PASS_TIER,
                },
            }

        r_80_auto = evaluate_composite_clinical_release(
            auto_80_bundle,
            legacy_evaluator=_promoted_auto_legacy_stub,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=reg_r13,
            openislet_root=openislet_root,
        )
        ok_80 = bool(
            bank_res["composite_verdict"] == "PASS_COMPOSITE_BANK_QUALIFICATION"
            and bank_res.get("qualification_scope") == QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL
            and bank_res.get("physical_qualification_complete") is False
            and rc_80_cr == 0
            and r_80_clin_reg["composite_verdict"] == "PASS_COMPOSITE_CLINICAL_RELEASE"
            and r_80_clin_reg["release_authorizing"] is True
            and r_80_clin_reg.get("qualification_scope") == QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL
            and r_80_clin_reg.get("physical_qualification_complete") is False
            and (r_80_clin_reg.get("gate0v_result_summary") or {}).get("qualification_scope") == QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL
            and (r_80_clin_reg.get("gate0v_result_summary") or {}).get("physical_qualification_complete") is False
            and rc_80_cd == 0
            and r_80_clin_dir["composite_verdict"] == "PASS_COMPOSITE_CLINICAL_RELEASE"
            and r_80_clin_dir.get("qualification_scope") == QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL
            and r_80_clin_dir.get("physical_qualification_complete") is False
            and r_80_auto["composite_verdict"] == "PASS_COMPOSITE_AUTOLOGOUS_CLINICAL_RELEASE"
            and r_80_auto["release_authorizing"] is True
            and r_80_auto.get("qualification_scope") == QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL
            and r_80_auto.get("physical_qualification_complete") is False
        )
        cases.append({
            "case": "r13_b4_composite_live_pass_all_tiers_emit_qualification_scope_and_physical_complete_false",
            "expected_verdict": "PASS_COMPOSITE_CLINICAL_RELEASE",
            "actual_verdict": r_80_clin_reg["composite_verdict"],
            "operational_tier": r_80_clin_reg["operational_tier"],
            "legacy_passed": (r_80_clin_reg.get("legacy_result_summary") or {}).get("legacy_evaluator_passed"),
            "legacy_tier": (r_80_clin_reg.get("legacy_result_summary") or {}).get("lot_release_readiness_tier"),
            "legacy_resolved_pvid": (r_80_clin_reg.get("legacy_result_summary") or {}).get("resolved_product_variant_id"),
            "gate0v_passed": (r_80_clin_reg.get("gate0v_result_summary") or {}).get("gate0v_evaluator_passed"),
            "gate0v_verdict": (r_80_clin_reg.get("gate0v_result_summary") or {}).get("verdict"),
            "expected_token": QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL,
            "exit_code": rc_80_cr,
            "hard_stops": [],
            "holds": [],
            "passed": ok_80,
        })

        # 81. R13-M1 & R13-M2: Composite `--lot-json` and coupled `--nw08-ocr-json` reject JSON integer
        #     `-0` AND string `"-0"` with exit 2 HOLD (`INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE`),
        #     AND invalid sampling spec (`units=3, deff=2.0`) / missing partition clear `clustering_design_effect_deff`
        #     to `None` while reporting `submitted_clustering_design_effect_deff_unvalidated`!
        f_lot_ni0 = Path(td) / "r13_m1_lot_neg_zero_int.json"
        f_lot_ni0.write_text('{"qualification_tier": "BANK_QUALIFICATION", "probe": -0}', encoding="utf-8")
        r_81_lot, rc_81_lot = evaluate_composite_lot_file(
            f_lot_ni0, legacy_evaluator=leg_fn, gate0v_evaluator=g0v_fn, openislet_root=openislet_root
        )
        f_ocr_ni0 = Path(td) / "r13_m1_ocr_neg_zero_int.json"
        f_ocr_ni0.write_text(
            json.dumps(ocr_bound_base, sort_keys=True).replace('"uncertainty_se": 0.0', '"uncertainty_se": -0'),
            encoding="utf-8",
        )
        r_81_ocr, rc_81_ocr = evaluate_composite_lot_file(
            clin_r2_f,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=reg_r13,
            openislet_root=openislet_root,
            nw08_ocr_json_path=f_ocr_ni0,
        )
        g0v_81_u3d2 = copy.deepcopy(g0v_bank)
        g0v_81_u3d2["clustering_and_independence_spec"]["independent_biological_units_n"] = 3
        g0v_81_u3d2["clustering_and_independence_spec"]["clustering_design_effect_deff"] = "2.0"
        g0v_81_u3d2["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_81_u3d2)
        f_81_u3d2 = Path(td) / "r13_m2_u3_deff2.json"
        f_81_u3d2.write_text(
            json.dumps(_make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_81_u3d2), sort_keys=True),
            encoding="utf-8",
        )
        r_81_m2, rc_81_m2 = evaluate_composite_lot_file(
            f_81_u3d2, legacy_evaluator=leg_fn, gate0v_evaluator=g0v_fn, openislet_root=openislet_root
        )
        ok_81 = bool(
            rc_81_lot == 2
            and r_81_lot["release_authorizing"] is False
            and "INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE" in r_81_lot["holds"]
            and rc_81_ocr == 2
            and r_81_ocr["release_authorizing"] is False
            and "INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE" in r_81_ocr["holds"]
            and (r_81_ocr.get("nw08_measured_ocr_dispatch_result") or {}).get("solver_executed") is False
            and rc_81_m2 == 2
            and r_81_m2["release_authorizing"] is False
            and (r_81_m2.get("gate0v_result_summary") or {}).get("clustering_design_effect_deff") is None
            and (r_81_m2.get("gate0v_result_summary") or {}).get("submitted_clustering_design_effect_deff_unvalidated") == "2.0"
        )
        cases.append({
            "case": "r13_m1_m2_composite_neg_zero_int_rejected_and_unvalidated_deff_none",
            "expected_verdict": "HOLD_COMPOSITE_RELEASE",
            "actual_verdict": r_81_ocr["composite_verdict"],
            "operational_tier": r_81_ocr["operational_tier"],
            "legacy_passed": (r_81_ocr.get("legacy_result_summary") or {}).get("legacy_evaluator_passed"),
            "legacy_tier": (r_81_ocr.get("legacy_result_summary") or {}).get("lot_release_readiness_tier"),
            "legacy_resolved_pvid": (r_81_ocr.get("legacy_result_summary") or {}).get("resolved_product_variant_id"),
            "gate0v_passed": (r_81_ocr.get("gate0v_result_summary") or {}).get("gate0v_evaluator_passed"),
            "gate0v_verdict": (r_81_ocr.get("gate0v_result_summary") or {}).get("verdict"),
            "expected_token": "INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE",
            "exit_code": rc_81_ocr,
            "hard_stops": [],
            "holds": r_81_ocr["holds"][:3],
            "passed": ok_81,
        })

        # ------------------------------------------------------------------
        # Round-14 Final-Closure Regressions (R14-B1 Mesh-Convergence HOLD,
        # R14-B2 Small-Sample Student-t OCR Inference & Bare-SE HOLD,
        # R14-B3 Cross-Interface Process-Wide Callback Serialization)
        # ------------------------------------------------------------------
        # 82. R14-B1: Coupled composite release routes BOTH observed mesh-resolution reversals
        #     (R1_390_stress @ 1.3164, bed=35 AND R2_DZ40 @ 2.099752752324571, bed=32) to
        #     HOLD_COMPOSITE_RELEASE (exit 2, release_authorizing=False,
        #     HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR) before any coupled authorization!
        clin_r1_390_bundle = _make_composite_bundle(
            clin_lot_id,
            mcb_id,
            pv_lead,
            leg_clin,
            g0v_clin,
            nw08_route_id="R1_390_stress",
            nw08_measurement_evidence_sha256=clin_ev_sha,
            nw08_measurement_not_before_utc="2026-11-28T00:00:00Z",
        )
        clin_r1_390_f = Path(td) / "r14_b1_clin_r1_390.json"
        clin_r1_390_f.write_text(json.dumps(clin_r1_390_bundle, sort_keys=True), encoding="utf-8")
        ocr_r14_r1_rev = v38.build_bound_nw08_ocr_record(
            lot_id=clin_lot_id,
            mcb_id=mcb_id,
            product_variant_id=pv_lead,
            route_id="R1_390_stress",
            lot_payload_sha256=clin_r1_390_bundle["payload_sha256"],
            measured_ocr=1.3164,
            uncertainty_se=0.0,
            measurement_record_id="OCR-R14-B1-R1-REV",
            measurement_evidence_sha256=clin_ev_sha,
            measurement_timestamp_utc="2026-11-29T01:00:00Z",
        )
        ocr_r14_r2_rev = v38.build_bound_nw08_ocr_record(
            lot_id=clin_lot_id,
            mcb_id=mcb_id,
            product_variant_id=pv_lead,