scripts/verify_iip0055_hygiene_safecell_minifh_orthogonality.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0055_hygiene_safecell_minifh_orthogonality.py · SHA-256: d5b98e2ba1310333…
if uses_hsv_tk is not None and uses_hsv_tk is not expected_dual_req:
fail_reasons.append("FAIL_CDK1_HSV_TK_ARM_MANIFEST_MISMATCH")
if arm_id_str == "D" and uses_icasp8 is False:
fail_reasons.append("FAIL_D1B_LEAN_K2_REQUIRES_SINGLE_LAYER_ACTB_ICASP8")
if arm_id_str in ("A", "B", "X", "Y", "Z") and uses_icasp8 is True:
fail_reasons.append("FAIL_ICASP8_NOT_ASSIGNED_TO_THIS_ARM_IN_MANIFEST")
# Reconcile caller switch/locus declarations strictly against verified lot construct switch_registry_by_id (Review #1)
if registered_primary_switch_verified:
if uses_icasp8 is not None and uses_icasp8 is not registered_primary_is_icasp8:
fail_reasons.append("FAIL_CALLER_ICASP8_CONTRADICTS_CONSTRUCT_SWITCH_REGISTRY")
if uses_d315a is not None and uses_d315a is not registered_primary_is_d315a:
fail_reasons.append("FAIL_CALLER_D315A_CONTRADICTS_CONSTRUCT_SWITCH_REGISTRY")
if pan_locus_str is not None:
if registered_primary_is_icasp8 is True and pan_locus_str != "ACTB_CHR7_3UTR_IRES":
fail_reasons.append("FAIL_PAN_LINEAGE_LOCUS_CONTRADICTS_CONSTRUCT_SWITCH_REGISTRY")
elif registered_primary_is_icasp8 is False and registered_primary_switch_id != "AAVS1::iCasp9" and pan_locus_str != "TBP_CHR6_3UTR_IRES":
fail_reasons.append("FAIL_PAN_LINEAGE_LOCUS_CONTRADICTS_CONSTRUCT_SWITCH_REGISTRY")
for active_sw_key in ("active_switch", "active_switch_id"):
if active_sw_key in payload and payload[active_sw_key] is not None:
asw = payload[active_sw_key]
allowed_asw = {x for x in (registered_primary_switch_id, registered_primary_benchmark_arm) if x is not None}
if not _is_clean_str(asw) or (registered_primary_switch_verified and asw not in allowed_asw):
fail_reasons.append("FAIL_CALLER_ACTIVE_SWITCH_CONTRADICTS_CONSTRUCT_SWITCH_REGISTRY")
if uses_hsv_tk is True and mhc_i_intact is True:
fail_reasons.append("FAIL_HSV_TK_PROHIBITED_ON_MHC_I_INTACT_ARM")
if uses_d315a is True and mhc_i_intact is True:
fail_reasons.append("FAIL_ICASP9_D315A_PROHIBITED_ON_MHC_I_INTACT_ARM")
if uses_htmpk is True and may_c07 is True:
fail_reasons.append("FAIL_HTMPK_F105Y_RYAFSGVAY_PROHIBITED_ON_HLA_C07_ARM")
if arm_id_str in ("D", "X") and may_c07 is False:
fail_reasons.append("FAIL_SELF_MHC_OR_HLAC_ARM_CANNOT_WAIVE_HLA_C07_SCREEN")
# P0-1 / C1.2: Ban release-level independence-assumed 1e-12 claim AND ban single-switch dual-escape inheritance
if dual_req is False and (dual_claim is True or "dual_layer_proliferative_escape_prob" in payload):
fail_reasons.append("FAIL_SINGLE_SWITCH_ARM_CANNOT_CLAIM_DUAL_ESCAPE")
if "dual_layer_proliferative_escape_prob" in payload:
fail_reasons.append("FAIL_INDEPENDENCE_ASSUMED_DUAL_ESCAPE_SCALAR_PROHIBITED_FOR_RELEASE")
if dual_claim is True:
fail_reasons.append("FAIL_INDEPENDENCE_ASSUMED_DUAL_ESCAPE_CLAIM_PROHIBITED_FOR_RELEASE")
req_bool("pmid_11242052_paired_with_23572523", expected=True, fail_code="FAIL_MISSING_PMID_11242052_ERRATUM_23572523_PAIRING")
# 3. Complement protection, unpaired ECD cysteines, & Design Y-v3 / Z split
comp_mode_raw = payload.get("complement_protection_mode")
comp_mode_str: Optional[str] = None
if comp_mode_raw is None:
hold_reasons.append("HOLD_MISSING_COMPLEMENT_PROTECTION_MODE")
elif not _is_clean_str(comp_mode_raw):
fail_reasons.append("FAIL_PROHIBITED_COMPLEMENT_MODE_CD46WT_OR_CD55_OVEREXPRESSION")
else:
comp_mode_str = comp_mode_raw
if arm_id_str is not None and comp_mode_str not in ALLOWED_COMPLEMENT_MODES_BY_ARM[arm_id_str]:
fail_reasons.append("FAIL_PROHIBITED_OR_MISMATCHED_COMPLEMENT_MODE_FOR_ARM")
req_int("ecd_unpaired_cysteine_count", exact=0, fail_code="FAIL_UNPAIRED_ECD_CYSTEINES_PRESENT", domain_code="FAIL_NON_INTEGER_UNPAIRED_CYS_COUNT")
lys265_ok = req_bool("minifh_lys265_and_g4s4_restored")
is_minifh_mode = comp_mode_str in ("TM_MINIFH_MONO_V2_PDGFRB_PLUS_CD59", "TM_MINIFH_MONO_V2_CD8A_C164S_C181S_PLUS_CD59")
if is_minifh_mode:
if lys265_ok is False:
fail_reasons.append("FAIL_MINIFH_MISSING_LYS265_OR_G4S4_LINKER")
if mhc_i_intact is True:
fail_reasons.append("FAIL_TM_MINIFH_CONFINED_TO_B2M_NULL_ARM_ONLY")
req_bool("design_y_uses_gapdh_7p2kb_3utr", expected=False, fail_code="FAIL_DESIGN_Y_GAPDH_7P2KB_3UTR_NMD_TRAP")
# 4. D1b-Lean-K2 CTL defense, explicit TXNIP-KO ban, explicit Design A zero-drug, PMIDs, orthogonality
is_auto_d1b = req_bool("is_autologous_d1b")
d1b_k2_flag = req_bool("d1b_has_universal_cxcl10_sb9_pdl1_k2")
if arm_id_str is not None and is_auto_d1b is not None:
if is_auto_d1b is not (arm_id_str == "D"):
fail_reasons.append("FAIL_IS_AUTOLOGOUS_D1B_ARM_MISMATCH")
if is_auto_d1b is True and d1b_k2_flag is False:
fail_reasons.append("FAIL_UNPATCHED_D1B_K1_VULNERABLE_TO_TWIN_CD8_RECURRENCE")
req_bool("txnip_ko_present", expected=False, fail_code="FAIL_GY026_TXNIP_KO_PROHIBITED")
if "txnip_ko_promoted" in payload and payload["txnip_ko_promoted"] is not False:
fail_reasons.append("FAIL_GY026_TXNIP_KO_PROHIBITED")
req_bool("design_a_strict_zero_drug", expected=True, fail_code="FAIL_DESIGN_A_STRICT_ZERO_DRUG_POLICY_VIOLATED")
cited_pmids = payload.get("cited_pmids")
if cited_pmids is None:
hold_reasons.append("HOLD_MISSING_CITED_PMIDS")
elif not isinstance(cited_pmids, list) or len(cited_pmids) == 0:
fail_reasons.append("FAIL_EMPTY_OR_INVALID_CITED_PMIDS_LIST")
elif any(not _is_clean_pmid_str(x) for x in cited_pmids):
fail_reasons.append("FAIL_MALFORMED_PMID_IN_CITED_PMIDS")
else:
for bad_p in QUARANTINED_ERROR_PMIDS:
if bad_p in cited_pmids:
fail_reasons.append(f"FAIL_QUARANTINED_WRONG_PMID_{bad_p}")
if "11242052" in cited_pmids and "23572523" not in cited_pmids:
fail_reasons.append("FAIL_PMID_11242052_CITED_WITHOUT_23572523")
if len(set(cited_pmids)) < 12 or not set(PRIMARY_12_PMIDS).issubset(set(cited_pmids)):
fail_reasons.append("FAIL_INCOMPLETE_CANONICAL_PRIMARY_12_PMIDS")
phi_inc = payload.get("modeled_phi_inc")
if phi_inc is None:
hold_reasons.append("HOLD_MISSING_MODELED_PHI_INC")
elif not _is_finite_number(phi_inc) or float(phi_inc) < 0.25 or float(phi_inc) > 1.0:
fail_reasons.append("FAIL_UNDERPRICED_OR_OUT_OF_DOMAIN_PHI_INC")
req_bool("orthogonality_zero_silent_exemptions", expected=True, fail_code="FAIL_SILENT_ORTHOGONALITY_EXEMPTIONS_PROHIBITED")
# 5. Archived & verified GY-030 5-lineage Gate 0V record (with strict bank vs clinical scope separation!)
# & unified Gate 5 clonogenic record (with exact high-precision Decimal Clopper-Pearson U95!)
g0v_is_bank_only = False
g0v_rec, g0v_verified = _resolve_archived_record(
"gate0v_5lineage_record",
prefix="GATE0V_5LINEAGE_RECORD",
expected_gate_source="GATE-0V",
allowed_decisions=VALID_GATE0V_PASS_VERDICTS,
role="gate0v",
)
if g0v_rec is not None:
g0v_dec = g0v_rec["decision"]
g0v_scope = g0v_rec["authority_scope"]
g0v_bq = g0v_rec["bank_qualified"]
g0v_pa = g0v_rec["promotion_authorized"]
g0v_tier = g0v_rec["evidence_tier"]
# Reject explicitly prohibited authority scopes immediately (Review #2)
if g0v_scope in {"REJECTED_OR_HELD", "STAGE_LIMITED_SORT_ONLY", "COMPONENT_SORT_QUALIFICATION_ONLY", "WAVE7_RESERVE_ONLY"}:
fail_reasons.append(f"FAIL_GATE0V_PROHIBITED_AUTHORITY_SCOPE_{g0v_scope}")
g0v_verified = False
# Cross-scope auto/allo Gate 0V MUST ALWAYS FAIL!
if arm_id_str == "D" and g0v_dec in GATE0V_ALLO_CLINICAL_DECISIONS:
fail_reasons.append("FAIL_GATE0V_CROSS_SCOPE_ALLOGENEIC_DECISION_ON_AUTOLOGOUS_ARM")
g0v_verified = False
elif arm_id_str in ("A", "B", "X", "Y", "Z") and g0v_dec in GATE0V_AUTO_CLINICAL_DECISIONS:
fail_reasons.append("FAIL_GATE0V_CROSS_SCOPE_AUTOLOGOUS_DECISION_ON_ALLOGENEIC_ARM")
g0v_verified = False
elif g0v_dec in GATE0V_BANK_ONLY_DECISIONS or g0v_scope == "BANK_QUALIFICATION_ONLY":
# Bank-only qualification: NEVER authorizes FULL_CLINICAL_PROMOTION!
if g0v_dec not in GATE0V_BANK_ONLY_DECISIONS or g0v_scope != "BANK_QUALIFICATION_ONLY":
fail_reasons.append("FAIL_GATE0V_BANK_ONLY_SCOPE_DECISION_MISMATCH")
g0v_verified = False
if g0v_pa is True:
fail_reasons.append("FAIL_GATE0V_BANK_ONLY_CANNOT_CLAIM_PROMOTION_AUTHORIZED")
g0v_verified = False
if g0v_tier == "AUTHENTICATED_ARCHIVED_WETLAB" and g0v_bq is not True:
fail_reasons.append("FAIL_GATE0V_BANK_ONLY_NOT_BANK_QUALIFIED")
g0v_verified = False
g0v_is_bank_only = True
else:
expected_clin = GATE0V_AUTO_CLINICAL_DECISIONS if arm_id_str == "D" else GATE0V_ALLO_CLINICAL_DECISIONS
if g0v_tier == "AUTHENTICATED_ARCHIVED_WETLAB":
if g0v_dec not in expected_clin:
fail_reasons.append("FAIL_GATE0V_CLINICAL_LOT_RELEASE_DECISION_REQUIRED")
g0v_verified = False
if g0v_scope != "CLINICAL_LOT_RELEASE" or g0v_bq is not True or g0v_pa is not True:
fail_reasons.append("FAIL_GATE0V_CLINICAL_LOT_RELEASE_AUTHORITY_REQUIRED")
g0v_verified = False
else:
if g0v_dec not in (expected_clin | {"SYNTHETIC_SELF_TEST_PASS"}):
fail_reasons.append("FAIL_GATE0V_SYNTHETIC_DECISION_INVALID")
g0v_verified = False
if g0v_scope != "SYNTHETIC_SELF_TEST" or g0v_bq is True or g0v_pa is True:
fail_reasons.append("FAIL_GATE0V_SYNTHETIC_AUTHORITY_INVALID")
g0v_verified = False
# Canonical lineages_verified (accept legacy alias lineages_tested ONLY if identical or lineages_verified absent)
lin_v = g0v_rec.get("lineages_verified")
lin_t = g0v_rec.get("lineages_tested")
if lin_v is None and lin_t is None:
hold_reasons.append("HOLD_MISSING_GATE0V_LINEAGES_VERIFIED")
g0v_verified = False
else:
if lin_v is not None and (not isinstance(lin_v, list) or any(not _is_clean_str(x) for x in lin_v)):
fail_reasons.append("FAIL_GY030_REQUIRES_5_LINEAGE_WHOLEGRAFT")
g0v_verified = False
elif lin_t is not None and (not isinstance(lin_t, list) or any(not _is_clean_str(x) for x in lin_t)):
fail_reasons.append("FAIL_GY030_REQUIRES_5_LINEAGE_WHOLEGRAFT")
g0v_verified = False
elif lin_v is not None and lin_t is not None and set(lin_v) != set(lin_t):
fail_reasons.append("FAIL_GATE0V_LINEAGES_VERIFIED_VS_TESTED_MISMATCH")
g0v_verified = False
else:
lin_eff = lin_v if lin_v is not None else lin_t
if set(lin_eff) != GY030_REQUIRED_5_LINEAGES:
fail_reasons.append("FAIL_GY030_REQUIRES_5_LINEAGE_WHOLEGRAFT")
g0v_verified = False
wg_stress = g0v_rec.get("whole_graft_stressed_tested")
if wg_stress is None:
hold_reasons.append("HOLD_MISSING_GATE0V_WHOLE_GRAFT_STRESSED_TESTED")
g0v_verified = False
elif not _is_strict_bool(wg_stress) or wg_stress is not True:
fail_reasons.append("FAIL_GATE0V_WHOLE_GRAFT_STRESSED_TESTED_REQUIRED")
g0v_verified = False
est1 = g0v_rec.get("estimand1_u_esc")
if est1 is None:
hold_reasons.append("HOLD_MISSING_GATE0V_ESTIMAND1_U_ESC")
g0v_verified = False
elif not _is_finite_number(est1) or float(est1) < 0.0 or float(est1) > 1.0e-4:
fail_reasons.append("FAIL_GATE0V_ESTIMAND1_U_ESC_GT_1E_MINUS_4")
g0v_verified = False
est2 = g0v_rec.get("estimand2_u_cond")
if est2 is None:
hold_reasons.append("HOLD_MISSING_GATE0V_ESTIMAND2_U_COND")
g0v_verified = False
elif not _is_finite_number(est2) or float(est2) < 0.0 or float(est2) > 1.0e-3:
fail_reasons.append("FAIL_GATE0V_ESTIMAND2_U_COND_GT_1E_MINUS_3")
g0v_verified = False
casp_fold = g0v_rec.get("caspase_fold_activity")
if casp_fold is None:
hold_reasons.append("HOLD_MISSING_GATE0V_CASPASE_FOLD_ACTIVITY")
g0v_verified = False
elif not _is_finite_number(casp_fold) or float(casp_fold) < 5.0:
fail_reasons.append("FAIL_GATE0V_CASPASE_FOLD_ACTIVITY_LT_5X")
g0v_verified = False
fv = g0v_rec.get("five_virus_max_fold_vs_wt")
if fv is None:
hold_reasons.append("HOLD_MISSING_GATE0V_FIVE_VIRUS_READOUT")
g0v_verified = False
elif not _is_finite_number(fv) or float(fv) <= 0.0 or float(fv) > 1.20:
fail_reasons.append("FAIL_GATE0V_FIVE_VIRUS_INFECTIVITY_EXCEEDED")
g0v_verified = False
cdc = g0v_rec.get("nhs20_cdc_c5b9_u95_pct")
if cdc is None:
hold_reasons.append("HOLD_MISSING_GATE0V_NHS20_CDC_READOUT")
g0v_verified = False
elif not _is_finite_number(cdc) or float(cdc) < 0.0 or float(cdc) > 5.0:
fail_reasons.append("FAIL_GATE0V_NHS20_CDC_LYSIS_GT_5PCT")
g0v_verified = False
g5_rec, g5_verified = _resolve_archived_record(
"gate5_panlineage_clonogenic_record",
prefix="GATE5_CLONOGENIC_RECORD",
expected_gate_source="GATE-5",
allowed_decisions=GATE5_ALLOWED_DECISIONS,
role="gate5",
)
if g5_rec is not None:
g5_dec = g5_rec["decision"]
g5_scope = g5_rec["authority_scope"]
g5_bq = g5_rec["bank_qualified"]
g5_pa = g5_rec["promotion_authorized"]
g5_tier = g5_rec["evidence_tier"]
if g5_scope in PROHIBITED_SUPPORTING_AUTHORITY_SCOPES:
fail_reasons.append(f"FAIL_GATE5_PROHIBITED_AUTHORITY_SCOPE_{g5_scope}")
g5_verified = False
if g5_tier == "AUTHENTICATED_ARCHIVED_WETLAB":
if g5_dec not in GATE5_WETLAB_PASS_DECISIONS: