scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py · SHA-256: 33439d619c00fcc3…
failures.append("FAIL_ENSC_CURRENT_ASSAY_GSIS_AGGREGATE_CONTRADICTS_PULSES")
if all(_is_num(arch_cur.get(lk)) for lk in ("stage7_ins_nkx61_beta_pct", "stage7_monohormonal_gcg_cpep_neg_alpha_pct", "stage7_sst_delta_pct", "stage7_tph1_sc_ec_pct")):
ac_lin_sum = (
float(arch_cur["stage7_ins_nkx61_beta_pct"])
+ float(arch_cur["stage7_monohormonal_gcg_cpep_neg_alpha_pct"])
+ float(arch_cur["stage7_sst_delta_pct"])
+ float(arch_cur["stage7_tph1_sc_ec_pct"])
)
lineage_sum_pct = ac_lin_sum
if ac_lin_sum > 100.0 + 1e-9:
failures.append("FAIL_ENSC_CURRENT_ASSAY_LINEAGE_SUM_GT_100PCT")
# Archived terminal_alk5i_class_exposed (required!) & terminal_reagents (required!)
ac_alk = arch_cur.get("terminal_alk5i_class_exposed")
if ac_alk is None:
holds.append("HOLD_ENSC_CURRENT_ASSAY_MISSING_TERMINAL_ALK5I_CLASS_EXPOSED")
elif not _is_strict_bool(ac_alk) or ac_alk is not False:
failures.append("FAIL_ENSC_CURRENT_ASSAY_TERMINAL_ALK5I_EXPOSED")
for alk_k in ("terminal_alk5i_exposed", "alk5i_exposed"):
if alk_k in arch_cur and arch_cur[alk_k] is not False:
failures.append("FAIL_ENSC_CURRENT_ASSAY_TERMINAL_ALK5I_EXPOSED")
has_tr = "terminal_reagents" in arch_cur and arch_cur["terminal_reagents"] is not None
has_tm = "terminal_maturation_small_molecules" in arch_cur and arch_cur["terminal_maturation_small_molecules"] is not None
tr_has_explicit_none = (
("terminal_reagents" in arch_cur and arch_cur["terminal_reagents"] is None)
or ("terminal_maturation_small_molecules" in arch_cur and arch_cur["terminal_maturation_small_molecules"] is None)
)
if not has_tr and not has_tm:
holds.append("HOLD_ENSC_CURRENT_ASSAY_MISSING_TERMINAL_REAGENTS")
else:
if tr_has_explicit_none:
holds.append("HOLD_ENSC_CURRENT_ASSAY_MISSING_TERMINAL_REAGENTS")
if has_tr and has_tm:
canon_tr = _audit_terminal_reagent_list(
arch_cur["terminal_reagents"],
label_prefix="CURRENT_ASSAY_",
declared_alk5_flag=arch_cur.get("terminal_alk5i_class_exposed", False),
)
canon_tm = _audit_terminal_reagent_list(
arch_cur["terminal_maturation_small_molecules"],
label_prefix="CURRENT_ASSAY_",
declared_alk5_flag=arch_cur.get("terminal_alk5i_class_exposed", False),
)
if canon_tr is None or canon_tm is None or canon_tr != canon_tm:
failures.append("FAIL_ENSC_CURRENT_ASSAY_TERMINAL_REAGENTS_ALIAS_CONFLICT")
ac_canon_reagents = canon_tr
else:
ac_tr = arch_cur["terminal_reagents"] if has_tr else arch_cur["terminal_maturation_small_molecules"]
ac_canon_reagents = _audit_terminal_reagent_list(
ac_tr,
label_prefix="CURRENT_ASSAY_",
declared_alk5_flag=arch_cur.get("terminal_alk5i_class_exposed", False),
)
if ac_canon_reagents is not None and parent_canon_reagents is not None and ac_canon_reagents != parent_canon_reagents:
failures.append("FAIL_ENSC_CURRENT_ASSAY_TERMINAL_REAGENTS_MISMATCH")
# Apply strict canonical ASCII identity validation to ALL caller, FMR & archived EnSC identifier fields (Audit R8-07)
_audit_canonical_identifier_fields(payload, label="ENSC_PAYLOAD", failures=failures)
if isinstance(fmr, dict):
_audit_canonical_identifier_fields(fmr, label="ENSC_FMR", failures=failures)
if arch_cur is not None:
_audit_canonical_identifier_fields(arch_cur, label="ENSC_ARCHIVE", failures=failures)
# Strict Round-11 consistency invariant (Audit R10-06): NEVER pair FAIL with any *_HOLD_ONLY u95_derivation_source!
if failures and u95_derivation_source == "UNVERIFIED_AGGREGATE_HOLD_ONLY":
u95_pct = None
ensc_distinct_animals = None
ensc_derived_events = None
provisional_agg_u95_pct = None
u95_derivation_source = "WITHHELD_INCOMPLETE_ARCHIVE_WITH_INDEPENDENT_FAIL"
if caller_roster_reconciliation_status in ("UNVERIFIED_ARCHIVE_INCOMPLETE", "NO_AUTHENTICATED_ARCHIVE"):
caller_roster_reconciliation_status = (
"CONFLICT_CALLER_MISMATCH_WITH_INCOMPLETE_ARCHIVE"
if (arch_cur is not None and caller_vs_arch_conflict)
else "UNVERIFIED_ARCHIVE_INCOMPLETE_WITH_INDEPENDENT_FAIL"
)
extra = {
"teratoma_onesided_95pct_u95_pct": _safe_round_finite(u95_pct, 4),
"u95_derivation_source": u95_derivation_source,
"caller_roster_reconciliation_status": caller_roster_reconciliation_status,
"caller_reported_unverified_u95_pct": _safe_round_finite(caller_reported_unverified_u95_pct, 4),
"provisional_unverified_aggregate_u95_pct": _safe_round_finite(provisional_agg_u95_pct, 4),
"verified_distinct_canonical_animals": ensc_distinct_animals,
"derived_teratoma_events": ensc_derived_events,
"unverified_archive_dedup_distinct_animals": unverified_archive_dedup_animals,
"unverified_archive_observed_teratoma_events": unverified_archive_observed_events,
"terminal_reagent_classes": reagent_classes,
"terminal_reagent_registry_version": ENSC_TERMINAL_REAGENT_REGISTRY_V2["registry_version"],
"mutually_exclusive_lineage_sum_pct": _safe_round_finite(lineage_sum_pct, 4),
}
# Separate bank-only vs clinical lot-release authority on AUTHENTICATED_ARCHIVED_WETLAB (Review #4 / Audit R4-07)
if not failures and not holds and valid_tier == "AUTHENTICATED_ARCHIVED_WETLAB":
if g0v_clinical_ok and g34_clinical_ok and g5_clinical_ok and gqc_clinical_ok and cur_clinical_ok:
return _finalize_gate_verdict(
"Gate 37-EnSC-P19-SinglePass",
failures,
holds,
"PASS",
"ALL_ENSC_SINGLEPASS_P20_55PD_GY024_GY030_GATE34_GATE5_OQ012_GY006_CURRENT_ASSAY_AND_CLINICAL_RELEASE_CRITERIA_MET",
evidence_tier=valid_tier,
pass_authority_scope="CLINICAL_LOT_RELEASE",
bank_qualified_on_wetlab_pass=True,
authorize_promotion_on_wetlab_pass=True,
extra=extra,
)
if g0v_bank_ok and g34_bank_ok and g5_bank_ok and gqc_bank_ok and cur_bank_ok:
return _finalize_gate_verdict(
"Gate 37-EnSC-P19-SinglePass",
failures,
holds,
"STAGE_LIMITED_BANK_QUALIFIED",
"BANK_QUALIFICATION_ONLY_SCOPE_CLINICAL_LOT_RELEASE_WITHHELD",
evidence_tier=valid_tier,
pass_authority_scope="BANK_QUALIFICATION_ONLY",
bank_qualified_on_wetlab_pass=True,
authorize_promotion_on_wetlab_pass=False,
extra=extra,
)
failures.append("FAIL_INSUFFICIENT_UPSTREAM_AUTHORITY_SCOPE")
return _finalize_gate_verdict(
"Gate 37-EnSC-P19-SinglePass",
failures,
holds,
"PASS",
"ALL_ENSC_SINGLEPASS_P20_55PD_GY024_GY030_GATE34_GATE5_OQ012_GY006_AND_FUNCTIONAL_CRITERIA_MET",
evidence_tier=valid_tier,
pass_authority_scope="CLINICAL_LOT_RELEASE",
bank_qualified_on_wetlab_pass=True,
authorize_promotion_on_wetlab_pass=True,
extra=extra,
)
def evaluate_gate35_gins_oq018_reserve(
payload: Any,
*,
trusted_evidence_store: Optional[Mapping[str, Any]] = None,
canonical_manifest: Optional[Mapping[str, Any]] = None,
canonical_manifest_sha256: Optional[str] = None,
) -> dict[str, Any]:
"""Strict fail-closed evaluator holding Arm Z-GINS at 0.00 pp active Wave-6 credit.
Enforces:
- Structured FAIL dict on top-level non-dict payloads (never raises)
- Mandatory hash-verified canonical_manifest context on AUTHENTICATED_ARCHIVED_WETLAB
- Lot-bound archived study_evidence_record verification in trusted_evidence_store binding
study_id, lot_id, non_integrating_platform_verified==True, vector_copy_number_per_cell==0.0,
process_class=='NON_INTEGRATING_NPM', vcn_assay_id, nhp_durability_pass_count>=3,
and polyclonal_donor_count>=6 (Audit F9 / Review C4 #4)
- active_wave6_credit_pp == 0.0 and promotion_authorized == False ALWAYS.
"""
if not isinstance(payload, dict):
return {
"gate": "Gate 37-GINS-OQ018-Reserve",
"evidence_tier": None,
"verdict": "FAIL",
"decision": "FAIL",
"authority_scope": "REJECTED_OR_HELD",
"bank_qualified": False,
"promotion_authorized": False,
"active_wave6_credit_pp": 0.0,
"wave7_promotion_eligible": False,
"reason": "INVALID_TOP_LEVEL_PAYLOAD_MUST_BE_DICT",
"failures": ["INVALID_TOP_LEVEL_PAYLOAD_MUST_BE_DICT"],
"holds": [],
}
failures: list[str] = []
holds: list[str] = []
ev_tier = payload.get("evidence_tier")
if ev_tier is None:
holds.append("MISSING_evidence_tier")
elif not _is_nonempty_str(ev_tier) or ev_tier not in _ALLOWED_EVIDENCE_TIERS:
failures.append("INVALID_evidence_tier")
valid_tier = ev_tier if (_is_nonempty_str(ev_tier) and ev_tier in _ALLOWED_EVIDENCE_TIERS) else None
_verify_canonical_manifest_context(canonical_manifest, canonical_manifest_sha256, valid_tier, failures)
valid_construct_sha = _verify_parent_manifest_digests(payload, holds, failures)
product_id = payload.get("product_id")
if product_id is None:
holds.append("MISSING_product_id")
elif not _is_nonempty_str(product_id) or product_id not in _CANONICAL_GINS_RESERVE_PRODUCTS:
failures.append("FAIL_UNREGISTERED_OR_MISMATCHED_GINS_PRODUCT_SCOPE")
valid_product = product_id if (_is_nonempty_str(product_id) and product_id in _CANONICAL_GINS_RESERVE_PRODUCTS) else None
for sfld in ("lot_id", "bank_id", "study_record_ref", "vcn_assay_id"):
val = payload.get(sfld)
if val is None:
holds.append(f"MISSING_{sfld}")
elif not _is_nonempty_str(val):
failures.append(f"INVALID_{sfld}")
valid_lot = payload.get("lot_id") if _is_nonempty_str(payload.get("lot_id")) else None
valid_bank = payload.get("bank_id") if _is_nonempty_str(payload.get("bank_id")) else None
valid_study_ref = payload.get("study_record_ref") if _is_nonempty_str(payload.get("study_record_ref")) else None
valid_vcn_assay = payload.get("vcn_assay_id") if _is_nonempty_str(payload.get("vcn_assay_id")) else None
opt_study_id = payload.get("study_id")
if opt_study_id is not None:
if not _is_nonempty_str(opt_study_id):
failures.append("INVALID_study_id")
elif valid_study_ref is not None and opt_study_id != valid_study_ref:
failures.append("FAIL_GINS_STUDY_ID_CONFLICT_WITH_STUDY_RECORD_REF")
# Affirmative non-integrating platform & process class verification
proc_cls = payload.get("process_class")
if proc_cls is None:
holds.append("MISSING_process_class")
elif not _is_nonempty_str(proc_cls) or proc_cls != "NON_INTEGRATING_NPM":
failures.append("FAIL_WRONG_PROCESS_CLASS_REQUIRES_NON_INTEGRATING_NPM")
vcn = payload.get("vector_copy_number_per_cell")
if vcn is None:
holds.append("MISSING_vector_copy_number_per_cell")
elif not _is_num(vcn) or float(vcn) < 0.0:
failures.append("INVALID_vector_copy_number_per_cell")
elif float(vcn) != 0.0:
failures.append("FAIL_NONZERO_VECTOR_COPY_NUMBER_INTEGRATING_PLATFORM")
for bfld, req_val, fcode in [
("non_integrating_platform_verified", True, "FAIL_NON_INTEGRATING_PLATFORM_NOT_VERIFIED"),
("integrating_lentivirus_used", False, "FAIL_REQUIRES_NON_INTEGRATING_NPM"),
("tamoxifen_inducible_fusion_used", False, "FAIL_PROHIBITED_4OHT_NGN3ER_FUSION"),
("liraglutide_free_perifusion", True, "FAIL_REQUIRES_LIRAGLUTIDE_FREE_PERIFUSION"),
("polyclonal_t1d_pbmc_hla_dq_verified", True, "FAIL_REQUIRES_HLA_DQ2P5_DQ8_DONOR_TYPING"),
]:
if bfld not in payload or payload[bfld] is None:
holds.append(f"MISSING_{bfld}")
elif not _is_strict_bool(payload[bfld]):
failures.append(f"INVALID_TYPE_{bfld}")
elif payload[bfld] is not req_val:
failures.append(fcode)
# Lot linkage for durability & polyclonal donor studies
for lfld, fcode in [
("durability_study_lot_id", "FAIL_DURABILITY_STUDY_LOT_ID_MISMATCH"),
("polyclonal_donor_study_lot_id", "FAIL_POLYCLONAL_DONOR_LOT_ID_MISMATCH"),
]:
lv = payload.get(lfld)
if lv is None:
holds.append(f"MISSING_{lfld}")
elif not _is_nonempty_str(lv):
failures.append(f"INVALID_{lfld}")
elif valid_lot is not None and lv != valid_lot:
failures.append(fcode)
# Strict >= 25% (25-30%) monohormonal alpha floor (rejects 20%!)