"""Metadata-only O1 contract creation after synthetic acceptance; never launch.""" import argparse import json from pathlib import Path import time from o1_partition import sha, checked, InputViolation from o1_prepare import read from s2_recovery_supervisor import save CODE=['o1_partition.py','o1_prepare.py','run_o1_prepare.py','prepare_o1_queue.py', 'test_o1_partition.py','test_o1_preparation.py','o1_determinism_probe.py','audit_samples.py','gre24_features.py', 'boundary_distance.py','r4bc_guard.py','s2_recovery_supervisor.py','s2_recovery_monitoring.py'] def prepare(root): start=time.process_time() if root.exists():raise FileExistsError('Existing O1 execution root; inspect instead of replacing') planpath=Path('artifacts/o1-planning-2026-11-17/contract-plan.json');plan=read(planpath) checked(plan['authoritative_contract'],plan['contract_sha256']) sources=dict(plan['sources_sha256']);sources[str(planpath)]=sha(planpath) sources[plan['authoritative_contract']]=plan['contract_sha256'] for p,h in sources.items():checked(p,h) roster=read('artifacts/s2-main-preparation-2026-11-15/final-roster.json') successful=read('artifacts/gre24-reproduction-2026-11-15/v5-models-continuation-2026-11-16/preparation-freeze.json')['successful'] original=Path('artifacts/gre24-reproduction-2026-11-15/v5-protocol/contract.json') sources[str(original)]=sha(original);archive=read(original) parts=[];metadata_cpu=[] for r in sorted((r for r in roster['parts'] if r['included']),key=lambda r:int(r['case'].split('_',1)[0])): row=dict(r); row['numeric_case']=int(row['case'].split('_',1)[0]);p=row['preparation'] resultpath=Path(p['preparation_root'])/'result.json';old=read(checked(resultpath,p['result_sha256'])) row['tets']=old['tets']; row['v5_cache']=successful.get(row['case']) row['metadata_failure']=None if row['v5_cache'] else 'PREEXISTING_V5_FULL_FEATURE_UNAVAILABLE' parts.append(row) if len(parts)!=617 or len({p['component_id'] for p in parts})!=209 or len({p['numeric_case'] for p in parts})!=617: raise InputViolation('Original roster identity changed') receipts=sorted(Path('artifacts/o1-acceptance-2026-11-17').glob('attempt-*/worker.receipt.json')) acceptance=[dict(path=str(p),sha256=sha(p),**read(p)) for p in receipts] if not acceptance or acceptance[-1]['status']!='PASS':raise ValueError('No final synthetic acceptance') accepted=read(receipts[-1].parent/'accepted-source.json') for p,h in accepted.items():checked(p,h) code={str(Path('tools')/n):sha(Path('tools')/n) for n in CODE} if accepted!=code:raise ValueError('Accepted source manifest incomplete') spent=60+sum(a['cpu_seconds'] for a in acceptance) if time.process_time()-start>60:raise ValueError('Metadata engineering reserve exceeded') dispatch=[i for i,p in enumerate(parts) if not p['metadata_failure']] c=dict(version='O1-GEOMETRY-PREPARATION-v1',parts=parts,dispatch=dispatch,first_ten=dispatch[:10], source_sha256=sources,code_sha256=code,archive=archive['archive'],archive_stat=archive['archive_stat'], main_review=['1794860233.507079','1794861463.486809'],contract_commit='7f820b76ea6d64b3a9f8a595bc04c8434ec00ae9', worker_cpus=[0,2,4,6],coordinator_cpu=1,limits=plan['limits'], part_limits=dict(cpu_seconds=1800,wall_seconds=1800,rss_bytes=8*2**30,disk_bytes=100*2**30), initial_preparation_cpu_seconds=spent,acceptance=acceptance, prepared_without_label_values=True,fit_launch=False) root.mkdir(parents=True) save(root/'contract.json',c) save(root/'prepared.json',dict(status='READY_FOR_GEOMETRY_PREPARATION_NO_FITS',parts=617,dispatch=len(dispatch), metadata_excluded=617-len(dispatch),contract_sha256=sha(root/'contract.json'), initial_preparation_cpu_seconds=spent,metadata_cpu_seconds_within_60_reserve=time.process_time()-start)) print(str(root),sha(root/'contract.json')) if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('root',type=Path);a=p.parse_args();prepare(a.root)