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…
single_or_split[rrid]["primary_outcome"] = 0
if rrid in pooled:
pooled[rrid]["rescued"] = True
pooled[rrid]["rescue_lot_ids"] = rlots
pooled[rrid]["rescued_primary_lot_ids"] = rprims
pooled[rrid]["primary_outcome"] = 0
return single_or_split, pooled, all_lot_rows
def _audit_raw_cmc_ledger_ancestry(
lot_ledger_raw: Any,
*,
ref_mcb_map: dict[str, str],
ref_wcb_map: dict[str, str],
observed_wcb_to_mcbs: dict[str, set[str]],
clinical_recipient_meta: dict[str, dict[str, Any]] | None = None,
raw_ancestry_claims_by_rid: dict[str, list[tuple[str | None, tuple[str, ...], tuple[str, ...], bool]]] | None = None,
) -> tuple[list[str], bool]:
"""
Single-source-of-truth raw PARALLEL_CMC_READINESS_LEDGER ancestry auditor executed across EVERY
disposition (primary, split, pooled, rescue, released-uninfused, manufacturing-failed) BOTH when
evaluate_cmc_attempted_lot_readiness succeeds AND when it raises any exception (preventing
initial-validation or compound non-ancestry errors from bypassing fail-closed ancestry invalidation).
Returns (ancestry_errors, has_ancestry_conflict).
"""
if not isinstance(lot_ledger_raw, list) or len(lot_ledger_raw) == 0:
return (
[
"CMC_LEDGER_ANCESTRY_UNVERIFIABLE: PARALLEL_CMC_READINESS_LEDGER lot_ledger must be a non-empty list of lot dicts."
],
True,
)
errs: list[str] = []
conflict = False
tree_wcb_to_mcbs: dict[str, set[str]] = {
wid_o: set(mcbs_o) for wid_o, mcbs_o in observed_wcb_to_mcbs.items()
}
for lid_r, wid_r in sorted(ref_wcb_map.items()):
if lid_r in ref_mcb_map:
tree_wcb_to_mcbs.setdefault(wid_r, set()).add(ref_mcb_map[lid_r])
seen_lots_raw: dict[str, tuple[str, str | None]] = {}
raw_primary_lot_rids: dict[str, set[str]] = {}
raw_rescue_rows: list[tuple[str, str | None, str | None, str | None]] = []
rescue_wcbs_seen: set[str] = set()
raw_lot_rows_by_lid: dict[
str,
list[
tuple[
Any,
str | None,
Any,
str | None,
Any,
set[str] | None,
set[str] | None,
set[str] | None,
bool,
bool,
bool,
]
],
] = {}
ordered_ledger_raw = sorted(lot_ledger_raw, key=_canonical_cmc_lot_sort_key)
for idx, entry in enumerate(ordered_ledger_raw):
if not isinstance(entry, dict):
errs.append(f"CMC_LEDGER_ANCESTRY_UNVERIFIABLE: raw PARALLEL_CMC_READINESS_LEDGER lot_ledger[{idx}] is not a dict.")
conflict = True
continue
lid = _strict_literal_id(entry.get("lot_id"))
mid = _strict_literal_id(entry.get("mcb_id"))
disp_raw = entry.get("disposition")
disp = _strict_literal_id(disp_raw)
lt_raw = entry.get("lot_type")
lt = _strict_literal_id(lt_raw)
infused_raw = entry.get("infused_doses_n")
# Extract EVERY supplied raw recipient-binding field SEPARATELY (ZERO silent union across fields!)
raw_out_dict = entry.get("recipient_outcomes")
raw_out_recs = entry.get("recipient_records")
raw_rids = entry.get("recipient_ids")
od_present = raw_out_dict is not None
od_valid_container = isinstance(raw_out_dict, dict)
od_valid_ids: list[str] = []
od_bad_keys: list[Any] = []
if od_valid_container:
for rk in sorted(raw_out_dict.keys(), key=repr):
lr = _strict_literal_id(rk)
if lr is None:
od_bad_keys.append(rk)
else:
od_valid_ids.append(lr)
od_set: set[str] | None = set(od_valid_ids) if (od_present and od_valid_container and not od_bad_keys) else None
rr_present = raw_out_recs is not None
rr_valid_container = isinstance(raw_out_recs, list)
rr_valid_ids: list[str] = []
rr_malformed = False
if rr_valid_container:
for r_obj in raw_out_recs:
if not isinstance(r_obj, dict):
rr_malformed = True
continue
lr = _strict_literal_id(r_obj.get("recipient_id"))
if lr is None:
rr_malformed = True
else:
rr_valid_ids.append(lr)
rr_has_dups = len(set(rr_valid_ids)) != len(rr_valid_ids)
rr_set: set[str] | None = (
set(rr_valid_ids) if (rr_present and rr_valid_container and not rr_malformed and not rr_has_dups) else None
)
ri_present = raw_rids is not None
ri_valid_container = isinstance(raw_rids, list)
ri_valid_ids: list[str] = []
ri_bad_ids: list[Any] = []
if ri_valid_container:
for rk in raw_rids:
lr = _strict_literal_id(rk)
if lr is None:
ri_bad_ids.append(rk)
else:
ri_valid_ids.append(lr)
ri_has_dups = len(set(ri_valid_ids)) != len(ri_valid_ids)
ri_set: set[str] | None = (
set(ri_valid_ids) if (ri_present and ri_valid_container and not ri_bad_ids and not ri_has_dups) else None
)
if lid is not None:
raw_lot_rows_by_lid.setdefault(lid, []).append(
(
disp_raw,
disp,
lt_raw,
lt,
infused_raw,
od_set,
rr_set,
ri_set,
od_present,
rr_present,
ri_present,
)
)
# Pass-0 separate raw primary recipient-binding validation BEFORE general CMC shape/outcome validation
# so earlier malformed split-lot counts can NEVER mask contradictory recipient bindings or leave ancestry positive!
if lt != "RESCUE_REPEAT_LOT":
lot_lbl = repr(lid) if lid is not None else f"lot_ledger[{idx}]"
if disp in ("FAILED_RELEASE", "RELEASED_UNINFUSED"):
if od_present and (not od_valid_container or len(raw_out_dict) > 0):
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER uninfused/failed "
f"lot {lot_lbl} (lot_type={lt!r}, disposition={disp!r}) must have empty recipient_outcomes; "
"ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
if rr_present and (not rr_valid_container or len(raw_out_recs) > 0):
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER uninfused/failed "
f"lot {lot_lbl} (lot_type={lt!r}, disposition={disp!r}) must have empty recipient_records; "
"ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
if ri_present and (not ri_valid_container or len(raw_rids) > 0):
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER uninfused/failed "
f"lot {lot_lbl} (lot_type={lt!r}, disposition={disp!r}) must have empty recipient_ids; "
"ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
elif disp == "RELEASED_INFUSED":
if not od_present and not rr_present:
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"lot {lot_lbl} (lot_type={lt!r}) is missing explicit recipient_outcomes or "
"recipient_records binding; ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
if od_present:
if not od_valid_container:
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"lot {lot_lbl} (lot_type={lt!r}) recipient_outcomes must be a dict; "
"ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
elif od_bad_keys:
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"lot {lot_lbl} (lot_type={lt!r}) recipient_outcomes contains invalid literal "
f"recipient_id key(s) {od_bad_keys!r}; ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
elif len(od_valid_ids) == 0:
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"lot {lot_lbl} (lot_type={lt!r}) has empty recipient_outcomes; "
"ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
if rr_present:
if not rr_valid_container:
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"lot {lot_lbl} (lot_type={lt!r}) recipient_records must be a list; "
"ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
elif rr_malformed or rr_has_dups:
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"lot {lot_lbl} (lot_type={lt!r}) recipient_records contains malformed or duplicate "
"recipient_id entries; ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
elif len(rr_valid_ids) == 0:
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"lot {lot_lbl} (lot_type={lt!r}) has empty recipient_records; "
"ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
if ri_present:
if not ri_valid_container:
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"lot {lot_lbl} (lot_type={lt!r}) recipient_ids must be a list; "
"ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
elif ri_bad_ids or ri_has_dups:
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"lot {lot_lbl} (lot_type={lt!r}) recipient_ids contains invalid literal or duplicate "
"recipient_id entries; ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True
elif len(ri_valid_ids) == 0:
errs.append(
f"CMC_PRIMARY_RECIPIENT_BINDING_CONFLICT: raw PARALLEL_CMC_READINESS_LEDGER infused "
f"lot {lot_lbl} (lot_type={lt!r}) has empty recipient_ids; "
"ancestry verification and cluster statistics nullified fail-closed."
)
conflict = True