missing_dossier_manifest_reasons + custody_reasons, ) if missing_qa_manifest_reasons: return _emit_fail( "FAIL_MISSING_QA_MANIFEST_ATTESTATION", "REJECTED_MISSING_MANIFEST_ATTESTATION", "G0V-MANIFEST-FAIL", missing_qa_manifest_reasons + custody_reasons, ) if manifest_mismatch_reasons: return _emit_fail( "FAIL_CANONICAL_MANIFEST_SHA256_MISMATCH", "REJECTED_MANIFEST_HASH_MISMATCH", "G0V-MANIFEST-FAIL", manifest_mismatch_reasons + custody_reasons, ) if issuer_auth_reasons: return _emit_fail( "FAIL_UNAUTHORIZED_QA_ISSUER", "REJECTED_UNAUTHORIZED_QA_ISSUER", "G0V-ISSUER-FAIL", issuer_auth_reasons + custody_reasons, ) if tier_rule_reasons: return _emit_fail( "FAIL_INAPPLICABLE_QUALIFICATION_TIER_FOR_PRODUCT_FAMILY", "REJECTED_INAPPLICABLE_QUALIFICATION_TIER", "G0V-TIER-FAIL", tier_rule_reasons + custody_reasons, ) if custody_reasons: return _emit_fail( "FAIL_PHYSICAL_EVIDENCE_CUSTODY_MISMATCH", "REJECTED_CUSTODY_MISMATCH", "G0V-CUSTODY-FAIL", custody_reasons + adverse_qual_reasons, ) if adverse_qual_reasons: return _emit_fail( "FAIL_GATE0V_QUALIFICATION_CRITERIA_FAILED", "REJECTED_ADVERSE_GATE0V_MEASUREMENT", "G0V-QUAL-FAIL", adverse_qual_reasons, extra={"owner_gate0v_verdict": owner_eval_verdict, "owner_gate0v_qualification_tier": qual_tier}, ) # Audit R8-03: Explicit positive authorization invariant BEFORE emitting any authorizing receipt! if not (positive_issuer_authorized and positive_reviewer_authorized and bool(qa_issuer_id_val) and bool(qa_reviewer_id_val)): return _emit_fail( "FAIL_UNAUTHORIZED_QA_ISSUER", "REJECTED_UNAUTHORIZED_QA_ISSUER", "G0V-ISSUER-FAIL", ["FAIL_MISSING_POSITIVE_ISSUER_OR_REVIEWER_AUTHORIZATION"], ) if release_scope_val is None or qual_tier is None: return _emit_fail( "FAIL_PHYSICAL_EVIDENCE_CUSTODY_MISMATCH", "REJECTED_CUSTODY_MISMATCH", "G0V-CUSTODY-FAIL", ["UNRESOLVED_RELEASE_SCOPE_OR_TIER"], ) if release_scope_val == "BANK_QUALIFICATION_ONLY": decision = "PASS_WHOLEGRAFT_BANK_QUALIFICATION" authority_scope = "BANK_QUALIFICATION_ONLY" bank_qualified = True promotion_authorized = False else: decision = ( "PASS_WHOLEGRAFT_AUTOLOGOUS_PROCESS_QUAL" if tier_family == "AUTOLOGOUS_D1B_AUTO_C" else "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE" ) authority_scope = "CLINICAL_LOT_RELEASE" bank_qualified = True promotion_authorized = True reg_prov_mode = str(issuer_reg_obj.get("provenance_mode") or "") if isinstance(issuer_reg_obj, dict) else "" trust_prov_mode = str(trust_ctx.get("provenance_mode") or "") inst_prov_mode = str(trust_ctx.get("installation_provenance_mode") or "") # Audit R10-04: ONLY a genuine owner-provisioned production chain may emit operational wet-lab # physical_qualification_complete=True / promotion_authorized=True! Synthetic/plumbing control # registries ALWAYS emit strictly typed non-authorizing SYNTHETIC_FIXTURE receipts! is_owner_provisioned_production = ( trust_prov_mode == "OWNER_PROVISIONED_PRODUCTION" and inst_prov_mode == "OWNER_PROVISIONED_PRODUCTION_INSTALLATION" and reg_prov_mode == "OWNER_PROVISIONED_PRODUCTION_REGISTRY" and isinstance(issuer_reg_obj, dict) and issuer_reg_obj.get("synthetic_fixture_issuers_forbidden") is True and qa_issuer_class_val == "OWNER_PROVISIONED_PRODUCTION" and not any( tok in s.upper() for s in (trust_prov_mode, inst_prov_mode, reg_prov_mode, qa_issuer_class_val, qa_issuer_id_val) for tok in _SYNTHETIC_ISSUER_FORBIDDEN_MARKERS_V2_ROUND10 ) ) scope_short_tag = "BANK" if release_scope_val == "BANK_QUALIFICATION_ONLY" else "CLIN" rec_body: Dict[str, Any] = { "schema_revision": "v2_round5_unified", "record_id": _make_canonical_gate0v_record_id_v2_round9(f"G0V:{scope_short_tag}", canonical_product_id, str(eff_lot_id)), "gate_source": "GATE-0V", "product_id": canonical_product_id, "lot_id": str(eff_lot_id), "bank_id": str(eff_bank_id), "bank_origin": bank_origin, "canonical_arm_manifest_sha256": manifest_sha, "construct_manifest_sha256": str(eff_construct_sha), "evidence_tier": "AUTHENTICATED_ARCHIVED_WETLAB", "evidence_class": "OWNER_PROVISIONED_PRODUCTION", "operational_wetlab_authority": True, "plumbing_control_only": False, "decision": decision, "authority_scope": authority_scope, "bank_qualified": bank_qualified, "promotion_authorized": promotion_authorized, "physical_qualification_complete": True, "modeled_qualification_only": False, "custody_verification_mode": "GOVERNED_ON_DISK_OWNER_STORE_AUTHENTICATED", "custody_authenticated": True, "owner_trust_config_sha256": trust_ctx["config_sha256"], "installation_id": trust_ctx["installation_id"], "installation_identity_sha256": trust_ctx["installation_identity_sha256"], "trust_provenance_mode": trust_prov_mode, "qa_issuer_registry_sha256": trust_ctx["qa_issuer_registry_sha256"], "qa_issuer_registry_provenance_mode": reg_prov_mode, "physical_dossier_id": str(eff_dossier_id), "physical_dossier_sha256": dossier_sha, "qa_signoff_id": str(eff_qa_signoff_id), "qa_signoff_sha256": qa_sha, "qa_issuer_id": qa_issuer_id_val, "qa_reviewer_id": qa_reviewer_id_val, "owner_gate0v_qualification_tier": qual_tier, "owner_gate0v_verdict": owner_eval_verdict, "lineages_verified": sorted(_GY030_REQUIRED_5_LINEAGES), "whole_graft_stressed_tested": True, "estimand1_u_esc": parsed_metrics["estimand1_u_esc"], "estimand2_u_cond": parsed_metrics["estimand2_u_cond"], "caspase_fold_activity": parsed_metrics["caspase_fold_activity"], "five_virus_max_fold_vs_wt": parsed_metrics["five_virus_max_fold_vs_wt"], "nhs20_cdc_c5b9_u95_pct": parsed_metrics["nhs20_cdc_c5b9_u95_pct"], } if release_scope_val == "CLINICAL_LOT_RELEASE": rec_body["release_authorizing"] = True # Audit R10-04, R11-05 & R12-06: Route PASS through the SAME single unified finalizer! sealed = _finalize_gate0v_cli_receipt( rec_body, is_synthetic_plumbing=(not is_owner_provisioned_production), ) # Audit R7-06: Register positive receipt strictly ONCE under a single canonical key (.json)! issued_dir = store_root / "issued_receipts" if issued_dir.is_symlink(): return _emit_fail( "FAIL_PHYSICAL_EVIDENCE_CUSTODY_MISMATCH", "REJECTED_CUSTODY_MISMATCH", "G0V-CUSTODY-FAIL", ["ISSUED_RECEIPTS_DIR_SYMLINK_FORBIDDEN"], ) issued_dir.mkdir(parents=True, exist_ok=True) reg_file = issued_dir / f"{sealed['archive_sha256']}.json" if reg_file.is_symlink(): return _emit_fail( "FAIL_PHYSICAL_EVIDENCE_CUSTODY_MISMATCH", "REJECTED_CUSTODY_MISMATCH", "G0V-CUSTODY-FAIL", ["ISSUED_RECEIPT_FILE_SYMLINK_FORBIDDEN"], ) serialized = json.dumps(sealed, indent=2, sort_keys=True, ensure_ascii=False, allow_nan=False) + "\n" if reg_file.is_file(): existing_txt = reg_file.read_text(encoding="utf-8") if existing_txt != serialized: return _emit_fail( "FAIL_PHYSICAL_EVIDENCE_CUSTODY_MISMATCH", "REJECTED_CUSTODY_MISMATCH", "G0V-CUSTODY-FAIL", ["ISSUED_RECEIPT_CONFLICTING_OVERWRITE_FORBIDDEN"], ) else: tmp_file = issued_dir / f".tmp_{sealed['archive_sha256']}_{_os_g0v.getpid()}.json" tmp_file.write_text(serialized, encoding="utf-8") _os_g0v.replace(tmp_file, reg_file) return sealed, 0 def emit_gate0v_physical_evidence_receipt_v2_round5( lookup_request: _AbcMapping[str, Any] | None = None, *, arm_id: Any = None, lot_id: Any = None, bank_id: Any = None, product_id: Any = None, construct_manifest_sha256: Any = None, dossier_id: Any = None, qa_signoff_id: Any = None, expected_dossier_sha256: Any = None, expected_qa_signoff_sha256: Any = None, expected_canonical_manifest_sha256: Any = None, release_scope: Any = None, governed_store_root: Path | str | None = None, canonical_manifest_path: Path | str | None = None, owner_physical_dossier_store: Any = None, owner_qa_signoff_store: Any = None, owner_qa_issuer_registry: Any = None, issued_receipt_store: Any = None, canonical_arm_manifest: Any = None, canonical_arm_manifest_sha256: Any = None, openislet_root: Path | None = None, ) -> Dict[str, Any]: """Governed Python wrapper for Gate 0V physical receipt issuance (Audit R7-06 / R7-07 / R7-12 / R12-06). STRICTLY REJECTS mutable caller-supplied dict/mapping stores with FAIL_MUTABLE_CALLER_STORE_FORBIDDEN and delegates exclusively to on-disk governed store resolution.""" if any( x is not None for x in ( owner_physical_dossier_store, owner_qa_signoff_store, owner_qa_issuer_registry, issued_receipt_store, ) ): _tctx_m, _ = _load_and_verify_owner_trust_config_v2_round9(_resolve_openislet_root(openislet_root)) return _finalize_gate0v_cli_receipt( _make_fail_closed_gate0v_custody_receipt_v2_round7( decision="FAIL_MUTABLE_CALLER_STORE_FORBIDDEN", authority_scope="REJECTED_MUTABLE_CALLER_STORE", evidence_tier="UNAUTHENTICATED_FAIL", record_prefix="G0V-STORE-FAIL", product_id=_safe_str_v2_round8(product_id), lot_id=_safe_str_v2_round8(lot_id), bank_id=_safe_str_v2_round8(bank_id), bank_origin="", manifest_sha="", construct_manifest_sha256=_safe_str_v2_round8(construct_manifest_sha256), dossier_id=_safe_str_v2_round8(dossier_id) or None, qa_signoff_id=_safe_str_v2_round8(qa_signoff_id) or None, custody_failure_reasons=["CALLER_SUPPLIED_IN_MEMORY_STORE_FORBIDDEN_USE_GOVERNED_STORE_ROOT"], ), is_synthetic_plumbing=_is_synthetic_plumbing_installation_v2_round13(_tctx_m), ) eff_exp_msha = expected_canonical_manifest_sha256 if expected_canonical_manifest_sha256 is not None else canonical_arm_manifest_sha256 rec, _rc = issue_gate0v_physical_receipt_from_governed_root( lookup_request, arm_id=arm_id, lot_id=lot_id, bank_id=bank_id, product_id=product_id, construct_manifest_sha256=construct_manifest_sha256, dossier_id=dossier_id,