"""Join witnessed, frozen geometric judgments to custody data without changing seals.""" from pathlib import Path from collections import Counter import csv import hashlib import json from datetime import datetime, timezone ROOT = Path('artifacts/s2-g1-custody-handoff-2026-11-14') OLD = Path('artifacts/s2-g1-blind120-2026-11-14') SHA = { 'sampling-and-mapping.json': '3a9495efad4196763713c20f8b9158d86fce3fb60409242208b67bcb481e37f9', 'pose-mapping-v1.json': '0b99923ed2de9d9bcf5d6032b72dacd9962cc3a08ec0da3703f673072b07c4fe', 'frozen-review.csv': '282f78136e01ca35dd7191b25e995f159d246769bd02c9bfa542d93737de01de', 'reviewer-attestation.md': 'd50ccb179316cb518d0bde78252eca03cb2c995d9afd546623a9a47e841ef7d5', } def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest() def save(path, data): with path.open('x') as f: json.dump(data, f, ensure_ascii=False, indent=2) f.write('\n') def main(): witness = (ROOT / 'witness-and-ruling-source.txt').read_text() assert '1794661806.338179' in witness and 'Witness conclusion: PASS' in witness for name, digest in SHA.items(): path = (OLD / 'custodian' if name.endswith('mapping.json') or name == 'pose-mapping-v1.json' else ROOT / 'frozen') / name assert sha(path) == digest, f'Changed input: {name}' mapping = json.loads((OLD / 'custodian/sampling-and-mapping.json').read_text()) rows = list(csv.DictReader((ROOT / 'frozen/frozen-review.csv').open())) blank = list(csv.DictReader((OLD / 'blind-package/blank-review.csv').open())) ids = [r['anonymous_pair_id'] for r in rows] assert len(ids) == len(set(ids)) == 120 assert ids == [r['anonymous_pair_id'] for r in blank] assert ids == [r['anonymous_pair_id'] for r in mapping['pairs']] assert set(rows[0]) == set(blank[0]) allowed = {'rigid', 'template', 'variant', 'unrelated', 'unresolved'} assert all(r['relation'].lower() in allowed and r['local_evidence'].strip() for r in rows) assert all(r['confirmed_relation'] is None and r['development_heldout_assignment'] is None for r in mapping['pairs']) joined = [] for source, judgment in zip(mapping['pairs'], rows): joined.append({**source, 'frozen_geometric_review': judgment, 'interpretation': 'Visual geometry judgment; not CAD ancestry or a numerical registration certificate', 'same_source_key_same_side': True}) custody = ROOT / 'custodian' custody.mkdir(mode=0o700, exist_ok=False) save(custody / 'joined-frozen-review.json', { 'witness_message_ts': '1794661806.338179', 'frozen_commit': 'd4da9d762fff04c918c88d63ab3191e2571d6547', 'input_sha256': SHA, 'pairs': joined, 'split_stream_consumed': False, 'split_policy': 'Earlier per-class certification path replaced by Claude 1794661802.418469; no split generated here', }) rigid = [r for r in joined if r['frozen_geometric_review']['relation'].lower() == 'rigid'] save(custody / 'rigid-calibration-inputs.json', { 'scope': 'Identity join only; calibration has not run', 'frozen_review_sha256': SHA['frozen-review.csv'], 'pairs': [{'anonymous_pair_id': r['anonymous_pair_id'], 'a': r['a'], 'b': r['b'], 'source_key': r['source_key'], 'exposure': r['source_cluster_state'], 'judgment': r['frozen_geometric_review']} for r in rigid], }) for path in custody.iterdir(): path.chmod(0o600) for name in ['sampling-and-mapping.json', 'pose-mapping-v1.json']: assert sha(OLD / 'custodian' / name) == SHA[name] public = ROOT / 'public' public.mkdir(exist_ok=True) result = { 'status': 'WITNESSED_FROZEN_REVIEW_JOINED_IN_CUSTODY', 'completed_utc': datetime.now(timezone.utc).isoformat(), 'witness_message_ts': '1794661806.338179', 'frozen_commit': 'd4da9d762fff04c918c88d63ab3191e2571d6547', 'pairs_joined': len(joined), 'source_keys': len({r['source_key'] for r in joined}), 'geometric_review_counts': dict(Counter(r['relation'].lower() for r in rows)), 'rigid_pairs': len(rigid), 'rigid_source_keys': len({r['source_key'] for r in rigid}), 'same_key_unresolved_already_same_side': sum(r['relation'].lower() == 'unresolved' for r in rows), 'input_sha256': SHA, 'joined_review_sha256': sha(custody / 'joined-frozen-review.json'), 'rigid_calibration_inputs_sha256': sha(custody / 'rigid-calibration-inputs.json'), 'original_seals_unchanged': True, 'mappings_sent_to_reviewer': False, 'split_stream_consumed': False, 'registration_or_calibration_run': False, 'per_class_miss_rate_budget': {k: 'NOT_VERIFIABLE' for k in ['rigid', 'template', 'variant']}, 'limitations': '2/120 is this sample visual rigid count, not ancestry prevalence or a cross-key recall bound. Unresolved is not negative.', } save(public / 'custody-join-receipt.json', result) print(json.dumps(result, ensure_ascii=False, indent=2)) if __name__ == '__main__': main()