scripts/evaluate_gate0v_composite_release.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/evaluate_gate0v_composite_release.py · SHA-256: 2be0252340222fe4…
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=reg_with_both_ocr,
openislet_root=openislet_root,
nw08_ocr_json_path=None,
)
# State 2: Matched OCR sidecar present with missing/unverified QA store entry -> HOLD (exit 2, release_authorizing=False)
api_s2 = evaluate_composite_clinical_release(
clin_r2_req_store,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=trusted_store,
openislet_root=openislet_root,
nw08_ocr_record=ocr_r2_req_rec,
)
cli_s2, rc_s2 = evaluate_composite_lot_file(
clin_r2_req_f,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=trusted_store,
openislet_root=openislet_root,
nw08_ocr_json_path=ocr_r2_req_f,
)
# State 3: Verified bound OCR solving below 15.0 mmHg floor -> FAIL (exit 3, release_authorizing=False)
api_s3 = evaluate_composite_clinical_release(
clin_r1_req_store,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=reg_with_both_ocr,
openislet_root=openislet_root,
nw08_ocr_record=ocr_r1_req_fail,
)
cli_s3, rc_s3 = evaluate_composite_lot_file(
clin_r1_req_f,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=reg_with_both_ocr,
openislet_root=openislet_root,
nw08_ocr_json_path=ocr_r1_req_fail_f,
)
# State 4: Verified bound OCR clearing 15.0 mmHg floor -> PASS (exit 0, release_authorizing=True)
api_s4 = evaluate_composite_clinical_release(
clin_r2_req_store,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=reg_with_both_ocr,
openislet_root=openislet_root,
nw08_ocr_record=ocr_r2_req_rec,
)
cli_s4, rc_s4 = evaluate_composite_lot_file(
clin_r2_req_f,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=reg_with_both_ocr,
openislet_root=openislet_root,
nw08_ocr_json_path=ocr_r2_req_f,
)
# Biological FAIL + missing required OCR -> preserves FAIL_HARD_STOP_COMPOSITE_RELEASE (exit 3, release_authorizing=False)
g0v_bio_fail = copy.deepcopy(g0v_clin)
g0v_bio_fail["cxadr_ko_present"] = True
g0v_bio_fail["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_bio_fail)
clin_bio_fail_req = _make_composite_bundle(
clin_lot_id,
mcb_id,
pv_lead,
leg_clin,
g0v_bio_fail,
nw08_route_id="R2_DZ40",
require_trusted_nw08_ocr_record=True,
)
clin_bf_f = Path(td) / "r11_b1_bio_fail_req.json"
clin_bf_f.write_text(json.dumps(clin_bio_fail_req, sort_keys=True), encoding="utf-8")
cli_bf, rc_bf = evaluate_composite_lot_file(
clin_bf_f,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=reg_with_both_ocr,
openislet_root=openislet_root,
nw08_ocr_json_path=None,
)
# Non-bool require_trusted_nw08_ocr_record ("true", 1, None) -> HOLD exit 2, release_authorizing=False!
nonbool_ok = True
for bad_rt in ("true", 1, None):
bad_doc = copy.deepcopy(clin_r2_bundle)
bad_doc["require_trusted_nw08_ocr_record"] = bad_rt
bad_doc["payload_sha256"] = compute_composite_payload_sha256(bad_doc)
r_nb = evaluate_composite_clinical_release(
bad_doc,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=reg_with_both_ocr,
openislet_root=openislet_root,
)
if not (
r_nb["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
and r_nb["release_authorizing"] is False
and "HOLD_NW08_COUPLED_INVALID_REQUIRE_TRUSTED_OCR_FLAG" in r_nb["holds"]
):
nonbool_ok = False
ok_70 = bool(
api_s1["composite_verdict"] == "HOLD_NW08_REQUIRED_OCR_RECORD_MISSING"
and api_s1["release_authorizing"] is False
and "HOLD_NW08_REQUIRED_OCR_RECORD_MISSING" in api_s1["holds"]
and rc_s1 == 2
and cli_s1["composite_verdict"] == "HOLD_NW08_REQUIRED_OCR_RECORD_MISSING"
and cli_s1["release_authorizing"] is False
and api_s2["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
and api_s2["release_authorizing"] is False
and rc_s2 == 2
and cli_s2["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
and cli_s2["release_authorizing"] is False
and api_s3["composite_verdict"] == "FAIL_HARD_STOP_COMPOSITE_RELEASE"
and api_s3["release_authorizing"] is False
and rc_s3 == 3
and cli_s3["composite_verdict"] == "FAIL_HARD_STOP_COMPOSITE_RELEASE"
and cli_s3["release_authorizing"] is False
and api_s4["composite_verdict"] == "PASS_COMPOSITE_CLINICAL_RELEASE"
and api_s4["release_authorizing"] is True
and rc_s4 == 0
and cli_s4["composite_verdict"] == "PASS_COMPOSITE_CLINICAL_RELEASE"
and cli_s4["release_authorizing"] is True
and rc_bf == 3
and cli_bf["composite_verdict"] == "FAIL_HARD_STOP_COMPOSITE_RELEASE"
and cli_bf["release_authorizing"] is False
and "HOLD_NW08_REQUIRED_OCR_RECORD_MISSING" in cli_bf["holds"]
and nonbool_ok
)
cases.append({
"case": "r11_b1_required_nw08_ocr_4state_matrix_api_and_cli_fail_preserved_strict_bool",
"expected_verdict": "HOLD2_HOLD2_FAIL3_PASS0_BIOFAIL3",
"actual_verdict": f"S1_{rc_s1}_S2_{rc_s2}_S3_{rc_s3}_S4_{rc_s4}_BF_{rc_bf}",
"operational_tier": "LOT_RELEASE_SURROGATE",
"legacy_passed": True,
"legacy_tier": LEGACY_PASS_TIER,
"legacy_resolved_pvid": pv_lead,
"gate0v_passed": True,
"gate0v_verdict": "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE",
"expected_token": "HOLD_NW08_REQUIRED_OCR_RECORD_MISSING",
"exit_code": 0 if ok_70 else -1,
"hard_stops": cli_s3["hard_stops"][:2],
"holds": cli_s1["holds"][:3],
"passed": ok_70,
})
# 71. R11-B3: Clustered composite lot (`deff = 2.0161290322580645`, even with 3x scaled counts)
# routes to `HOLD_CLUSTERED_DEFF_GT_1_REQUIRES_CLUSTER_LEVEL_INFERENCE` (exit 2, release_authorizing=False),
# and `PASS_COMPOSITE_BANK_QUALIFICATION` sets `release_authorizing=False, bank_qualification_authorized=True`!
g0v_sol_clin = copy.deepcopy(g0v_clin)
g0v_sol_clin["clustering_and_independence_spec"]["clustering_design_effect_deff"] = "2.0161290322580645"
for _pb in g0v_sol_clin["gate0v_b_infectious_challenge"]["pathogens"].values():
_pb["total_viable_cells_acquired_n"] *= 3
_pb["lineage_unassigned_cells_n"] *= 3
_pb["unassigned_fraction_viral_readout"]["unassigned_cells_screened_n"] = _pb["lineage_unassigned_cells_n"]
_pb["day28_latent_and_defective_genome_arm"]["ddpcr_cell_equivalents_screened_n"] *= 3
for _te in _pb["day28_latent_and_defective_genome_arm"]["ddpcr_targets"].values():
_te["n"] *= 3
for _le in _pb["day28_persistence_by_lineage"].values():
_le["cells_assigned_n"] *= 3
_le["cells_scored_n"] *= 3
for _rb in g0v_sol_clin["gate0v_kill_stress_ap1903"].values():
for _lb in _rb.values():
_lb["ap1903_24h_input_n"] *= 3
_lb["ap1903_72h_input_n"] *= 3
if "pre_ap1903_lineage_input_cells_n" in _lb:
_lb["pre_ap1903_lineage_input_cells_n"] *= 3
v38.reconcile_fixture_per_unit_counts(g0v_sol_clin)
g0v_sol_clin["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_sol_clin)
clin_sol_deff = _make_composite_bundle(clin_lot_id, mcb_id, pv_lead, leg_clin, g0v_sol_clin)
clin_sol_f = Path(td) / "r11_b3_clin_sol_deff.json"
clin_sol_f.write_text(json.dumps(clin_sol_deff, sort_keys=True), encoding="utf-8")
res_71, rc_71 = evaluate_composite_lot_file(
clin_sol_f,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=trusted_store,
openislet_root=openislet_root,
)
ok_71 = bool(
rc_71 == 2
and res_71["composite_verdict"] == "HOLD_CLUSTERED_DEFF_GT_1_REQUIRES_CLUSTER_LEVEL_INFERENCE"
and res_71["release_authorizing"] is False
and "HOLD_CLUSTERED_DEFF_GT_1_REQUIRES_CLUSTER_LEVEL_INFERENCE" in res_71["holds"]
and (res_71.get("gate0v_result_summary") or {}).get("exact_directional_confidence_certified") is False
and bank_res["release_authorizing"] is False
and bank_res["bank_qualification_authorized"] is True
)
cases.append({
"case": "r11_b3_clustered_deff_2p0161_composite_lot_held_cluster_level_inference_exit_2",
"expected_verdict": "HOLD_CLUSTERED_DEFF_GT_1_REQUIRES_CLUSTER_LEVEL_INFERENCE",
"actual_verdict": res_71["composite_verdict"],
"operational_tier": res_71["operational_tier"],
"legacy_passed": (res_71.get("legacy_result_summary") or {}).get("legacy_evaluator_passed"),
"legacy_tier": (res_71.get("legacy_result_summary") or {}).get("lot_release_readiness_tier"),
"legacy_resolved_pvid": (res_71.get("legacy_result_summary") or {}).get("resolved_product_variant_id"),
"gate0v_passed": (res_71.get("gate0v_result_summary") or {}).get("gate0v_evaluator_passed"),
"gate0v_verdict": (res_71.get("gate0v_result_summary") or {}).get("verdict"),
"expected_token": "HOLD_CLUSTERED_DEFF_GT_1_REQUIRES_CLUSTER_LEVEL_INFERENCE",
"exit_code": rc_71,
"hard_stops": res_71["hard_stops"][:2],
"holds": res_71["holds"][:3],
"passed": ok_71,
})
# 72. R11-B4: JSON nesting depth > 64 AND monkeypatched parser RecursionError on `{}` map cleanly
# to structured exit-2 HOLD (`release_authorizing=False`, `JSON_DEPTH_OR_RECURSION_LIMIT_EXCEEDED`)
# across composite lot intake, coupled `--nw08-ocr-json` intake, AND `--trusted-qualification-store` intake!
deep_70_f = Path(td) / "r11_b4_deep_70.json"
deep_70_f.write_text('{"a":' * 70 + "1" + "}" * 70, encoding="utf-8")
empty_f = Path(td) / "r11_b4_empty.json"
empty_f.write_text("{}", encoding="utf-8")
r_d_lot, rc_d_lot = evaluate_composite_lot_file(
deep_70_f, legacy_evaluator=leg_fn, gate0v_evaluator=g0v_fn, openislet_root=openislet_root
)
r_d_ocr, rc_d_ocr = evaluate_composite_lot_file(
clin_r2_f,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=trusted_store,
openislet_root=openislet_root,
nw08_ocr_json_path=deep_70_f,
)
r_d_store, rc_d_store = evaluate_composite_lot_file(
clin_r2_f,
legacy_evaluator=leg_fn,
gate0v_evaluator=g0v_fn,
trusted_qualification_store=deep_70_f,
openislet_root=openislet_root,
)
orig_v38_loads = v38.json.loads
def _raise_rec_comp(*_a: Any, **_kw: Any) -> Any:
raise RecursionError("simulated parser recursion error")
v38.json.loads = _raise_rec_comp # type: ignore[assignment]
try:
r_r_lot, rc_r_lot = evaluate_composite_lot_file(
empty_f, legacy_evaluator=leg_fn, gate0v_evaluator=g0v_fn, openislet_root=openislet_root
)
finally:
v38.json.loads = orig_v38_loads # type: ignore[assignment]
ok_72 = bool(
rc_d_lot == 2
and r_d_lot["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
and r_d_lot["release_authorizing"] is False
and "HOLD_COMPOSITE_AMBIGUOUS_OR_NONCANONICAL_LOT_JSON:JSON_DEPTH_OR_RECURSION_LIMIT_EXCEEDED" in r_d_lot["holds"]
and rc_d_ocr == 2
and r_d_ocr["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
and r_d_ocr["release_authorizing"] is False