2026-03-21 07:37:59 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import json
|
2026-03-21 07:55:21 +00:00
|
|
|
import os
|
|
|
|
|
import signal
|
2026-03-21 07:37:59 +00:00
|
|
|
import subprocess
|
2026-03-21 07:55:21 +00:00
|
|
|
from datetime import datetime, timezone
|
2026-03-21 07:37:59 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
ROOT = Path('/home/openclaw/.openclaw/workspace')
|
|
|
|
|
CONFIG = ROOT / 'configs' / 'sacred_eval_gate.json'
|
|
|
|
|
RESULT = ROOT / 'evals' / 'results' / 'regression_results.json'
|
|
|
|
|
RUNNER = ROOT / 'evals' / 'run_regression.py'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_config() -> dict:
|
|
|
|
|
try:
|
|
|
|
|
return json.loads(CONFIG.read_text(encoding='utf-8'))
|
|
|
|
|
except Exception:
|
|
|
|
|
return {
|
|
|
|
|
'min_route_accuracy_percent': 95.0,
|
|
|
|
|
'min_memory_signal_accuracy_percent': 90.0,
|
|
|
|
|
'max_timeouts': 0,
|
|
|
|
|
'require_pass': True,
|
2026-03-21 07:55:21 +00:00
|
|
|
'runner_timeout_seconds': 90,
|
2026-03-21 07:49:32 +00:00
|
|
|
'runner_start': 0,
|
2026-03-21 07:55:21 +00:00
|
|
|
'runner_limit': 5,
|
|
|
|
|
'runner_per_case_timeout': 8,
|
|
|
|
|
'runner_progress_every': 5,
|
2026-03-21 07:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-03-21 07:55:21 +00:00
|
|
|
def gate_output_path() -> Path:
|
|
|
|
|
ts = datetime.now(timezone.utc).strftime('%Y%m%dT%H%M%SZ')
|
|
|
|
|
return ROOT / 'evals' / 'results' / f'sacred_gate_{ts}.json'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_regression(cfg: dict) -> tuple[int, str, str, Path]:
|
|
|
|
|
output = gate_output_path()
|
|
|
|
|
cmd = ['python3', str(RUNNER), '--output', str(output)]
|
2026-03-21 07:49:32 +00:00
|
|
|
start = cfg.get('runner_start', None)
|
|
|
|
|
limit = cfg.get('runner_limit', None)
|
2026-03-21 07:55:21 +00:00
|
|
|
per_case = cfg.get('runner_per_case_timeout', None)
|
|
|
|
|
progress = cfg.get('runner_progress_every', None)
|
2026-03-21 07:49:32 +00:00
|
|
|
if start is not None:
|
|
|
|
|
cmd.extend(['--start', str(start)])
|
|
|
|
|
if limit is not None:
|
|
|
|
|
cmd.extend(['--limit', str(limit)])
|
2026-03-21 07:55:21 +00:00
|
|
|
if per_case is not None:
|
|
|
|
|
cmd.extend(['--per-case-timeout', str(per_case)])
|
|
|
|
|
if progress is not None:
|
|
|
|
|
cmd.extend(['--progress-every', str(progress)])
|
|
|
|
|
proc = subprocess.Popen(
|
2026-03-21 07:49:32 +00:00
|
|
|
cmd,
|
2026-03-21 07:55:21 +00:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
|
stderr=subprocess.PIPE,
|
2026-03-21 07:49:32 +00:00
|
|
|
text=True,
|
2026-03-21 07:55:21 +00:00
|
|
|
start_new_session=True,
|
2026-03-21 07:49:32 +00:00
|
|
|
)
|
2026-03-21 07:55:21 +00:00
|
|
|
try:
|
|
|
|
|
stdout, stderr = proc.communicate(timeout=int(cfg.get('runner_timeout_seconds', 90) or 90))
|
|
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
|
try:
|
|
|
|
|
os.killpg(proc.pid, signal.SIGTERM)
|
|
|
|
|
except Exception:
|
|
|
|
|
proc.kill()
|
|
|
|
|
raise
|
|
|
|
|
return proc.returncode, stdout, stderr, output
|
2026-03-21 07:37:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> int:
|
|
|
|
|
cfg = load_config()
|
2026-03-21 07:49:32 +00:00
|
|
|
try:
|
2026-03-21 07:55:21 +00:00
|
|
|
rc, stdout, stderr, output_path = run_regression(cfg)
|
2026-03-21 07:49:32 +00:00
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
|
print(json.dumps({'ok': False, 'decision': 'hold', 'reason': 'runner_timeout'}, ensure_ascii=False))
|
|
|
|
|
return 1
|
2026-03-21 07:37:59 +00:00
|
|
|
if rc != 0:
|
2026-03-21 07:49:32 +00:00
|
|
|
print(json.dumps({'ok': False, 'decision': 'hold', 'reason': 'runner_failed', 'runner_rc': rc, 'stderr': (stderr or '')[:300]}, ensure_ascii=False))
|
2026-03-21 07:37:59 +00:00
|
|
|
return 1
|
2026-03-21 07:55:21 +00:00
|
|
|
result_path = output_path if output_path.exists() else RESULT
|
|
|
|
|
data = json.loads(result_path.read_text(encoding='utf-8'))
|
2026-03-21 07:37:59 +00:00
|
|
|
route = float(data.get('route_accuracy_percent', 0.0) or 0.0)
|
|
|
|
|
memory = float(data.get('memory_signal_accuracy_percent', 0.0) or 0.0)
|
|
|
|
|
timeouts = int(data.get('timeouts', 0) or 0)
|
|
|
|
|
passed = bool(data.get('pass'))
|
|
|
|
|
ok = True
|
|
|
|
|
reasons = []
|
|
|
|
|
if route < float(cfg.get('min_route_accuracy_percent', 95.0)):
|
|
|
|
|
ok = False
|
|
|
|
|
reasons.append('route_accuracy_below_threshold')
|
|
|
|
|
if memory < float(cfg.get('min_memory_signal_accuracy_percent', 90.0)):
|
|
|
|
|
ok = False
|
|
|
|
|
reasons.append('memory_accuracy_below_threshold')
|
|
|
|
|
if timeouts > int(cfg.get('max_timeouts', 0)):
|
|
|
|
|
ok = False
|
|
|
|
|
reasons.append('timeouts_above_threshold')
|
|
|
|
|
if bool(cfg.get('require_pass', True)) and not passed:
|
|
|
|
|
ok = False
|
|
|
|
|
reasons.append('regression_not_pass')
|
|
|
|
|
print(json.dumps({
|
|
|
|
|
'ok': ok,
|
|
|
|
|
'decision': 'promote' if ok else 'hold',
|
|
|
|
|
'reasons': reasons,
|
|
|
|
|
'route_accuracy_percent': route,
|
|
|
|
|
'memory_signal_accuracy_percent': memory,
|
|
|
|
|
'timeouts': timeouts,
|
|
|
|
|
'pass': passed,
|
2026-03-21 07:55:21 +00:00
|
|
|
'result_path': str(result_path),
|
2026-03-21 07:37:59 +00:00
|
|
|
}, ensure_ascii=False))
|
|
|
|
|
return 0 if ok else 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
raise SystemExit(main())
|