"""Supervise five concurrent Inspect tasks and one bounded operational retry pass.""" import subprocess,time,sys from pathlib import Path from inspect_ai.log import read_eval_log,read_eval_log_sample_summaries from encoding_tax.common import ROOT,now,write_json,digest,read_json,GateError from .design import require_extension BASE=ROOT/'results/e6-exploratory-v2/pilot' STATUS=BASE/'status.json' def supervise(commands,phase): children=[subprocess.Popen(cmd,cwd=ROOT) for cmd in commands] started=time.time() try: while any(p.poll() is None for p in children): newest=max([started]+[p.stat().st_mtime for folder,pat in [('transport','*.json'),('inspect','*.eval')] for p in (BASE/folder).glob(pat)]) idle=time.time()-newest write_json(STATUS,{'updated_at':now(),'status':'running','phase':phase,'pids':[p.pid for p in children if p.poll() is None],'seconds_without_recorded_progress':round(idle),'watchdog_seconds':900}) if idle>900:raise RuntimeError('No request/log progress for 15 minutes') time.sleep(20) if any(p.returncode for p in children):raise RuntimeError(f'Inspect subprocess exits: {[p.returncode for p in children]}') finally: for p in children: if p.poll() is None:p.terminate() for p in children: try:p.wait(timeout=10) except subprocess.TimeoutExpired:p.kill();p.wait() def latest(): result={} for p in sorted((BASE/'inspect').glob('*.eval')): h=read_eval_log(p,header_only=True);result[h.eval.model]=(p,h) return result def main(): require_extension() canary=read_json(ROOT/'results/e6-exploratory-v2/canary/receipt.json') if not canary.get('passed') or canary.get('freeze_sha256')!=digest(ROOT/'extensions/e6_exploratory_v2/freeze.json'): raise GateError('Matching live format canary required before pilot launch') BASE.mkdir(parents=True,exist_ok=True) write_json(BASE/'launch.json',{'started_at':now(),'freeze_sha256':digest(ROOT/'extensions/e6_exploratory_v2/freeze.json'),'samples':9120,'concurrency_per_reader':16,'automatic_full_run':False}) try: supervise([[str(ROOT/'.venv/bin/inspect'),'eval-set','extensions/e6_exploratory_v2/tasks.py','--max-connections','16','--max-samples','80','--max-tasks','5','--max-retries','0','--retry-attempts','1','--no-retry-cleanup','--log-dir',str(BASE/'inspect')]],'pilot_collection') retries=[];decisions=[] allowed=('429','500 Internal','502','503','504','raw completion JSON','upstream serialization','Native/provider prompt counts','ConnectError','ReadTimeout','RemoteProtocolError') for model,(path,h) in latest().items(): failed=[s for s in read_eval_log_sample_summaries(path) if s.error] if failed and all(any(t in str(s.error) for t in allowed) for s in failed): decisions.append({'model':model,'original_log':str(path.relative_to(ROOT)),'sha256':digest(path),'samples':[{'id':s.id,'error':str(s.error)} for s in failed]}) retries.append([str(ROOT/'.venv/bin/python'),'-c','from encoding_tax.common import setup_environment; setup_environment(); import extensions.e6_exploratory_v2.provider; from inspect_ai._cli.main import main; main()','eval-retry',str(path),'--max-connections','16','--max-samples','16','--max-retries','0','--log-dir',str(BASE/'inspect')]) write_json(BASE/'retry-decisions.json',{'recorded_at':now(),'policy':'One operational retry pass; all gates unchanged; no malformed or wrong model output resampled','decisions':decisions}) if retries:supervise(retries,'operational_retries') logs=latest();remaining=sum(h.results.total_samples-h.results.completed_samples if h.results else 1824 for _,h in logs.values()) if len(logs)!=5 or remaining:raise RuntimeError(f'Unresolved samples: {remaining}; model logs: {len(logs)}') write_json(STATUS,{'updated_at':now(),'status':'running','phase':'descriptive_analysis'}) from .analyze import main as analyze analyze() write_json(STATUS,{'updated_at':now(),'status':'pilot_complete','samples':9120,'next':'Review pilot before choosing a larger or 4096-token run'}) except BaseException as exc: write_json(STATUS,{'updated_at':now(),'status':'needs_review','error':str(exc)}) raise if __name__=='__main__':main()