donors_with_invalid_topology.add(did_t) # Pass 1c (R16 Shared Blocker #1): Reconcile the fixed-horizon predeclared per-donor sample size N # commitment across ALL raw submitted rostered donor rows BEFORE the duplicate-donor exclusion gate! # Any raw rostered row whose unit counts violate roster_predeclared_n_by_donor[did] (in ANY row order, # e.g. [60, 70] or [70, 60] on a conflicted duplicate donor) populates roster_sample_size_plan_mismatched_donors # and sets authorization_grade_fwer_bound_valid = False, withholding donor-cohort authorization while # preserving zero biological credit for duplicate rows, avoiding false N-mismatches on matching-count # duplicates ([60, 60]), and preserving fail-first independent qualified SPR FAIL! if roster_verified: for idx_n, d_n in enumerate(donors_raw): if not isinstance(d_n, dict): continue did_raw_n = d_n.get("donor_id") if type(did_raw_n) is not str or not did_raw_n.strip(): continue did_n = did_raw_n.strip() if did_n not in roster_predeclared_n_by_donor: continue committed_n = roster_predeclared_n_by_donor[did_n] has_raw_u_n = "raw_independent_units_n" in d_n and d_n["raw_independent_units_n"] is not None has_raw_alias_n = "cytotoxicity_n_raw_units" in d_n and d_n["cytotoxicity_n_raw_units"] is not None raw_u_primary_n: int | None = None raw_u_alias_n: int | None = None if has_raw_u_n: raw_u_primary_n, _ = _shield_check_strict_int( d_n["raw_independent_units_n"], f"donors[{idx_n}].raw_independent_units_n", min_val=1 ) if has_raw_alias_n: raw_u_alias_n, _ = _shield_check_strict_int( d_n["cytotoxicity_n_raw_units"], f"donors[{idx_n}].cytotoxicity_n_raw_units", min_val=1 ) raw_u_ok = ( (has_raw_u_n or has_raw_alias_n) and (not has_raw_u_n or raw_u_primary_n == committed_n) and (not has_raw_alias_n or raw_u_alias_n == committed_n) ) n_eff_n, _ = _shield_check_strict_int( d_n.get("apc_cytotoxicity_n_eff"), f"donors[{idx_n}].apc_cytotoxicity_n_eff", min_val=1 ) gy_n = d_n.get("gy018_independence_justification") pd_n_raw: int | None = None if isinstance(gy_n, dict): pd_n_raw, _ = _shield_check_strict_int( gy_n.get("predeclared_per_donor_unit_count_n"), f"donors[{idx_n}].gy018_independence_justification.predeclared_per_donor_unit_count_n", min_val=_SHIELD_MIN_CYTO_N_EFF_PER_DONOR, ) if not raw_u_ok or n_eff_n != committed_n or pd_n_raw != committed_n: roster_sample_size_plan_mismatched_donors.add(did_n) _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_n}] (row[{idx_n}]): submitted cytotoxicity sample size " f"(raw_independent_units_n={raw_u_primary_n if has_raw_u_n else raw_u_alias_n}, " f"apc_cytotoxicity_n_eff={n_eff_n}, gy018.predeclared_per_donor_unit_count_n={pd_n_raw}) " f"violates hash-pinned preregistered_donor_family_roster fixed-horizon commitment " f"N={committed_n} (unauthorized post-readout or interim sample-size change invalidates " f"fixed-horizon Bonferroni FWER <= 0.05)", ) # Pass 2: Validate each non-conflicted donor record (T1D eligibility, assay_run_id, suppression assay acceptance range, GY-018 evidence!) for idx, d in enumerate(donors_raw): if not isinstance(d, dict): _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"donors[{idx}] must be an object") continue did = d.get("donor_id") if type(did) is not str or not did.strip(): _escalate("HOLD_INVALID_OR_MISSING_INPUT", f"donors[{idx}] missing non-empty donor_id") continue did_c = did.strip() seen_donors.add(did_c) if did_c in conflicted_donors: continue donor_valid = True if did != did_c or not _SHIELD_STRICT_ID_RE.match(did): donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donors[{idx}].donor_id={did!r} must be an unpadded canonical ID matching {_SHIELD_STRICT_ID_RE.pattern}", ) if did_c in unrostered_submitted_donors or did_c in excluded_overlap_donors: donor_valid = False # R08 B5: Mandatory typed T1D donor eligibility verification (excluded from PASS and bio FAIL if invalid!) if d.get("t1d_diagnosis_confirmed") is not True: donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: mandatory t1d_diagnosis_confirmed must be literal boolean True " f"(got {d.get('t1d_diagnosis_confirmed')!r})", ) cohort_raw = d.get("donor_clinical_cohort") if type(cohort_raw) is not str or cohort_raw != _SHIELD_REQUIRED_DONOR_CLINICAL_COHORT: donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: mandatory donor_clinical_cohort must equal " f"{_SHIELD_REQUIRED_DONOR_CLINICAL_COHORT!r} (got {cohort_raw!r})", ) prequal_raw = d.get("t1d_prequalification_ref") if type(prequal_raw) is not str or not prequal_raw or prequal_raw != prequal_raw.strip(): donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: mandatory t1d_prequalification_ref must be a non-empty unpadded string " f"(got {prequal_raw!r})", ) if _SHIELD_FORBIDDEN_NON_T1D_DONOR_RE.search(did_c): donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: contradictory non-T1D donor_id rejected fail-closed regardless of boolean flags", ) if type(prequal_raw) is str and _SHIELD_FORBIDDEN_NON_T1D_DONOR_RE.search(prequal_raw): donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: contradictory non-T1D t1d_prequalification_ref={prequal_raw!r} rejected fail-closed", ) raw_assay_run = d.get("assay_run_id") assay_run_c: str | None = None if ( type(raw_assay_run) is not str or not raw_assay_run or raw_assay_run != raw_assay_run.strip() or not _SHIELD_STRICT_ID_RE.match(raw_assay_run) ): donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: mandatory assay_run_id must be a non-empty unpadded ID matching " f"{_SHIELD_STRICT_ID_RE.pattern} (got {raw_assay_run!r})", ) else: assay_run_c = raw_assay_run tmp_ref_d: set[str] = set() tmp_ck1_d: set[str] = set() tmp_ck2_d: set[str] = set() b_err = _shield_validate_batch_ids( d.get("expression_batch_ids"), f"donor[{did_c}]", passing_batch_constructs, tmp_ref_d, require_cocktail_both_leads=True, role_comp1_batches=tmp_ck1_d, role_comp2_batches=tmp_ck2_d, ) raw_mix_id = d.get("cocktail_mixture_id") if b_err is not None: donor_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", b_err) if ( type(raw_mix_id) is not str or not raw_mix_id or raw_mix_id != raw_mix_id.strip() or not _SHIELD_STRICT_ID_RE.match(raw_mix_id) ): donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: missing or invalid mandatory cocktail_mixture_id referencing a passing " f"physical mixture in sec_mals_dls_monomer_coformulation.qualified_coformulation_mixtures " f"(got {raw_mix_id!r}); excluded from biological adjudication and batch-linkage credit", ) elif not sec_cocktail_qualified or raw_mix_id not in qualified_passing_mixtures: donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: excluded from biological adjudication and batch-linkage credit because " f"cocktail_mixture_id={raw_mix_id!r} lacks a passing physical co-formulation SEC-MALS/DLS " f"qualification record (qualified_mixtures={sorted(qualified_passing_mixtures.keys())})", ) elif b_err is None: mix_c1_bid, mix_c2_bid = qualified_passing_mixtures[raw_mix_id] expected_mix_batches = {mix_c1_bid, mix_c2_bid} if ( tmp_ref_d != expected_mix_batches or mix_c1_bid not in tmp_ck1_d or mix_c2_bid not in tmp_ck2_d ): donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: excluded from biological adjudication and batch-linkage credit because " f"cocktail expression_batch_ids={sorted(tmp_ref_d)} do not match the exact physical " f"co-formulation mixture {raw_mix_id!r} component lot pair " f"(comp1={mix_c1_bid!r}, comp2={mix_c2_bid!r}); crossed or unqualified lot combination rejected", ) has_hla = "hla_genotype" in d and d["hla_genotype"] is not None has_hla_alias = "hla_dq_genotype" in d and d["hla_dq_genotype"] is not None if has_hla and has_hla_alias and str(d["hla_genotype"]).strip() != str(d["hla_dq_genotype"]).strip(): donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: hla_genotype={d['hla_genotype']!r} disagrees with hla_dq_genotype={d['hla_dq_genotype']!r}", ) raw_hla = d["hla_genotype"] if has_hla else d.get("hla_dq_genotype") _, hla_err = _shield_parse_qualifying_hla_genotype(raw_hla, f"donor[{did_c}]") if hla_err is not None: donor_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", hla_err) # R09 B3 + R10 B5 + R11 M1: Enforce suppression assay acceptance range [-1000.0, 100.0]% (100% blockade down to -1000% = 11x enhancement); # out-of-range values (< -1000.0 or > 100.0, e.g. -1e200) fail closed to HOLD_INVALID_OR_MISSING_INPUT without OverflowError, # while valid negative enhancement values in [-1000.0, 0.0) route to the anti-enhancement safety guard (min >= 0.0%) -> HOLD. sup_v, sup_err = _shield_check_num( d.get("suppression_pct"), f"donor[{did_c}].suppression_pct", lo=_SHIELD_SUPPRESSION_ASSAY_ACCEPTANCE_MIN_PCT, hi=_SHIELD_SUPPRESSION_ASSAY_ACCEPTANCE_MAX_PCT, ) if sup_err is not None or sup_v is None: donor_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", sup_err or f"Invalid donor[{did_c}].suppression_pct") # GY-018-compliant denominator verification (EXACT deff == 1.0 with zero tolerance & n_eff == raw_n >= 60) has_raw_u = "raw_independent_units_n" in d and d["raw_independent_units_n"] is not None has_raw_alias = "cytotoxicity_n_raw_units" in d and d["cytotoxicity_n_raw_units"] is not None if has_raw_u and has_raw_alias and d["raw_independent_units_n"] != d["cytotoxicity_n_raw_units"]: donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: raw_independent_units_n disagrees with cytotoxicity_n_raw_units", ) raw_units_in = d["raw_independent_units_n"] if has_raw_u else d.get("cytotoxicity_n_raw_units") raw_units_n, raw_u_err = _shield_check_strict_int( raw_units_in, f"donor[{did_c}].raw_independent_units_n", min_val=1 ) if raw_u_err is not None: donor_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", raw_u_err) deff_v, deff_err = _shield_check_exact_deff(d.get("design_effect_deff"), f"donor[{did_c}].design_effect_deff") if deff_err is not None or deff_v is None: donor_valid = False _escalate("HOLD_INVALID_OR_MISSING_INPUT", deff_err or f"Invalid donor[{did_c}].design_effect_deff") indep_model = d.get("cytotoxicity_independence_model") if type(indep_model) is not str or indep_model != _SHIELD_CYTO_INDEPENDENCE_MODEL: donor_valid = False _escalate( "HOLD_INVALID_OR_MISSING_INPUT", f"donor[{did_c}]: cytotoxicity_independence_model must be {_SHIELD_CYTO_INDEPENDENCE_MODEL!r} (got {indep_model!r})", ) # R09 M1 + R10 B3 + R12 0037-B3: Mandatory authorization-grade strict closed-schema GY-018 independence