Files
myfileagent-pipeline/ci/run_live_review.py
T
Codex 9275fcdcae
myfileagent-python-ci/pipeline/head This commit looks good
Final project review (live) / review (push) Failing after 1m24s
Integrate real reviewer with measured Actions execution and live Jenkins pipeline
2026-11-27 19:08:59 +00:00

46 lines
2.6 KiB
Python

"""Run the pinned reviewer inside the actual capped Actions job and retain measurements."""
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
root = Path(__file__).resolve().parents[1]
lock_bytes = (root/'reviewer/model-lock.json').read_bytes()
lock = json.loads(lock_bytes)
runtime = root/'out/runtime'
cgroup = Path('/sys/fs/cgroup')
limit = int((cgroup/'memory.max').read_text())
assert limit == 250000000, 'Actual Actions container must have the exact 250 MB limit'
assert (cgroup/'memory.swap.max').read_text().strip() == '0', 'Swap must be disabled'
assert not os.environ.get('REVIEWER_BACKEND_COMMAND'), 'Fixture override is forbidden'
private = Path('/private-model')/lock['quantized_filename']
assert private.is_file(), 'Model must be downloaded into private tmpfs'
library = runtime/'libgomp-root'/lock['libgomp_library_path']
assert hashlib.sha256(library.read_bytes()).hexdigest() == lock['libgomp_library_sha256']
env = os.environ.copy()
env.update(REVIEWER_MODEL_PATH=str(private),
REVIEWER_LLAMA_COMPLETION=str(runtime/f"llama-{lock['runtime_tag']}"/lock['entrypoint']),
LD_LIBRARY_PATH=str(library.parent)+':'+str(runtime/f"llama-{lock['runtime_tag']}"))
result = subprocess.run([sys.executable,'-m','reviewer','--input','tests/fixtures/demo_broken.py',
'--source-commit',env['SOURCE_SHA'],'--out-dir','out/review'],cwd=root,env=env)
peak = int((cgroup/'memory.peak').read_text())
events = {k:int(v) for k,v in (line.split() for line in (cgroup/'memory.events').read_text().splitlines())}
measurement = dict(scope='actual Actions job including runtime preparation, reviewer and private tmpfs model',
memory_limit_bytes=limit,memory_peak_bytes=peak,memory_events=events,
swap_limit_bytes=0,reviewer_exit_code=result.returncode)
Path('out').mkdir(exist_ok=True)
Path('out/resource.json').write_text(json.dumps(measurement,indent=2)+'\n')
print(json.dumps(measurement))
assert result.returncode == 0 and events['oom_kill'] == 0 and peak <= limit, 'Live acceptance gate failed'
p=Path('out/review/review.json');data=json.loads(p.read_text())
assert data['mode']=='live' and data['status']=='corrected'
data['resource_measurement']=measurement
data['model_lock_sha256']=hashlib.sha256(lock_bytes).hexdigest()
data['raw_response']=(p.parent/'raw_response.txt').read_text()
data['runtime_response']=json.loads((p.parent/'runtime_response.json').read_text())
p.write_text(json.dumps(data,indent=2)+'\n')
subprocess.run([sys.executable,'tests/smoke_demo.py',str(p.parent/'reviewed.py')],check=True)