scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py · SHA-256: 25e12d578ba80b55…
"derived_nhp_eligible_visit_n": eval_res["derived_nhp_eligible_visit_n"],
"derived_nhp_zero_complications": eval_res["derived_nhp_zero_complications"],
"derived_nhp_eligible_diabetic_n": eval_res["derived_nhp_eligible_diabetic_n"],
"derived_nhp_qualified_ii_count": eval_res["derived_nhp_ii"],
"derived_nhp_cpeptide_extinction_verified_count": eval_res["derived_nhp_cpeptide_extinction_verified_count"],
"derived_rest_pulse1_si_ratio": _safe_round(eval_res["derived_rest_p1_ratio"], 4),
"derived_rest_pulse2_si_ratio": _safe_round(eval_res["derived_rest_p2_ratio"], 4),
"derived_rest_endpoint_ratio": _safe_round(eval_res["derived_rest_endpoint_ratio"], 4),
"primary_exvivo_rest_h4_credit_pp": 0.0,
}
if fail_sorted:
return {
**meta,
"status": "FAIL",
"decision": "FAIL_GATE35_ADVERSE_SAFETY_OR_SPEC_VIOLATION",
"authority_scope": "REJECTED_OR_HELD",
"promotion_authorized": False,
"experiment_booking_authorized": False,
"fail_reasons": fail_sorted,
"hold_reasons": hold_sorted,
"reasons": all_reasons,
}
if hold_sorted:
return {
**meta,
"status": "HOLD",
"decision": "HOLD_GATE35_MISSING_MANDATORY_EVIDENCE",
"authority_scope": "REJECTED_OR_HELD",
"promotion_authorized": False,
"experiment_booking_authorized": False,
"fail_reasons": [],
"hold_reasons": hold_sorted,
"reasons": all_reasons,
}
# HARD RULE (R2-01): SYNTHETIC_FIXTURE records MUST NEVER authorize clinical promotion!
if valid_evidence_tier == "SYNTHETIC_FIXTURE":
return {
**meta,
"status": "SYNTHETIC_SELF_TEST_PASS" if is_promo else "SYNTHETIC_SELF_TEST_BOOKING_PASS",
"decision": "SYNTHETIC_SELF_TEST_PASS" if is_promo else "SYNTHETIC_SELF_TEST_BOOKING_PASS",
"authority_scope": "SYNTHETIC_SELF_TEST",
"promotion_authorized": False,
"experiment_booking_authorized": False,
"synthetic_fixture_valid": True,
"site_tier": "LEAD_VISCERAL_PORTAL" if eff_site == "R4_OMENTUM_LEAD" else "SECONDARY_BACKUP_SUBARS",
"fail_reasons": [],
"hold_reasons": [],
"reasons": [],
}
if not is_promo:
return {
**meta,
"status": "PASS_BOOKING_ONLY",
"decision": "PASS_STAGE0_CANDIDATE_EXPERIMENT_BOOKING_ONLY",
"authority_scope": "BANK_QUALIFICATION_ONLY",
"promotion_authorized": False,
"experiment_booking_authorized": True,
"site_tier": "LEAD_VISCERAL_PORTAL" if eff_site == "R4_OMENTUM_LEAD" else "SECONDARY_BACKUP_SUBARS",
"fail_reasons": [],
"hold_reasons": [],
"reasons": [],
}
# Review #6 / Audit R4-03: ANIMAL_PRECLINICAL_SCALE can NEVER authorize CLINICAL_LOT_RELEASE!
if eff_scale_mode == "ANIMAL_PRECLINICAL_SCALE":
return {
**meta,
"status": "STAGE_LIMITED_PRECLINICAL_ONLY",
"decision": "STAGE_LIMITED_PRECLINICAL_ONLY",
"authority_scope": "STAGE_LIMITED_PRECLINICAL_ONLY",
"promotion_authorized": False,
"experiment_booking_authorized": True,
"site_tier": "LEAD_VISCERAL_PORTAL" if eff_site == "R4_OMENTUM_LEAD" else "SECONDARY_BACKUP_SUBARS",
"fail_reasons": [],
"hold_reasons": [],
"reasons": ["ANIMAL_PRECLINICAL_SCALE_CANNOT_AUTHORIZE_CLINICAL_LOT_RELEASE"],
}
return {
**meta,
"status": "PASS",
"decision": "PASS_GATE35_CLINICAL_PROMOTION_AUTHORIZED",
"authority_scope": "CLINICAL_LOT_RELEASE",
"promotion_authorized": True,
"experiment_booking_authorized": True,
"site_tier": "LEAD_VISCERAL_PORTAL" if eff_site == "R4_OMENTUM_LEAD" else "SECONDARY_BACKUP_SUBARS",
"fail_reasons": [],
"hold_reasons": [],
"reasons": [],
}
evaluate_gate35_route4_omentum_and_exvivo_rest = evaluate_gate33_route4_omentum_and_exvivo_rest
def _make_upstream_fixture_bundle(
arm_manifest: Dict[str, Any],
*,
arm_key: str,
lot_id: str,
evidence_tier: str,
bank_id: Optional[str] = None,
construct_manifest_sha256: Optional[str] = None,
) -> Tuple[Dict[str, Dict[str, Any]], Dict[str, Dict[str, Any]]]:
"""Build 3 unified v2_round5_unified upstream records (collision-free GATE-34, GATE-0V, live Blueprint OQ-012 GATE-5) plus store."""
spec = arm_manifest["arms"][arm_key]
b_id = bank_id if bank_id is not None else f"BANK-{arm_key}-001"
c_sha = construct_manifest_sha256 if construct_manifest_sha256 is not None else _fixture_construct_manifest_sha256(arm_key, spec["product_id"])
is_synth = (evidence_tier == "SYNTHETIC_FIXTURE")
auth_scope = "SYNTHETIC_SELF_TEST" if is_synth else "CLINICAL_LOT_RELEASE"
bank_qual = False if is_synth else True
promo_auth = False if is_synth else True
g5_n_tested = 1_000_000_000
g5_f_clon = 0.50
g5_eta_det = 0.80
g5_n_eff = 400_000_000
g5_u95 = clopper_pearson_u95(0, g5_n_eff, alpha=0.05)
g0v_dec = (
"SYNTHETIC_SELF_TEST_PASS"
if is_synth
else ("PASS_WHOLEGRAFT_AUTOLOGOUS_PROCESS_QUAL" if arm_key == "D" else "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE")
)
g0v = seal_upstream_evidence_record({
"schema_revision": UPSTREAM_RECEIPT_SCHEMA_REVISION,
"record_id": f"REC-G0V-{arm_key}-{lot_id}",
"gate_source": "GATE-0V",
"product_id": spec["product_id"],
"lot_id": lot_id,
"bank_id": b_id,
"bank_origin": spec["cell_origin"],
"canonical_arm_manifest_sha256": EXPECTED_CANONICAL_MANIFEST_SHA256,
"construct_manifest_sha256": c_sha,
"evidence_tier": evidence_tier,
"decision": g0v_dec,
"authority_scope": auth_scope,
"bank_qualified": bank_qual,
"promotion_authorized": promo_auth,
"lineages_verified": sorted(REQUIRED_GY030_LINEAGES),
"whole_graft_stressed_tested": True,
})
g5 = seal_upstream_evidence_record({
"schema_revision": UPSTREAM_RECEIPT_SCHEMA_REVISION,
"record_id": f"REC-G5-{arm_key}-{lot_id}",
"gate_source": "GATE-5",
"product_id": spec["product_id"],
"lot_id": lot_id,
"bank_id": b_id,
"bank_origin": spec["cell_origin"],
"canonical_arm_manifest_sha256": EXPECTED_CANONICAL_MANIFEST_SHA256,
"construct_manifest_sha256": c_sha,
"evidence_tier": evidence_tier,
"decision": "SYNTHETIC_SELF_TEST_PASS" if is_synth else "PASS_GATE5_OQ012_CLONOGENIC_ERADICATION",
"authority_scope": auth_scope,
"bank_qualified": bank_qual,
"promotion_authorized": promo_auth,
"oq012_clonogenic_regrowth_pass": True,
"survivor_count_k": 0,
"tested_cells_n": g5_n_tested,
"clonogenic_fraction_f": g5_f_clon,
"spike_in_detection_efficiency_eta": g5_eta_det,
"effective_clonogenic_trials_n_eff": g5_n_eff,
"u95_exact": g5_u95,
})
g34 = seal_upstream_evidence_record({
"schema_revision": UPSTREAM_RECEIPT_SCHEMA_REVISION,
"record_id": f"REC-G34-{arm_key}-{lot_id}",
"gate_source": "GATE-34",
"product_id": spec["product_id"],
"lot_id": lot_id,
"bank_id": b_id,
"bank_origin": spec["cell_origin"],
"canonical_arm_manifest_sha256": EXPECTED_CANONICAL_MANIFEST_SHA256,
"construct_manifest_sha256": c_sha,
"evidence_tier": evidence_tier,
"decision": "SYNTHETIC_SELF_TEST_PASS" if is_synth else "PASS_GATE34_CLINICAL_LOT_RELEASE",
"authority_scope": auth_scope,
"bank_qualified": bank_qual,
"promotion_authorized": promo_auth,
"dual_switch_lot_qualified": bool(spec["dual_switch_required_for_release"]),
"prerequisite_archive_sha256s": {
"GATE-0V": g0v["archive_sha256"],
"GATE-5": g5["archive_sha256"],
},
})
records = {
"upstream_gate32_record": g34,
"upstream_gate0v_record": g0v,
"upstream_gate5_oq012_record": g5,
}
store = {r["record_id"]: dict(r) for r in records.values()}
return records, store
def seal_gate33_current_assay_record(
payload: Mapping[str, Any],
*,
arm_manifest: Optional[Dict[str, Any]] = None,
record_id: Optional[str] = None,
decision: Optional[str] = None,
authority_scope: Optional[str] = None,
bank_qualified: Optional[bool] = None,
promotion_authorized: Optional[bool] = None,
) -> Dict[str, Any]:
"""Build and SHA-256-seal a v2_round5_unified collision-free GATE-35 current_assay_evidence_record from payload measurements."""
manifest, err = _get_verified_canonical_manifest(arm_manifest)
require_cond(manifest is not None and err is None, f"Cannot seal current_assay record without verified manifest: {err}")
arm_key = str(payload.get("arm_key", "Y"))
spec = manifest["arms"].get(arm_key)
bank_origin = spec["cell_origin"] if isinstance(spec, dict) else "allogeneic_hiPSC"
product_id = str(payload.get("product_id", spec["product_id"] if isinstance(spec, dict) else "UNKNOWN"))
lot_id = str(payload.get("lot_id", "LOT-UNKNOWN"))
bank_id = str(payload.get("bank_id", f"BANK-{arm_key}-001"))
c_sha = str(payload.get("construct_manifest_sha256") or _fixture_construct_manifest_sha256(arm_key, product_id))
ev_tier = str(payload.get("evidence_tier", "SYNTHETIC_FIXTURE"))
is_synth = (ev_tier == "SYNTHETIC_FIXTURE")
is_promo = (payload.get("evaluation_scope") == "CLINICAL_PROMOTION")
scale_m = payload.get("scale_mode")
if decision is None:
if is_synth:
decision = "SYNTHETIC_SELF_TEST_PASS" if is_promo else "SYNTHETIC_SELF_TEST_BOOKING_PASS"
elif not is_promo:
decision = "PASS_STAGE0_CANDIDATE_EXPERIMENT_BOOKING_ONLY"
elif scale_m == "ANIMAL_PRECLINICAL_SCALE":
decision = "STAGE_LIMITED_PRECLINICAL_ONLY"
else:
decision = "PASS_GATE35_CURRENT_ASSAY_VERIFIED"
if authority_scope is None:
if is_synth:
authority_scope = "SYNTHETIC_SELF_TEST"
elif (not is_promo) or (scale_m == "ANIMAL_PRECLINICAL_SCALE"):
authority_scope = "BANK_QUALIFICATION_ONLY"
else:
authority_scope = "CLINICAL_LOT_RELEASE"
if bank_qualified is None:
bank_qualified = False if is_synth else True
if promotion_authorized is None:
promotion_authorized = False if (is_synth or (not is_promo) or (scale_m == "ANIMAL_PRECLINICAL_SCALE")) else True
body: Dict[str, Any] = {
"schema_revision": UPSTREAM_RECEIPT_SCHEMA_REVISION,
"record_id": record_id if record_id is not None else f"REC-G35-CUR-{arm_key}-{lot_id}",
"gate_source": "GATE-35",
"product_id": product_id,
"lot_id": lot_id,
"bank_id": bank_id,