eval: evaluator environment, evaluator.log, ajieval evaluate

The evaluator now receives AJIEVAL_LANGUAGE, AJIEVAL_TOOLCHAIN_PATH and
AJIEVAL_TOOLCHAIN_DIRS (the toolchain exactly as the agent's sandbox had
it), its full output is saved as evaluator.log in the run directory, and
ajieval evaluate runs an evaluator on any workspace exactly as the
harness does. harness.md documents what a sandboxing evaluator should do
(bind the toolchain dirs, private CARGO_HOME + --offline, build without
the agent's target/ and caches, report infrastructure failures
distinctly).
This commit is contained in:
dev committed 2026-10-04 19:40:23 +03:00
1 parent 93cf553a77
commit 2ee1ff192f
27 files changed
+91 -7

No files matched your search

+19
View File
@@ -94,6 +94,17 @@ def cmd_matrix(a):
report.print_report([out])
def cmd_evaluate(a):
"""Runs an evaluator on a workspace exactly as the harness does (same
arguments and environment), to debug evaluator integration without an
agent run."""
from . import task as task_mod
t = task_mod.Task(a.task)
lim = t.limits
verdict = record.evaluate(shlex.split(a.evaluator), os.path.realpath(a.workspace), a.language, t.dir, lim["command_timeout"] * 4, a.log)
print(json.dumps(verdict, indent=2))
def cmd_freeze(a):
path, frozen = freeze.write(a.plan, a.order_seed)
print(json.dumps({"freeze": path, "cells": len(frozen["order"]), "order_seed": frozen["order_seed"], "aji_commit": frozen["state"]["aji_commit"]}))
@@ -161,6 +172,14 @@ def main(argv=None):
m.add_argument("plan")
m.set_defaults(fn=cmd_matrix)
ev = sub.add_parser("evaluate", help="run an evaluator on a workspace exactly as the harness does")
ev.add_argument("--task", required=True)
ev.add_argument("--language", required=True, choices=languages.available())
ev.add_argument("--workspace", required=True)
ev.add_argument("--evaluator", required=True)
ev.add_argument("--log", help="write the evaluator's full stdout/stderr here")
ev.set_defaults(fn=cmd_evaluate)
fz = sub.add_parser("freeze", help="freeze a plan: record its state and a random cell order")
fz.add_argument("plan")
fz.add_argument("--order-seed", type=int)
+1 -1
View File
@@ -455,7 +455,7 @@ def run_native(task_dir, lang_name, agent_name, model, out_dir, effort=None, see
cyc = cycles(profile, lang.get("test"), command_events(agent_name, transcript))
with open(os.path.join(run_dir, "patch.diff"), "w") as f:
f.write(diff_tree(pristine, workspace))
verdict = record.evaluate(evaluator, workspace, lang_name, task.dir, lim["command_timeout"] * 4) if evaluator else None
verdict = record.evaluate(evaluator, workspace, lang_name, task.dir, lim["command_timeout"] * 4, os.path.join(run_dir, "evaluator.log")) if evaluator else None
rec = {
"schema": "aji-eval-native/1",
+29 -5
View File
@@ -47,12 +47,36 @@ def file_hashes(root):
return out
def evaluate(evaluator, workspace, lang, task_dir, timeout):
"""Runs the (external, hidden) evaluator; returns its JSON verdict."""
def evaluator_env(lang):
"""Environment for the evaluator: the caller's environment plus the
language toolchain exactly as the agent's sandbox had it, so an
evaluator that sandboxes the code it runs can bind the same directories.
AJIEVAL_LANGUAGE language id (aji_air, rust, zig)
AJIEVAL_TOOLCHAIN_PATH PATH entries of the toolchain (`:`-separated)
AJIEVAL_TOOLCHAIN_DIRS directories to bind read-only (newline-separated)
"""
env = dict(os.environ)
try:
p = subprocess.run(evaluator + [workspace, lang, task_dir], capture_output=True, text=True, timeout=timeout)
_, binds = languages.resolve_binaries(languages.load(lang))
except SystemExit:
binds = []
env["AJIEVAL_LANGUAGE"] = lang
env["AJIEVAL_TOOLCHAIN_PATH"] = ":".join(languages.sandbox_path(binds))
env["AJIEVAL_TOOLCHAIN_DIRS"] = "\n".join(binds)
return env
def evaluate(evaluator, workspace, lang, task_dir, timeout, log_path=None):
"""Runs the (external, hidden) evaluator; returns its JSON verdict. Its
full output goes to `log_path` (the run directory), not to the record."""
try:
p = subprocess.run(evaluator + [workspace, lang, task_dir], capture_output=True, text=True, timeout=timeout, env=evaluator_env(lang))
except subprocess.TimeoutExpired:
return {"accepted": False, "error": "evaluator timed out"}
if log_path:
with open(log_path, "w") as f:
f.write(f"$ {' '.join(evaluator)} WORKSPACE {lang} TASK_DIR\nexit {p.returncode}\n--- stdout ---\n{p.stdout}\n--- stderr ---\n{p.stderr}")
try:
verdict = json.loads(p.stdout)
except json.JSONDecodeError:
@@ -110,9 +134,9 @@ def run_one(task_dir, lang_name, provider_name, model, out_dir, model_class=None
verdict = first_verdict = None
if evaluator:
verdict = evaluate(evaluator, workspace, lang_name, task.dir, lim["command_timeout"] * 4)
verdict = evaluate(evaluator, workspace, lang_name, task.dir, lim["command_timeout"] * 4, os.path.join(run_dir, "evaluator.log"))
if a.first_snapshot:
first_verdict = evaluate(evaluator, a.first_snapshot, lang_name, task.dir, lim["command_timeout"] * 4)
first_verdict = evaluate(evaluator, a.first_snapshot, lang_name, task.dir, lim["command_timeout"] * 4, os.path.join(run_dir, "evaluator.first.log"))
metrics["first_hidden_test_passed"] = None if first_verdict is None else first_verdict["accepted"]
record = {