"""New pipeline experiment process receipts, with exclusive output and no retries.""" import argparse from datetime import datetime, timezone import json import os from pathlib import Path import re import shutil import subprocess import time ROOT = Path('/home/qishizhe/phase4ar-pipeline-acceleration-20261001') p = argparse.ArgumentParser() p.add_argument('--label', required=True) p.add_argument('--timeout', type=int, default=900) p.add_argument('command', nargs=argparse.REMAINDER) a = p.parse_args() assert re.fullmatch(r'[a-z0-9-]+', a.label) and a.command and 0 < a.timeout <= 1800 assert ROOT.is_dir() and not ROOT.is_symlink() assert shutil.disk_usage(ROOT).free >= 100 * (1 << 30) out = ROOT / 'jobs' out.mkdir(exist_ok=True) start = time.perf_counter() record = dict(label=a.label, command=a.command, scope='independent engineering replay only', started_utc=datetime.now(timezone.utc).isoformat(), scientific_AR_resumed=False) with (out / (a.label + '.start.json')).open('x') as f: json.dump(record, f, indent=2) with (out / (a.label + '.stdout.log')).open('x') as stdout, (out / (a.label + '.stderr.log')).open('x') as stderr: try: proc = subprocess.run(a.command, stdout=stdout, stderr=stderr, timeout=a.timeout, env={**os.environ, 'PYTHONDONTWRITEBYTECODE':'1'}) record.update(exit_code=proc.returncode, observed_exit=True, timed_out=False) except subprocess.TimeoutExpired: record.update(exit_code=None, observed_exit=False, timed_out=True) except OSError as error: record.update(exit_code=None, observed_exit=False, timed_out=False, launch_error=str(error)) record.update(wall_seconds=time.perf_counter()-start, finished_utc=datetime.now(timezone.utc).isoformat()) with (out / (a.label + '.exit.json')).open('x') as f: json.dump(record, f, indent=2) print(json.dumps(record), flush=True) raise SystemExit(record['exit_code'] if record['observed_exit'] else 124)