"""Freeze the approved scientific-v2 panel and cumulative ledger; never launch.""" import argparse import copy from pathlib import Path import time from o1_partition import checked, sha, InputViolation from o1_prepare import read, contract from run_o1_v2 import validate_runtime_contract from s2_recovery_supervisor import save OLD = Path('artifacts/o1-preparation-continuation-2026-11-17') SPEC = Path('references/2026-11-17/o1/mold-o1-v2-geometric-spec.md') SPEC_SHA = '632688217e59dd134922245e524ff1c0f63933be64600be21379f7aa74947a5f' COMPLETE_SHA = '4640e3a6c38072a9c04829f906bf003e5556705b0392502044541336239b7be8' TESTED = ['o1_v2.py', 'o1_v2_prepare.py', 'run_o1_v2.py', 'test_o1_v2.py'] def prepare(root): start = time.process_time() if root.exists(): raise FileExistsError('Existing scientific-v2 root; inspect, never replace') old = contract(OLD) done = read(checked(OLD/'complete.json', COMPLETE_SHA)) checked(SPEC, SPEC_SHA) ledger = read(OLD/'final-cost-ledger.json') records = {r['index']: r for r in done['records']} if len(records) != 60 or len(done['records']) != 60 or not done['accounting_complete']: raise InputViolation('Original sixty receipt identity/accounting') panel = [i for i in old['dispatch'] if i in records] if len(panel) != 60: raise InputViolation('Original attempted indices outside dispatch') manifest = [] for i in panel: r = records[i]; row = old['parts'][i] guard = OLD/'parts'/row['case']/'guard-result.json' if read(guard) != r: raise InputViolation('Original guard differs from terminal receipt') result = read(checked(r['result_path'], r['result_sha256'])) if r['result_path'] else None manifest.append(dict(index=i, case=row['case'], component_id=row['component_id'], original_worker_status=r['worker']['status'], original_stop_reason=r['worker']['stop_reason'], original_scientific_status=result['status'] if result else None, original_guard_path=str(guard), original_guard_sha256=sha(guard), original_result_sha256=r['result_sha256'])) acceptance_paths = sorted(Path('artifacts/o1-v2-acceptance-2026-11-17').glob('attempt-*/worker.receipt.json')) acceptance = [dict(path=str(p), sha256=sha(p), **read(p)) for p in acceptance_paths] if not acceptance or acceptance[-1]['status'] != 'PASS': raise InputViolation('No accepted synthetic run') test_start = read(acceptance_paths[-1].parent/'worker.started.json')['unix'] tested = {str(Path('tools')/n): sha(Path('tools')/n) for n in TESTED} if any(Path(p).stat().st_mtime > test_start for p in tested): raise InputViolation('Scientific source changed after accepted synthetic start') # Existing imported scientific/guard code is checked against the immutable v1 contract. code = dict(old['code_sha256']); code.update(tested) code['tools/prepare_o1_v2.py'] = sha('tools/prepare_o1_v2.py') sources = dict(old['source_sha256']) for path in [OLD/'contract.json', OLD/'complete.json', OLD/'final-cost-ledger.json', SPEC]: sources[str(path)] = sha(path) # A bounded five-second metadata reserve is charged once, inside the same 12 h ledger. prior = ledger['cumulative_preparation_cpu_seconds'] synthetic = sum(a['cpu_seconds'] for a in acceptance) initial = prior + synthetic + 5. c = copy.deepcopy(old) c.pop('first_ten', None) c.update(version='O1-SCIENTIFIC-v2-AREA-RANK', panel_indices=panel, dispatch=panel+[i for i in old['dispatch'] if i not in records], scientific_spec_sha256=SPEC_SHA, source_sha256=sources, code_sha256=code, main_review=['1794863409.977129'], prior_reviews=old['main_review'], initial_preparation_cpu_seconds=initial, acceptance=acceptance, prior_preparation_cpu_seconds=prior, metadata_reserve_cpu_seconds=5., panel_original_complete_sha256=COMPLETE_SHA, labels_read=False, fit_launch=False) validate_runtime_contract(c) if len(c['parts']) != 617 or len({p['component_id'] for p in c['parts']}) != 209: raise InputViolation('Full domain changed') if time.process_time()-start > 5: raise InputViolation('Metadata reserve exceeded before freeze') root.mkdir(parents=True) save(root/'panel-manifest.json', dict(parts=manifest, order='original dispatch', original_complete_sha256=COMPLETE_SHA, original_count=60, substitutions=0)) c['source_sha256'][str(root/'panel-manifest.json')] = sha(root/'panel-manifest.json') save(root/'accepted-source.json', dict(tested_sources=tested, acceptance=acceptance, provenance='Unchanged source mtimes precede accepted synthetic worker start; immutable imported sources checked')) save(root/'contract.json', c) save(root/'prepared.json', dict(status='FROZEN_NOT_LAUNCHED', contract_sha256=sha(root/'contract.json'), panel=60, dispatch=len(c['dispatch']), original_parts=617, original_components=209, prior_preparation_cpu_seconds=prior, synthetic_cpu_seconds=synthetic, metadata_reserve_cpu_seconds=5., metadata_actual_cpu_seconds=time.process_time()-start, initial_preparation_cpu_seconds=initial, labels_read=False, fits_started=False)) print(read(root/'prepared.json')) if __name__ == '__main__': p=argparse.ArgumentParser(); p.add_argument('root',type=Path) prepare(p.parse_args().root)