OpenIslet

scripts/verify_iip0041_clinical_h1_cd64t_siglec.py

EXP-028 (CAND-031 / Target IIP-0041 — Bucket 2A) Remediated Verification Suite

script Release v0.8.0 gen-eb955f8266035aba 984 KB · 69 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_iip0041_clinical_h1_cd64t_siglec.py · SHA-256: f004cf6d8259b8b4…

                        elif c_state == "INCUMBENT_INTACT_WITHIN_CAPS" and caller_l2v3_broken is True:
                            h2h_mismatches.append(
                                "Caller l2v3_broken_by_t1d_sera_gt_5pct=True contradicts trusted paired comparator state INCUMBENT_INTACT_WITHIN_CAPS."
                            )
                        derived_incumbent_state = c_state
                        derived_incumbent_details = c_inc_details
                        authenticated_upstream_digests["paired_comparator_record"] = crecomp
                        if c_issuer is not None:
                            trusted_store_issuers["paired_comparator_record"] = c_issuer
                        paired_comparator_summary = {
                            "paired_assay_run_id": c_run_id,
                            "panel_digest": crec.get("panel_digest"),
                            "incumbent_comparator_construct_id": crec.get("incumbent_comparator_construct_id"),
                            "incumbent_comparator_lot_id": crec.get("incumbent_comparator_lot_id"),
                            "incumbent_comparator_mcb_id": crec.get("incumbent_comparator_mcb_id"),
                            "incumbent_adjudication_state": c_state,
                            "derived_incumbent_broken": c_state == "INCUMBENT_CONCLUSIVELY_BROKEN",
                            "straddling_cap_endpoints": list(c_inc_details.get("straddling_cap_endpoints", [])),
                            "conclusively_broken_endpoints": list(c_inc_details.get("conclusively_broken_endpoints", [])),
                            "verdict": expected_c_verdict,
                            "head_to_head_candidate_and_panel_reconciled": len(h2h_mismatches) == 0,
                        }
                    if isinstance(inline_comp, dict) and compute_upstream_record_sha256(inline_comp) != crecomp:
                        h2h_mismatches.append("Inline paired_comparator_record contradicts trusted qualification store record.")
                    if h2h_mismatches:
                        reasons.extend(h2h_mismatches)
                    else:
                        head_to_head_reconciled = True

    bound_identity = {
        "product_track": product_track,
        "chassis_id": chassis_id,
        "construct_id": construct_id,
        "product_variant_id": product_variant_id,
        "lot_id": lot_id,
        "mcb_id": mcb_id,
        "incumbent_comparator_construct_id": inc_comp_id,
        "incumbent_comparator_lot_id": inc_comp_lot_id,
        "paired_assay_run_id": payload_run_id,
        "panel_digest": payload_panel_digest,
        "head_to_head_reconciled": head_to_head_reconciled,
        "derived_day90_mfi_retention_pct": derived_mfi_retentions,
        "trusted_store_resolution_source": trusted_store_source,
        "self_attested_inline_records_rejected": self_attested_inline_ignored,
        "authenticated_upstream_record_sha256": authenticated_upstream_digests,
        "authenticated_issuer_authorities": trusted_store_issuers,
        "paired_comparator_summary": paired_comparator_summary,
    }

    if reasons:
        return {
            "status": "FAIL_OR_PENDING",
            "disposition": "DO_NOT_PROMOTE_LOCUS_2",
            "full_promotion_authorized": False,
            "lead_promotion_authorized": False,
            "arbitration_closed": False,
            "incumbent_retained": False,
            "incumbent_adjudication_state": derived_incumbent_state,
            "policy_pin_verified": True,
            "expected_pinned_side_contract_sha256": PINNED_SIDE_CONTRACT_SHA256,
            "pending_full_qualification_fields": pending_full_fields,
            "reasons": reasons,
            "bound_identity": bound_identity,
            "side_contract_sha256": side_contract_sha,
        }
    if hold_pathways:
        return {
            "status": "HOLD_UNDERPOWERED_EXPAND_N",
            "disposition": "INCONCLUSIVE_C4B2A_BAND_EXPAND_REPLICATES",
            "full_promotion_authorized": False,
            "lead_promotion_authorized": False,
            "arbitration_closed": False,
            "incumbent_retained": False,
            "incumbent_adjudication_state": derived_incumbent_state,
            "policy_pin_verified": True,
            "expected_pinned_side_contract_sha256": PINNED_SIDE_CONTRACT_SHA256,
            "pending_full_qualification_fields": pending_full_fields,
            "reasons": [f"Inconclusive C4b2a HOLD band on {', '.join(hold_pathways)}; expand independent T1D sera/donor n."],
            "bound_identity": bound_identity,
            "side_contract_sha256": side_contract_sha,
        }
    if pending_full_fields or derived_incumbent_state is None:
        hint_broken = (
            (derived_incumbent_state == "INCUMBENT_CONCLUSIVELY_BROKEN")
            if derived_incumbent_state is not None
            else caller_l2v3_broken
        )
        winner_disp = (
            "COMPONENT_ARBITRATION_WINNER_ABX_CD64T_IL1RN_PENDING_FULL_GY025_AND_TRUSTED_STORE"
            if hint_broken is True
            else "COMPONENT_ARBITRATION_RETAIN_L2V3_PENDING_FULL_GY025_AND_TRUSTED_STORE"
        )
        return {
            "status": "COMPONENT_PASS_CIITA_ARBITRATION_ONLY_PENDING_FULL_GY025",
            "disposition": winner_disp,
            "full_promotion_authorized": False,
            "lead_promotion_authorized": False,
            "arbitration_closed": False,
            "incumbent_retained": False,
            "incumbent_adjudication_state": derived_incumbent_state,
            "policy_pin_verified": True,
            "expected_pinned_side_contract_sha256": PINNED_SIDE_CONTRACT_SHA256,
            "pending_full_qualification_fields": pending_full_fields,
            "reasons": [
                "CIITA Locus-2 humoral/signaling/IL-1Ra component passed, but full GY-025 physical endpoints and/or "
                "independent trusted_qualification_store records (Gate 0V, Rule S11, GY-025 Tier 6B, and head-to-head paired "
                f"incumbent comparator) remain pending: {', '.join(pending_full_fields)}."
            ],
            "bound_identity": bound_identity,
            "side_contract_sha256": side_contract_sha,
        }
    if derived_incumbent_state == "INCUMBENT_UNRESOLVED_STRADDLING_CAP":
        strad_list = derived_incumbent_details.get("straddling_cap_endpoints", [])
        return {
            "status": "HOLD_INCUMBENT_COMPARATOR_UNRESOLVED",
            "disposition": "INCONCLUSIVE_INCUMBENT_COMPARATOR_STRADDLES_CAP_EXPAND_REPLICATES",
            "full_promotion_authorized": False,
            "lead_promotion_authorized": False,
            "arbitration_closed": False,
            "incumbent_retained": False,
            "incumbent_adjudication_state": "INCUMBENT_UNRESOLVED_STRADDLING_CAP",
            "policy_pin_verified": True,
            "expected_pinned_side_contract_sha256": PINNED_SIDE_CONTRACT_SHA256,
            "pending_full_qualification_fields": ["incumbent_comparator_conclusive_resolution"],
            "reasons": [
                "Incumbent L2_V3 comparator is unresolved (no endpoint has L95 > cap, but >= 1 endpoint straddles cap: "
                f"{', '.join(strad_list)}); incumbent uncertainty NEVER authorizes lead promotion — expand matched replicates."
            ],
            "bound_identity": bound_identity,
            "side_contract_sha256": side_contract_sha,
        }
    if derived_incumbent_state == "INCUMBENT_CONCLUSIVELY_BROKEN":
        return {
            "status": "PASS_FULL_GY025_AND_GATE28B_PROMOTE",
            "disposition": "WINNER_TAKES_ALLELE_ABX_L2_V2_CD64T_IL1RN_ARCHIVE_LOSER_FAMILY",
            "full_promotion_authorized": True,
            "lead_promotion_authorized": True,
            "arbitration_closed": True,
            "incumbent_retained": False,
            "incumbent_adjudication_state": "INCUMBENT_CONCLUSIVELY_BROKEN",
            "policy_pin_verified": True,
            "expected_pinned_side_contract_sha256": PINNED_SIDE_CONTRACT_SHA256,
            "pending_full_qualification_fields": [],
            "reasons": [],
            "bound_identity": bound_identity,
            "side_contract_sha256": side_contract_sha,
        }
    return {
        "status": "PASS_FULL_GY025_AND_GATE28B_RETAIN_L2V3",
        "disposition": "WINNER_TAKES_ALLELE_RETAIN_IIP0031_L2V3_ARCHIVE_LOSER_FAMILY",
        "full_promotion_authorized": False,
        "lead_promotion_authorized": False,
        "arbitration_closed": True,
        "incumbent_retained": True,
        "incumbent_adjudication_state": "INCUMBENT_INTACT_WITHIN_CAPS",
        "policy_pin_verified": True,
        "expected_pinned_side_contract_sha256": PINNED_SIDE_CONTRACT_SHA256,
        "pending_full_qualification_fields": [],
        "reasons": [],
        "bound_identity": bound_identity,
        "side_contract_sha256": side_contract_sha,
    }


