"""Acceptance grader for bench test fixture FT-2. Runs /app/controller.py through the gauntlet on the hidden episodes, with this directory's own copies of the gauntlet, task.py, scoring.py, the scene and the robot model. The controller runs in a separate, unprivileged process (gauntlet/harness.py, the same module run_gauntlet.py uses): it receives each observation pickled by this side and answers with raw float64 bytes or a small JSON status object, so nothing from the controller is ever unpickled here. Writes /logs/verifier/reward.txt (mean episode score) and details.json. """ import hashlib import json import os import sys import time HERE = os.path.dirname(os.path.abspath(__file__)) WORLD = os.path.join(HERE, "world") sys.path.insert(0, WORLD) import task as task_mod # noqa: E402 (also puts WORLD/gauntlet on sys.path) import gauntlet as G # noqa: E402 import harness # noqa: E402 import scoring # noqa: E402 APP = os.environ.get("FT2_APP_DIR", "/app") LOG_DIR = os.environ.get("FT2_LOG_DIR", "/logs/verifier") CONTROLLER = os.path.join(APP, "controller.py") def sha256(path): with open(path, "rb") as f: return hashlib.sha256(f.read()).hexdigest() def write_result(reward, details): os.makedirs(LOG_DIR, exist_ok=True) with open(os.path.join(LOG_DIR, "reward.txt"), "w") as f: f.write(f"{reward:.6f}\n") with open(os.path.join(LOG_DIR, "details.json"), "w") as f: json.dump(details, f, indent=1, default=str) print(f"reward {reward:.6f}") def main(): with open(os.path.join(HERE, "hidden_seeds.json")) as f: spec = json.load(f) with open(os.path.join(HERE, "app_sha256.json")) as f: expected = json.load(f) details = {"episodes": []} for rel, h in expected.items(): p = os.path.join(APP, rel) if not os.path.isfile(p) or sha256(p) != h: details["error"] = f"/app/{rel} differs from the shipped file (it is read-only)" return write_result(0.0, details) if not os.path.isfile(CONTROLLER): details["error"] = "/app/controller.py not found" return write_result(0.0, details) if os.geteuid() == 0: try: os.chmod(HERE, 0o700) # the controller runs as nobody and cannot read the hidden seeds except Exception: pass os.makedirs(LOG_DIR, exist_ok=True) ws = harness.Workspace(CONTROLLER, APP, stderr_path=os.path.join(LOG_DIR, "controller_stderr.log")) task = task_mod.TASK rows, t_all = [], time.monotonic() try: for tier, n in spec["episodes"].items(): for idx in range(n): r = harness.run_episode(G, task, ws, tier, idx, int(spec["base_seed"]), os.path.join(APP, "scene.xml")) x = scoring.summarize(r) rows.append(x) print(f"{tier} {idx:2d} band={x['band']} score={x['score']:.3f} fully_done={x['fully_done']} " f"violations={x['violations']}", flush=True) finally: ws.close() details.update(scoring.aggregate(rows)) details["mix"] = spec["episodes"] details["episodes"] = rows print(f"grading wall time {time.monotonic() - t_all:.1f}s", file=sys.stderr) write_result(details["reward"], details) if __name__ == "__main__": main()