"""Validate original or merged preparation terminal evidence without rerunning it.""" import argparse import json import os from pathlib import Path from freeze_g1_components import sha from s2_e1_supervisor import disk_usage def continuation_allowed(source,batch): if batch['status']!='STOPPED' or batch.get('stop_reason')!='FIRST_50_PROJECTION_OVER_CAP':return False checkpoint=json.loads((source/'first-50-checkpoint.json').read_text()) return (60*3600=0 assert job['worker']['status']!='GUARD_FAILED_ACCOUNTING_UNKNOWN' jobs.append(dict(job,index=original_cases[case],source_index=job['index'],ready_source_root=str(root))) assert seen==set(original_cases) and len(jobs)==499 cpu=sum(r['worker']['cpu_seconds'] for r in jobs);used=sum(disk_usage(root) for root in roots) assert cpu<=80*3600 and used<=100*2**30,'Merged budget exceeded' return dict(status='ATTEMPTS_COMPLETE',stop_reason=None,not_run_indices=[],jobs=sorted(jobs,key=lambda r:r['index']), worker_cpu_seconds=cpu,guard_cpu_seconds=sum(b['guard_cpu_seconds'] for b in batches), failed=sum(r['worker']['status']!='PASS' for r in jobs),disk_bytes=used, source_provenance=proof,continuation_ruling='1794683049.057259',retry=False,replacement=False,test_labels_read=False) def terminal_batch(source): merged=source/'merged-terminal.json' if not merged.exists(): path=source/'batch-complete.json';return json.loads(path.read_text()),path m=json.loads(merged.read_text());proof=m['source_provenance'] batch=combine(source,Path(proof[1]['root']),proof) assert batch['jobs']==m['jobs'] and batch['worker_cpu_seconds']==m['worker_cpu_seconds'] return batch,merged def merge(source,continuation): proof=[dict(root=str(root),contract_sha256=sha(root/'contract.json'),batch_sha256=sha(root/'batch-complete.json')) for root in [source,continuation]] batch=combine(source,continuation,proof) pending=source/'merged-terminal.json.pending' with pending.open('x') as f:json.dump(batch,f,indent=2);f.write('\n');f.flush();os.fsync(f.fileno()) # The waiting entry sees either no merged manifest or the complete file. # link creates the final name atomically and refuses an existing manifest. os.link(pending,source/'merged-terminal.json');pending.unlink() return batch if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('source',type=Path);p.add_argument('continuation',type=Path);a=p.parse_args();r=merge(a.source,a.continuation) print(json.dumps(dict(status=r['status'],terminal=len(r['jobs']),failed=r['failed'],worker_cpu_seconds=r['worker_cpu_seconds'])))