scripts/verify_iip0041_clinical_h1_cd64t_siglec.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0041_clinical_h1_cd64t_siglec.py · SHA-256: f004cf6d8259b8b4…
if rr_malformed or len(set(valid_rr_ids)) != len(valid_rr_ids):
malformed_cmc_rescue_errs.append(
f"CMC_RESCUE_RECIPIENT_BINDING_CONFLICT / CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: "
f"raw PARALLEL_CMC_READINESS_LEDGER infused RESCUE_REPEAT_LOT {lid!r} recipient_records "
"contains malformed or duplicate recipient_id entries; "
"ancestry verification and cluster statistics nullified fail-closed."
)
ancestry_conflict = True
else:
valid_rr_sorted = sorted(valid_rr_ids)
bound_sets.append(("recipient_records", valid_rr_sorted))
if resc_rid is not None and valid_rr_sorted != [resc_rid]:
malformed_cmc_rescue_errs.append(
f"CMC_RESCUE_RECIPIENT_BINDING_CONFLICT / CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: "
f"raw PARALLEL_CMC_READINESS_LEDGER infused RESCUE_REPEAT_LOT {lid!r} declares "
f"recipient_records recipient_ids={valid_rr_sorted!r}, contradicting "
f"rescued_recipient_id={resc_rid!r}; ancestry verification and cluster statistics nullified fail-closed."
)
ancestry_conflict = True
elif resc_rid is None and len(valid_rr_sorted) != 1:
malformed_cmc_rescue_errs.append(
f"CMC_RESCUE_RECIPIENT_BINDING_CONFLICT / CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: "
f"raw PARALLEL_CMC_READINESS_LEDGER infused RESCUE_REPEAT_LOT {lid!r} declares "
f"recipient_records recipient_ids={valid_rr_sorted!r} (expected exactly 1 rescued recipient); "
"ancestry verification and cluster statistics nullified fail-closed."
)
ancestry_conflict = True
if raw_rids is not None:
if not isinstance(raw_rids, list):
malformed_cmc_rescue_errs.append(
f"CMC_RESCUE_RECIPIENT_BINDING_CONFLICT / CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: "
f"raw PARALLEL_CMC_READINESS_LEDGER infused RESCUE_REPEAT_LOT {lid!r} recipient_ids must be a list; "
"ancestry verification and cluster statistics nullified fail-closed."
)
ancestry_conflict = True
else:
valid_rids_list: list[str] = []
bad_rids_list: list[Any] = []
for rk in raw_rids:
lr = _strict_literal_id(rk)
if lr is None:
bad_rids_list.append(rk)
else:
valid_rids_list.append(lr)
if bad_rids_list or len(set(valid_rids_list)) != len(valid_rids_list):
malformed_cmc_rescue_errs.append(
f"CMC_RESCUE_RECIPIENT_BINDING_CONFLICT / CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: "
f"raw PARALLEL_CMC_READINESS_LEDGER infused RESCUE_REPEAT_LOT {lid!r} recipient_ids "
"contains invalid literal or duplicate recipient_id entries; "
"ancestry verification and cluster statistics nullified fail-closed."
)
ancestry_conflict = True
else:
valid_rids_sorted = sorted(valid_rids_list)
bound_sets.append(("recipient_ids", valid_rids_sorted))
if resc_rid is not None and valid_rids_sorted != [resc_rid]:
malformed_cmc_rescue_errs.append(
f"CMC_RESCUE_RECIPIENT_BINDING_CONFLICT / CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: "
f"raw PARALLEL_CMC_READINESS_LEDGER infused RESCUE_REPEAT_LOT {lid!r} declares "
f"recipient_ids={valid_rids_sorted!r}, contradicting "
f"rescued_recipient_id={resc_rid!r}; ancestry verification and cluster statistics nullified fail-closed."
)
ancestry_conflict = True
elif resc_rid is None and len(valid_rids_sorted) != 1:
malformed_cmc_rescue_errs.append(
f"CMC_RESCUE_RECIPIENT_BINDING_CONFLICT / CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: "
f"raw PARALLEL_CMC_READINESS_LEDGER infused RESCUE_REPEAT_LOT {lid!r} declares "
f"recipient_ids={valid_rids_sorted!r} (expected exactly 1 rescued recipient); "
"ancestry verification and cluster statistics nullified fail-closed."
)
ancestry_conflict = True
if len(bound_sets) >= 2 and len({tuple(vals) for _lbl, vals in bound_sets}) > 1:
malformed_cmc_rescue_errs.append(
f"CMC_RESCUE_RECIPIENT_BINDING_CONFLICT / CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: "
f"raw PARALLEL_CMC_READINESS_LEDGER infused RESCUE_REPEAT_LOT {lid!r} has mutually contradictory "
f"recipient bindings {bound_sets!r}; ancestry verification and cluster statistics nullified fail-closed."
)
ancestry_conflict = True
if resc_rid is None:
malformed_cmc_rescue_errs.append(
f"CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"RESCUE_REPEAT_LOT {lid!r} is missing valid literal rescued_recipient_id."
)
ancestry_conflict = True
continue
if resc_rid not in seen_rids:
non_cohort_cmc_rescues.append((resc_rid, lid))
ancestry_conflict = True
continue
cmc_rescue_lots_by_rid.setdefault(resc_rid, []).append(lid)
cmc_rescue_lineages_by_rid.setdefault(resc_rid, []).append((lid, mid, wid))
for merr in sorted(set(malformed_cmc_rescue_errs)):
if merr not in errs:
errs.append(merr)
for r_target, clid_r in sorted(non_cohort_cmc_rescues):
nc_msg = (
f"CMC_EXTRA_RESCUE_LOT_OMITTED_FROM_CLINICAL_COHORT: raw PARALLEL_CMC_READINESS_LEDGER "
f"infused RESCUE_REPEAT_LOT {clid_r!r} references non-cohort recipient {r_target!r}."
)
if nc_msg not in errs:
errs.append(nc_msg)
for rid in sorted(seen_rids):
cmeta = clinical_recipient_meta.get(rid)
if cmeta is None:
continue
cmc_rescue_lots: list[str] = sorted(cmc_rescue_lots_by_rid.get(rid, []))
cmc_rescue_lineages: list[tuple[str, str | None, str | None]] = sorted(
cmc_rescue_lineages_by_rid.get(rid, []),
key=repr,
)
if rid in duplicate_rids_set:
dup_cmc_msg = (
f"DUPLICATE_CLINICAL_RECIPIENT_INVALIDATES_CMC_RECONCILIATION: recipient {rid!r} "
f"appears {len(raw_ancestry_claims_by_rid[rid])} times in clinical cohort "
"(1:1 unique CMC reconciliation invalidated deterministically)."
)
if dup_cmc_msg not in errs:
errs.append(dup_cmc_msg)
dup_resc_errs_rid = duplicate_rescue_errors_by_rid.get(rid, [])
for dup_resc_err in dup_resc_errs_rid:
if dup_resc_err not in errs:
errs.append(dup_resc_err)
if dup_resc_errs_rid:
ancestry_conflict = True
dup_rlids_sorted = sorted(
{
rlid_x
for rc_x in raw_rescue_claims_by_rid.get(rid, [])
for rlid_x in rc_x.get("rescue_lot_ids", ())
}
)
dup_rescue_lineages = sorted(
{
(rlid_x, ref_mcb_map.get(rlid_x), ref_wcb_map.get(rlid_x))
for rlid_x in dup_rlids_sorted
},
key=repr,
)
distinct_bank_lineages = {
(mcb_x, wcb_x) for _rl, mcb_x, wcb_x in dup_rescue_lineages
}
if len(distinct_bank_lineages) > 1 or any(
mcb_x is None for _rl, mcb_x, _wcb in dup_rescue_lineages
):
anc_resc_msg = (
f"CONFLICTING_DUPLICATE_RECIPIENT_RESCUE_ANCESTRY: duplicate clinical rows "
f"for recipient_id={rid!r} reference incompatible linked rescue lineages "
f"{dup_rescue_lineages!r}; ancestry verification and cluster statistics nullified fail-closed."
)
if anc_resc_msg not in errs:
errs.append(anc_resc_msg)
rclaims_to_check = cmeta.get("all_raw_rescue_claims") or [{
"intercurrent_event": cmeta["intercurrent_event"],
"rescue_declared": cmeta["rescue_declared"],
"rescue_lot_ids": tuple(cmeta["rescue_lot_ids"]),
"explicit_rescue_ids_provided": cmeta["explicit_rescue_ids_provided"],
"missing_explicit_rescue_lot_id": cmeta.get("missing_explicit_rescue_lot_id", False),
"rescue_parse_error": cmeta["rescue_parse_error"],
}]
for rclaim_chk in rclaims_to_check:
clin_rescue_lots: list[str] = list(rclaim_chk["rescue_lot_ids"])
clin_rescue_lineages: list[tuple[str, str | None, str | None]] = sorted(
[(rlid_c, ref_mcb_map.get(rlid_c), ref_wcb_map.get(rlid_c)) for rlid_c in clin_rescue_lots],
key=repr,
)
if rclaim_chk["rescue_parse_error"]:
err_rp = f"RESCUE_LOT_CARDINALITY_MISMATCH: recipient {rid!r} has invalid or conflicting clinical rescue declarations."
if err_rp not in errs:
errs.append(err_rp)
if not rclaim_chk["rescue_declared"]:
if len(cmc_rescue_lots) > 0:
err_ex0 = (
f"CMC_EXTRA_RESCUE_LOT_OMITTED_FROM_CLINICAL_COHORT / RESCUE_LOT_CARDINALITY_MISMATCH: "
f"recipient {rid!r} has {len(cmc_rescue_lots)} infused CMC rescue lot(s) {cmc_rescue_lots!r} "
f"omitted from clinical cohort (clinical intercurrent_event={rclaim_chk['intercurrent_event']!r}, expected 0 rescue lots)."
)
if err_ex0 not in errs:
errs.append(err_ex0)
err_lin0 = (
f"CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: recipient {rid!r} has infused PARALLEL_CMC_READINESS_LEDGER "
f"rescue lot lineage(s) {cmc_rescue_lineages!r} omitted from clinical cohort "
f"(clinical intercurrent_event={rclaim_chk['intercurrent_event']!r}); ancestry verification and cluster statistics nullified fail-closed."
)
if err_lin0 not in errs:
errs.append(err_lin0)
ancestry_conflict = True
elif rclaim_chk["explicit_rescue_ids_provided"]:
if len(cmc_rescue_lots) == 0:
err_om1 = (
f"CLINICAL_RESCUE_OMITTED_FROM_CMC_LEDGER / RESCUE_LOT_CARDINALITY_MISMATCH: "
f"recipient {rid!r} declares clinical rescue lot(s) {clin_rescue_lots!r} with 0 "
"matching infused RESCUE_REPEAT_LOT records in PARALLEL_CMC_READINESS_LEDGER."
)
if err_om1 not in errs:
errs.append(err_om1)
err_lin1 = (
f"CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: recipient {rid!r} declares clinical rescue lot "
f"lineage(s) {clin_rescue_lineages!r} omitted from PARALLEL_CMC_READINESS_LEDGER infused rescue rows; "
"ancestry verification and cluster statistics nullified fail-closed."
)
if err_lin1 not in errs:
errs.append(err_lin1)
ancestry_conflict = True
elif cmc_rescue_lots != clin_rescue_lots:
extra_cmc_resc = sorted((Counter(cmc_rescue_lots) - Counter(clin_rescue_lots)).elements())
missing_cmc_resc = sorted((Counter(clin_rescue_lots) - Counter(cmc_rescue_lots)).elements())
if extra_cmc_resc:
err_ex1 = (
f"CMC_EXTRA_RESCUE_LOT_OMITTED_FROM_CLINICAL_COHORT / RESCUE_LOT_CARDINALITY_MISMATCH: "
f"recipient {rid!r} raw PARALLEL_CMC_READINESS_LEDGER reports extra infused rescue lot(s) "
f"{extra_cmc_resc!r} omitted from clinical cohort "
f"(clinical={clin_rescue_lots!r} [n={len(clin_rescue_lots)}] vs cmc={cmc_rescue_lots!r} [n={len(cmc_rescue_lots)}])."
)
if err_ex1 not in errs:
errs.append(err_ex1)
if missing_cmc_resc:
err_ms1 = (
f"CLINICAL_RESCUE_LOT_ID_MISMATCH_IN_CMC_LEDGER / RESCUE_LOT_CARDINALITY_MISMATCH: "
f"recipient {rid!r} clinical rescue lot(s) {missing_cmc_resc!r} missing from "
f"PARALLEL_CMC_READINESS_LEDGER infused rescue lots "
f"(clinical={clin_rescue_lots!r} [n={len(clin_rescue_lots)}] vs cmc={cmc_rescue_lots!r} [n={len(cmc_rescue_lots)}])."
)
if err_ms1 not in errs:
errs.append(err_ms1)
err_lin2 = (
f"CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: recipient {rid!r} clinical rescue lot lineage(s) "
f"{clin_rescue_lineages!r} contradict PARALLEL_CMC_READINESS_LEDGER infused rescue lot lineage(s) "
f"{cmc_rescue_lineages!r}; ancestry verification and cluster statistics nullified fail-closed."
)
if err_lin2 not in errs:
errs.append(err_lin2)
ancestry_conflict = True
elif cmc_rescue_lineages != clin_rescue_lineages:
err_lin_same = (
f"CLINICAL_CMC_RESCUE_IDENTITY_CONFLICT: recipient {rid!r} clinical/manifest rescue lot lineage(s) "
f"{clin_rescue_lineages!r} contradict PARALLEL_CMC_READINESS_LEDGER infused rescue lot lineage(s) "
f"{cmc_rescue_lineages!r} on matching rescue lot(s) {clin_rescue_lots!r}; "
"ancestry verification and cluster statistics nullified fail-closed."
)
if err_lin_same not in errs:
errs.append(err_lin_same)
ancestry_conflict = True
else: