"""Freeze the approved 131 geometry-only attempts; preserve the old 493 successes.""" import csv import json from pathlib import Path from freeze_g1_components import sha from s2_recovery_supervisor import save ROOT = Path('artifacts/s2-main-preparation-2026-11-15') PLAN = Path('artifacts/s2-main-engineering-2026-11-15/planned-preparation-131.json') SPLITS = Path('artifacts/s2-g1-components-2026-11-15/custodian/part-splits.json') OLD = Path('artifacts/s2-pilot-inputs-2026-11-15/contract.json') MERGED = Path('artifacts/s2-preparation-incident-2026-11-15/merged-recovery-terminal.json') SUCCESS = Path('artifacts/s2-pilot-training-2026-11-15/success-manifest.json') def read(path): return json.loads(Path(path).read_text()) def main(): assert not ROOT.exists(), 'Never overwrite an existing attempt' plan=read(PLAN);old=read(OLD);merged=read(MERGED);success=read(SUCCESS) parts={p['case']:p for p in read(SPLITS)} prior={p['case']:p for p in old['cases']} failed={p['case'] for p in merged['jobs'] if p['worker']['status']!='PASS'} passed={p['case'] for p in success['ready_parts']} expected=failed | {k for k,p in parts.items() if p['assignments'][0]['role']=='test'} assert len(parts)==624 and len(failed)==6 and len(passed)==493 assert len(plan['jobs'])==131 and {p['case'] for p in plan['jobs']}==expected assert not expected & passed and expected | passed == set(parts) g1=read('artifacts/s2-g1-registration-2026-11-14/custodian/plan.json')['geometry_cache'] settings_path=Path('artifacts/s2-e1-2026-11-14/log-flow-setting-check/fill-time-setting-context.json') settings={p['member'].removesuffix('.log'):p for p in read(settings_path)} counts={p['case']:p for p in csv.DictReader(open('artifacts/s2-e1-2026-11-14/preflight/geometry_counts.csv'))} cases=[] for job in plan['jobs']: case=job['case'];p=parts[case] assert job['decode_labels'] is False and job['retries']==0 assert job['nodes']==p['nodes'] and job['component_id']==p['component_id'] assert job['wall_limit_seconds']==(3600 if case in failed else 1800) if case in failed: spec=json.loads(json.dumps(prior[case])) assert not any(k in spec for k in ['reuse_preparation','prior_failed_preparation']) else: setting=settings[case] spec=dict(case=case,numeric_prefix=int(case.split('_')[0]),source_key=p['source_key'], component_id=p['component_id'],tet_nodes=p['nodes'],tet_cells=int(counts[case]['tet_cells']), t_set=setting['setting']['seconds'],t_set_provenance=setting,g1_geometry=g1[case]['path'], input_sha256={g1[case]['path']:g1[case]['sha256'],str(settings_path):sha(settings_path)}) cache=Path('artifacts/s1-panel-precheck-2026-11-14')/case if (cache/'result.json').exists(): r=read(cache/'result.json');assert r['status']=='COUNT_COMPLETE' spec.update(legacy_geometry=str(cache/'geometry.npz'),existing_distance=str(cache/'boundary_distance_raw.npy')) for name in ['geometry.npz','boundary_distance_raw.npy']: spec['input_sha256'][str(cache/name)]=r['output_sha256'][name] draw=Path('artifacts/s1-sampled-draw-2026-11-14')/case/'draw.npz' if draw.exists(): r=read(draw.parent/'receipt.json');assert r['status']=='DRAW_COMPLETE' spec['existing_primary_draw']=str(draw);spec['input_sha256'][str(draw)]=r['output_sha256']['draw.npz'] o2=Path('artifacts/s1-sampled-o2-2026-11-14/panel')/(case+'_original') if (o2/'result.json').exists(): r=read(o2/'result.json');assert r['status']=='COMPLETE' spec.update(existing_sampled_o2_nodes=str(o2/'nodes.npz'),existing_sampled_o2_result=str(o2/'result.json')) spec['input_sha256'][str(o2/'nodes.npz')]=r['output_sha256']['nodes.npz'] spec['input_sha256'][str(o2/'result.json')]=sha(o2/'result.json') spec.update(attempt=job) for path,digest in spec['input_sha256'].items():assert sha(path)==digest,path cases.append(spec) # Only hash geometry/features; neither open nor decode any labels.npz. reused=[] for row in success['ready_parts']: source=Path(row['preparation_root']);r=read(source/'result.json') assert r['status']=='COMPLETE' and r['label_arrays_decoded']==[] assert r['case']==row['case'] and r['nodes']==parts[row['case']]['nodes'] for name,digest in r['output_sha256'].items(): assert 'label' not in name and sha(source/name)==digest,(source,name) reused.append(dict(case=row['case'],preparation_root=str(source), result_sha256=sha(source/'result.json'),output_sha256=r['output_sha256'])) base=read('artifacts/s2-ten-part-measurement-2026-11-15/contract.json') for path,digest in old['code_sha256'].items():assert sha(path)==digest,path paths=set(old['code_sha256']) | {'tools/prepare_s2_main_inputs.py','tools/run_s2_main_preparation.py', 'tools/freeze_s2_main_roster.py','tools/test_s2_main_preparation.py','tools/s2_main_prepare.py', 'tools/s2_recovery_monitoring.py','tools/s2_recovery_supervisor.py'} sources={str(p):sha(p) for p in [PLAN,SPLITS,OLD,MERGED,SUCCESS,settings_path]} ROOT.mkdir() save(ROOT/'reuse-493.json',dict(status='VERIFIED_GEOMETRY_FEATURES_ONLY',parts=reused,labels_decoded=False)) sources[str(ROOT/'reuse-493.json')]=sha(ROOT/'reuse-493.json') c={k:base[k] for k in ['fixed_split_commit','archive','archive_stat','scales','draw','eligibility']} c.update(version='S2-main-131-label-free-v1',authorizing_rulings=['1794698734.967459','1794699027.366469'], cases=cases,code_sha256={p:sha(p) for p in sorted(paths)},source_sha256=sources, prior_worker_cpu_seconds=merged['worker_cpu_seconds'], limits=dict(worker_cpu_hours=20,workers=16,disk_bytes=100*2**30,per_part_tree_rss_bytes=1342177280,retries=0), budget_roots=['artifacts/s2-ten-part-measurement-2026-11-15','artifacts/s2-pilot-inputs-2026-11-15', 'artifacts/s2-preparation-incident-2026-11-15','artifacts/s2-pilot-recovery-inputs-2026-11-15',str(ROOT)], input_policy='Geometry/features only for all 131; no labels decoded, no fit, no GPU. Original 493 reused without label reads.', accounting='20 additional worker CPU-h; historical CPU recorded separately; live guard CPU conservatively included in cap.', failure_policy='One labelled new attempt per planned case; no retry. Retain prior failures. Remaining failures excluded globally across all five folds with original component identity.', dispatch='Frozen plan order, at most16; no first50 gate; freeze roster only after all131 terminal within approved budget.') save(ROOT/'contract.json',c) print(json.dumps(dict(status='FROZEN_NOT_STARTED',root=str(ROOT),contract_sha256=sha(ROOT/'contract.json'), cases=len(cases),reused=len(reused),labels_decoded=False))) if __name__=='__main__':main()