Files
MeltMind/tools/phase2_b1213_serial.py

46 lines
2.4 KiB
Python

"""Claude1794896825: exactly one B12 then one B13, no B1 dependency."""
import fcntl
import json
import os
from pathlib import Path
import subprocess
import sys
import time
import psutil
from phase2_h1_worker_v2 import save,sha,checked
BASE=Path('/home/frank14f/optane/MeltMind')
ROOT=BASE/'artifacts/phase2-b1213-serial-2026-11-17'
def read(p):return json.loads(Path(p).read_text())
def live(root):
return [p.pid for p in psutil.process_iter(['pid','cmdline'])
if p.pid!=os.getpid() and str(root) in (p.info['cmdline'] or [])]
def run():
c=read(ROOT/'contract.json')
for p,h in c['source_sha256'].items():checked(BASE/p,h)
os.sched_setaffinity(0,[24]);start=time.process_time()
with (ROOT/'run.lock').open('a') as lock:
fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
if (ROOT/'started.json').exists():raise FileExistsError('Unique chain already attempted')
save(ROOT/'started.json',dict(pid=os.getpid(),unix=time.time(),contract_sha256=sha(ROOT/'contract.json')))
results=[]
try:
for name in ['phase2-b12-gate-2026-11-17','phase2-b13-gate-2026-11-17']:
root=BASE/'artifacts'/name
for p,h in c['source_sha256'].items():checked(BASE/p,h)
if live(root) or (root/'started.json').exists():raise RuntimeError('Gate already attempted; no duplicate')
save(ROOT/'live-progress.json',dict(stage='RUN_'+name,unix=time.time(),coordinator_cpu_seconds=time.process_time()-start))
with (ROOT/(name+'.log')).open('x') as log:
child=subprocess.run([sys.executable,'tools/phase2_b1213_gate.py','run',str(root)],stdout=log,stderr=subprocess.STDOUT)
if not (root/'complete.json').exists() or live(root):raise RuntimeError('Missing terminal or live children')
result=read(root/'complete.json');results.append(dict(gate=name,returncode=child.returncode,complete_sha256=sha(root/'complete.json'),status=result['status']))
save(ROOT/'gate-terminals.json',results)
save(ROOT/'complete.json',dict(status='BOTH_GATES_TERMINAL',results=results,coordinator_cpu_seconds=time.process_time()-start,retry=False))
except BaseException as exc:
save(ROOT/'complete.json',dict(status='STOPPED',reason=type(exc).__name__+': '+str(exc),results=results,coordinator_cpu_seconds=time.process_time()-start,retry=False));raise
if __name__=='__main__':run()