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…

        on already-decoded Python inputs: for strict JSON-ingested payloads decoded via IEEE-754 binary64 (float64) in
        load_strict_json_text / load_strict_json_bytes, exactness starts at JSON-decoded float64 precision (not raw
        decimal text beyond 53-bit significand), whereas direct Python Decimal or int inputs retain exact decimal/integer
        precision. Day-90 MFI retention is verified via exact cross-product Fraction(day90_mfi) * 100 >= Fraction(t0_mfi) * 75
        with display rounding isolated in localcontext(prec=50), reconciling caller-supplied day90_mfi_retention_pct_vs_t0 within <= 0.5 pp.
      - Independent Trusted Qualification Store, Head-to-Head Binding, & 3-State Incumbent Adjudication: Full authorization
        NEVER accepts bare summary booleans, self-attested inline upstream records, or a bare caller boolean. All four
        records (GATE_0V_WHOLEGRAFT, RULE_S11_MOLECULAR_BATTERY, GY025_TIER6B_MASTER_LOT_OUTGROWTH, and
        PAIRED_L2V3_INCUMBENT_COMPARATOR) resolve strictly from trusted_qualification_store (operational deployment
        dependencies: independent QA operator control, verified external store provenance, write-restricted access policy,
        and separation of duties). PAIRED_L2V3_INCUMBENT_COMPARATOR binds BOTH candidate and incumbent arms plus matched
        assay panel (paired_assay_run_id, t1d_sera_panel_ids, nk_donor_panel_ids, differentiation_batch_ids, panel_digest)
        and enforces symmetric 3-state incumbent adjudication (INCUMBENT_CONCLUSIVELY_BROKEN via L95 > cap;
        INCUMBENT_UNRESOLVED_STRADDLING_CAP -> HOLD_INCUMBENT_COMPARATOR_UNRESOLVED; INCUMBENT_INTACT_WITHIN_CAPS -> RETAIN).
      - Distinct Retain-Incumbent vs Lead-Promotion Semantics: PASS_FULL_GY025_AND_GATE28B_RETAIN_L2V3 sets
        full_promotion_authorized=False and lead_promotion_authorized=False (while arbitration_closed=True and
        incumbent_retained=True); ONLY PASS_FULL_GY025_AND_GATE28B_PROMOTE authorizes lead promotion.
    """
    if not isinstance(payload, dict):
        return {
            "status": "FAIL_INVALID_PAYLOAD",
            "disposition": "DO_NOT_PROMOTE_LOCUS_2",
            "full_promotion_authorized": False,
            "lead_promotion_authorized": False,
            "arbitration_closed": False,
            "incumbent_retained": False,
            "policy_pin_verified": False,
            "pending_full_qualification_fields": [],
            "reasons": ["Gate 28-B payload must be a JSON object/dict."],
        }

    try:
        side_contract, side_contract_sha, policy_pin_verified = _load_iip0041_side_contract(
            side_contract_path,
            require_pinned_sha=False,
        )
        gate_cfg = side_contract["executable_stage0_gates"]["Gate_28_B"]
    except Exception as exc:
        return {
            "status": "FAIL_HARD_STOP",
            "disposition": "BLOCKED_MISSING_OR_INVALID_SIDE_CONTRACT",
            "full_promotion_authorized": False,
            "lead_promotion_authorized": False,
            "arbitration_closed": False,
            "incumbent_retained": False,
            "policy_pin_verified": False,
            "expected_pinned_side_contract_sha256": PINNED_SIDE_CONTRACT_SHA256,
            "pending_full_qualification_fields": [],
            "reasons": [f"Cannot load or validate immutable Gate 28-B side contract: {exc}"],
        }

    if not policy_pin_verified:
        return {
            "status": "NON_AUTHORIZING_UNPINNED_POLICY_DIAGNOSTIC",
            "disposition": "UNPINNED_OR_MODIFIED_SIDE_CONTRACT_NO_PROMOTION_AUTHORITY",
            "full_promotion_authorized": False,
            "lead_promotion_authorized": False,
            "arbitration_closed": False,
            "incumbent_retained": False,
            "policy_pin_verified": False,
            "expected_pinned_side_contract_sha256": PINNED_SIDE_CONTRACT_SHA256,
            "side_contract_sha256": side_contract_sha,
            "pending_full_qualification_fields": ["pinned_side_contract_sha256_verification"],
            "reasons": [
                f"Alternate or modified side contract rejected for authorization: "
                f"actual_sha256={side_contract_sha} != pinned_sha256={PINNED_SIDE_CONTRACT_SHA256}. "
                "Runtime promotion authority requires the exact runtime-pinned side contract."
            ],
        }

    reasons: list[str] = []
    pending_full_fields: list[str] = []

    def _strict_bool(val: Any) -> bool | None:
        return val if type(val) is bool else None

    def _strict_int(val: Any, *, min_val: int, max_val: int | None = None) -> int | None:
        if type(val) is not int:
            return None
        if val < min_val:
            return None
        if max_val is not None and val > max_val:
            return None
        return val

    allowed_issuers = set(gate_cfg["allowed_issuer_authorities"])
    eligible_tracks = set(gate_cfg["eligible_product_tracks"])
    blocked_tracks = set(gate_cfg["blocked_product_tracks"])
    eligible_chassis = set(gate_cfg["eligible_chassis"])
    promotable_leads = set(gate_cfg["promotion_eligible_construct_ids"])
    control_ids = set(gate_cfg["non_promotable_control_construct_ids"])
    cd46_hold_ids = set(gate_cfg["blocked_cd46_hold_construct_ids"])
    cfh_hold_ids = set(gate_cfg["blocked_tertiary_cfh_cd55_hold_construct_ids"])
    comparators_by_chassis: dict[str, list[str]] = gate_cfg["eligible_incumbent_comparators_by_chassis"]

    def _early_stop(status: str, disposition: str, msg_list: list[str], pending: list[str] | None = None) -> dict[str, Any]:
        return {
            "status": status,
            "disposition": disposition,
            "full_promotion_authorized": False,
            "lead_promotion_authorized": False,
            "arbitration_closed": False,
            "incumbent_retained": False,
            "policy_pin_verified": True,
            "expected_pinned_side_contract_sha256": PINNED_SIDE_CONTRACT_SHA256,
            "pending_full_qualification_fields": list(pending or []),
            "reasons": msg_list,
            "side_contract_sha256": side_contract_sha,
        }

    # 1. Positive strictly literal product_track binding (zero silent stripping!)
    product_track = _strict_literal_id(payload.get("product_track"))
    if product_track in blocked_tracks:
        return _early_stop(
            "FAIL_HARD_STOP",
            "INCOMPATIBLE_AT_LOCUS_2_PER_GY025",
            ["Track-2 B'-SCT is permanently incompatible at CIITA Locus 2 per GY-025."],
        )
    if product_track not in eligible_tracks:
        return _early_stop(
            "FAIL_HARD_STOP",
            "BLOCKED_INELIGIBLE_PRODUCT_TRACK_FOR_GATE28B",
            [
                f"product_track {payload.get('product_track')!r} is ineligible or contains illegal whitespace for Gate 28-B "
                f"(allowed exact literal side-contract tracks: {sorted(eligible_tracks)}; autologous D1b is governed exclusively by IIP-0035/DEC-114)."
            ],
        )

    # 2. Positive strictly literal construct_id binding against pinned side-contract allowlist
    construct_id = _strict_literal_id(payload.get("construct_id"))
    if construct_id is None:
        return _early_stop(
            "FAIL_HARD_STOP",
            "BLOCKED_UNREGISTERED_OR_INELIGIBLE_CONSTRUCT_ID",
            [
                f"Missing, non-string, or whitespace-padded construct_id={payload.get('construct_id')!r}; "
                "Gate 28-B requires exact literal side-contract lead construct binding (no silent stripping)."
            ],
        )
    cid_upper = construct_id.upper()
    if construct_id in cd46_hold_ids or "CD46" in cid_upper:
        addendum_raw = payload.get("cand034_cd46_tropic_addendum_cleared", False)
        addendum_bool = _strict_bool(addendum_raw)
        cd46_reasons = [
            f"{construct_id!r} is archived as an immutable HOLD-comparator outside Wave-5 Go scope "
            "(manufacture_authorized=false; requires IIP-0043/DEC-122 executable cd46_tropic_addendum and separate contract amendment; "
            "core Gate 0V-B covering CVB/HCMV is non-citable for CD46_WT)."
        ]
        if addendum_bool is None:
            cd46_reasons.append(f"Non-boolean cand034_cd46_tropic_addendum_cleared={addendum_raw!r} rejected fail-closed.")
        return _early_stop(
            "HOLD_BLOCKED",
            "BLOCKED_ARCHIVED_HOLD_COMPARATOR_CD46WT_PENDING_IIP0043_ADDENDUM",
            cd46_reasons,
            pending=["iip0043_cd46_tropic_addendum_and_contract_amendment"],
        )
    if construct_id in cfh_hold_ids or "CFH_CD55" in cid_upper:
        return _early_stop(
            "HOLD_BLOCKED",
            "BLOCKED_TERTIARY_HOLD_COMPARATOR_CFH_CD55_PIGK1",
            [
                f"{construct_id!r} is a tertiary HOLD comparator (PIGK=1, 26/12 absent Swiss-Prot windows, manufacture_authorized=false) "
                "and is ineligible for Gate 28-B promotion pending IIP-0043 cd55_full_length_addendum, matched CTRL_CFH_CD55_ONLY control, and PIGK qualification."
            ],
            pending=["iip0043_cd55_full_length_addendum_and_pigk_qualification"],
        )
    if construct_id in control_ids:
        return _early_stop(
            "CONTROL_ATTRIBUTION_ONLY_NON_PROMOTABLE",
            "NON_PROMOTABLE_SINGLE_CARGO_ATTRIBUTION_CONTROL",
            [
                f"{construct_id!r} is a single-cargo attribution control (promotion_eligible=false in immutable side contract) "
                "and can NEVER receive lead therapeutic promotion."
            ],
        )
    if "CR1" in cid_upper:
        return _early_stop(
            "FAIL_HARD_STOP",
            "BLOCKED_BY_GY026_SHORT_STALK_CR1",
            [f"{construct_id!r} is permanently blocked by GY-026 (short-stalk CR1)."],
        )
    if construct_id not in promotable_leads:
        return _early_stop(
            "FAIL_HARD_STOP",
            "BLOCKED_UNREGISTERED_OR_INELIGIBLE_CONSTRUCT_ID",
            [
                f"construct_id {construct_id!r} is not in Gate 28-B promotion-eligible lead allowlist {sorted(promotable_leads)}."
            ],
        )

    # 3. Required strictly literal chassis, lot, MCB, product_variant_id, and incumbent comparator identity binding
    chassis_id = _strict_literal_id(payload.get("chassis_id"))
    if chassis_id not in eligible_chassis:
        reasons.append(f"Invalid, whitespace-padded, or missing chassis_id {payload.get('chassis_id')!r}; allowed Core A/B/X chassis: {sorted(eligible_chassis)}.")
    lot_id = _strict_literal_id(payload.get("lot_id"))
    if lot_id is None:
        reasons.append(f"Missing or whitespace-padded mandatory literal lot_id={payload.get('lot_id')!r} for same-lot qualification binding.")
    mcb_id = _strict_literal_id(payload.get("mcb_id"))
    if mcb_id is None:
        reasons.append(f"Missing or whitespace-padded mandatory literal mcb_id={payload.get('mcb_id')!r} for master cell bank binding.")
    pvid_raw = payload.get("product_variant_id")
    if pvid_raw is None:
        product_variant_id = construct_id
    else:
        product_variant_id = _strict_literal_id(pvid_raw)
        if product_variant_id != construct_id:
            reasons.append(f"product_variant_id={pvid_raw!r} must literally match lead construct_id={construct_id!r}.")
    inc_comp_id = _strict_literal_id(payload.get("incumbent_comparator_construct_id"))
    inc_comp_lot_id = _strict_literal_id(payload.get("incumbent_comparator_lot_id"))
    if chassis_id in comparators_by_chassis:
        allowed_comps = set(comparators_by_chassis[chassis_id])
        if inc_comp_id not in allowed_comps:
            reasons.append(
                f"incumbent_comparator_construct_id {payload.get('incumbent_comparator_construct_id')!r} is not an allowlisted "
                f"literal IIP-0031 L2_V3 comparator for chassis {chassis_id!r} (allowed: {sorted(allowed_comps)})."
            )
    elif inc_comp_id is None:
        reasons.append("Missing or whitespace-padded mandatory incumbent_comparator_construct_id.")
    if inc_comp_lot_id is None:
        reasons.append("Missing or whitespace-padded mandatory literal incumbent_comparator_lot_id for paired comparator binding.")

    # 4. Strict literal zygosity & explicit exact-integer counts (ZERO defaults, NO floats, NO bools!)
    zygosity = _strict_literal_id(payload.get("zygosity"))
    allowed_zyg = set(gate_cfg["allowed_zygosities"])
    if zygosity not in allowed_zyg:
        reasons.append(
            f"Zygosity {payload.get('zygosity')!r} not in allowed exact literal set {sorted(allowed_zyg)} "
            "(heterotypic half-dosage requires separate full qualification)."
        )

    clone_cap = int(gate_cfg["clone_screening_cap_per_design"])
    clones_n = _strict_int(payload.get("clones_screened_n"), min_val=1, max_val=clone_cap)
    if clones_n is None:
        reasons.append(
            f"Invalid or omitted clones_screened_n={payload.get('clones_screened_n')!r}: require explicit exact int in [1, {clone_cap}]."
        )

    fam_cap = int(gate_cfg["gmp_aav6_locus2_donor_family_cap"])
    donor_fam_n = _strict_int(payload.get("gmp_aav6_locus2_donor_families_n"), min_val=1, max_val=fam_cap)
    if donor_fam_n is None:
        reasons.append(
            f"Invalid or omitted gmp_aav6_locus2_donor_families_n={payload.get('gmp_aav6_locus2_donor_families_n')!r}: "
            f"require explicit exact int == {fam_cap} (winner-takes-allele cap)."
        )

    min_sera = int(gate_cfg["independent_t1d_sera_min"])
    min_nk = int(gate_cfg["independent_nk_donors_min"])
    min_diff = int(gate_cfg["independent_differentiations_min"])
    sera_n = _strict_int(payload.get("independent_t1d_sera_n"), min_val=min_sera)
    nk_n = _strict_int(payload.get("independent_nk_donors_n"), min_val=min_nk)