def build_valid_gate28b_reference_bundle(
    store_path: pathlib.Path | str | None = None,
    *,
    lot_id: str = "LOT-ABX-2026-001",
    mcb_id: str = "MCB-ISLET1A-001",
    chassis_id: str = "ISLET1_A",
    incumbent_comparator_construct_id: str = "L2_V3_CO_PRIMARY_CD200",
    incumbent_comparator_lot_id: str = "LOT-L2V3-2026-001",
    incumbent_comparator_mcb_id: str = "MCB-L2V3-001",
    l2v3_broken: bool = True,
    incumbent_state: str | None = None,
    incumbent_evidence_override: dict[str, Any] | None = None,
    candidate_arm_override: dict[str, Any] | None = None,
    paired_assay_run_id: str = "PAIRED-HUMORAL-2026-001",
    t1d_sera_panel_ids: list[str] | None = None,
    nk_donor_panel_ids: list[str] | None = None,
    differentiation_batch_ids: list[str] | None = None,
) -> tuple[dict[str, Any], dict[str, dict[str, Any]]]:
    """
    Build a complete, contract-valid Gate 28-B payload + independent trusted-store records
    (binding BOTH candidate & incumbent head-to-head arms and matched assay panel IDs, with
    3-state incumbent adjudication: INCUMBENT_CONCLUSIVELY_BROKEN / INCUMBENT_UNRESOLVED_STRADDLING_CAP /
    INCUMBENT_INTACT_WITHIN_CAPS).
    """
    construct_id = "ABX_L2_v2_CD64T_IL1RN"
    product_track = "CORE_ABX"
    sera_ids = list(t1d_sera_panel_ids) if t1d_sera_panel_ids is not None else [f"SERA-T1D-{i:02d}" for i in range(1, 7)]
    nk_ids = list(nk_donor_panel_ids) if nk_donor_panel_ids is not None else [f"NK-DONOR-{i:02d}" for i in range(1, 4)]
    diff_ids = list(differentiation_batch_ids) if differentiation_batch_ids is not None else [f"DIFF-S7-{i:02d}" for i in range(1, 4)]

    eff_state = (
        incumbent_state
        if incumbent_state is not None
        else ("INCUMBENT_CONCLUSIVELY_BROKEN" if l2v3_broken else "INCUMBENT_INTACT_WITHIN_CAPS")
    )
    if eff_state not in INCUMBENT_ADJUDICATION_STATES:
        raise ValueError(f"Invalid incumbent_state={eff_state!r}; expected one of {sorted(INCUMBENT_ADJUDICATION_STATES)}")

    g0v_rec = build_authenticated_upstream_record(
        gate_id="GATE_0V_WHOLEGRAFT",
        verdict="PASS_WHOLEGRAFT_GATE0V_AND_STRESS_AP1903",
        lot_id=lot_id,
        mcb_id=mcb_id,
        construct_id=construct_id,
        chassis_id=chassis_id,
        product_track=product_track,
        assay_id="GATE0V-WHOLEGRAFT-2026-001",
        evidence_summary={"beta_alpha_delta_iec_pericyte_persistent_vp1_ie1_events": 0, "stressed_ap1903_log10_kill": 4.7},
    )
    s11_rec = build_authenticated_upstream_record(
        gate_id="RULE_S11_MOLECULAR_BATTERY",
        verdict="PASS_RULE_S11_MOLECULAR_BATTERY",
        lot_id=lot_id,
        mcb_id=mcb_id,
        construct_id=construct_id,
        chassis_id=chassis_id,
        product_track=product_track,
        assay_id="RULES11-BATTERY-2026-001",
        evidence_summary={"tp53_ppm1d_bcor_vaf": 0.0, "castseq_translocations": 0, "race_umi_count": 4200},
    )
    t6b_rec = build_authenticated_upstream_record(
        gate_id="GY025_TIER6B_MASTER_LOT_OUTGROWTH",
        verdict="PASS_GY025_TIER6B_MASTER_LOT_OUTGROWTH",
        lot_id=lot_id,
        mcb_id=mcb_id,
        construct_id=construct_id,
        chassis_id=chassis_id,
        product_track=product_track,
        assay_id="GY025-TIER6B-2026-001",
        evidence_summary={"clonogenic_survivors_k": 0, "effective_clonogenic_trials": 300000000},
    )

    if eff_state == "INCUMBENT_CONCLUSIVELY_BROKEN":
        comp_evidence: dict[str, Any] = {
            "incumbent_intact_serum_cd16_adcc_l95_pct": 9.2,
            "incumbent_intact_serum_cd16_adcc_u95_pct": 14.8,
            "incumbent_igg_attributable_cd16_adcc_l95_pct": 7.8,
            "incumbent_igg_attributable_cd16_adcc_u95_pct": 12.6,
            "incumbent_ap_c5b9_l95_pct": 1.9,
            "incumbent_ap_c5b9_u95_pct": 4.1,
            "incumbent_overall_20pct_nhs_l95_pct": 5.4,
            "incumbent_overall_20pct_nhs_u95_pct": 7.9,
            "incumbent_classical_c4b2a_l95_pct": 10.6,
            "incumbent_classical_c4b2a_u95_pct": 15.2,
            "incumbent_lectin_c4b2a_l95_pct": 3.2,
            "incumbent_lectin_c4b2a_u95_pct": 7.4,