- Claude Code and OpenCode: system shells replaced inside the sandbox by wrappers that run every command in a nested bubblewrap with an empty network namespace and no resolver socket; the CLI keeps its backend connection. dev-netprobe (new dev task) passes for all three agents: no network, no DNS from the shell - context metrics for both tracks: provider input (cached/uncached), cumulative context through the tool loop, unique reference tokens and bundle coverage; report shows them; no dollar cost for Track B - ajieval freeze: frozen state (clean Aji commit, binary, bundle, toolchains, docs, CLI versions and config fingerprints, tasks, evaluator, limits) and a shuffled cell order; matrix verifies it and runs cells sequentially in that order; ajieval journal - docs: benchmark-authoring.md (roles, clean-context brief, E-G checklist); harness.md, protocol §39b, plan updated
140 lines
5.5 KiB
Python
140 lines
5.5 KiB
Python
"""Freezing an experiment (protocol §39a, §39b).
|
||
|
||
`ajieval freeze PLAN.json` writes PLAN.freeze.json. It records everything
|
||
that must not change until the last run of the plan:
|
||
|
||
- the Aji commit (the repository must be clean), the `aji` binary and the
|
||
Agent Reference Bundle;
|
||
- each language profile, toolchain version and documentation hash;
|
||
- each native agent's CLI version and binary hash, and a fingerprint of
|
||
its configuration: written config, command line template, task
|
||
preamble, networkless shell wrapper;
|
||
- the harness commit, the task hashes and the evaluator hash;
|
||
- the cell order: every cell (task × language × model × run) shuffled
|
||
once with a recorded seed.
|
||
|
||
`ajieval matrix` refuses to run a plan whose freeze file no longer matches,
|
||
and runs the cells sequentially in the frozen order.
|
||
"""
|
||
|
||
import json
|
||
import os
|
||
import random
|
||
import shutil
|
||
import subprocess
|
||
import tempfile
|
||
|
||
from . import languages, native, task as task_mod, util
|
||
|
||
|
||
def _agent_fingerprint(mdl):
|
||
ag = native.AGENTS[mdl["agent"]]
|
||
home = tempfile.mkdtemp()
|
||
try:
|
||
config = ag.configure(home, mdl["model"], mdl.get("effort"))
|
||
finally:
|
||
shutil.rmtree(home, ignore_errors=True)
|
||
material = {
|
||
"config": config,
|
||
"argv": ag.argv(mdl["model"], mdl.get("effort"), "<task message>"),
|
||
"preamble": native.PREAMBLE,
|
||
"netless_wrapper": native.NETLESS_WRAPPER if ag.netless_shell else None,
|
||
"codex_features_off": native.CODEX_FEATURES_OFF if mdl["agent"] == "codex" else None,
|
||
"credentials": ag.credentials,
|
||
}
|
||
cli = os.path.realpath(shutil.which(ag.binary) or ag.binary)
|
||
return {
|
||
"cli_version": ag.version(),
|
||
"cli_hash": util.sha256_path(cli) if os.path.exists(cli) else None,
|
||
"configuration_hash": util.sha256_text(json.dumps(material, sort_keys=True)),
|
||
}
|
||
|
||
|
||
def snapshot(plan, base):
|
||
"""The current state of everything a plan depends on."""
|
||
commit = util.git_commit()
|
||
aji = os.path.join(util.REPO, "zig-out", "bin", "aji")
|
||
bundle = os.path.join(util.REPO, "zig-out", "agent", "reference-bundle.md")
|
||
langs = {}
|
||
for name in plan["languages"]:
|
||
prof = languages.load(name)
|
||
langs[name] = {
|
||
"profile_hash": prof["profile_hash"],
|
||
"toolchain": [v.get("output") for v in languages.versions(prof)],
|
||
"docs": {("/docs/" + n): util.sha256_path_cached(p) for n, p in languages.docs_mounts(prof)},
|
||
}
|
||
tasks = {}
|
||
for t in plan["tasks"]:
|
||
tk = task_mod.Task(os.path.join(base, t))
|
||
tasks[tk.id] = {"version": tk.version, "hash": tk.hash()}
|
||
evaluator = None
|
||
if plan.get("evaluator"):
|
||
ev = plan["evaluator"].split()[0]
|
||
ev = ev if os.path.isabs(ev) else os.path.join(base, ev)
|
||
hp = plan.get("evaluator_hash_path")
|
||
hp = (hp if os.path.isabs(hp) else os.path.join(base, hp)) if hp else ev
|
||
evaluator = util.sha256_path(hp)
|
||
models = {}
|
||
for mdl in plan["models"]:
|
||
key = (mdl["agent"] + ":" + mdl["model"]) if mdl.get("agent") else mdl["model"]
|
||
models[key] = _agent_fingerprint(mdl) if mdl.get("agent") else {"provider": mdl["provider"], "options": {k: mdl.get(k) for k in ("extra", "base_url", "token_param", "max_tokens", "temperature")}}
|
||
return {
|
||
"aji_commit": commit,
|
||
"aji_binary": util.sha256_path(aji) if os.path.exists(aji) else None,
|
||
"agent_reference_bundle": util.sha256_path(bundle) if os.path.exists(bundle) else None,
|
||
"harness_commit": commit,
|
||
"languages": langs,
|
||
"tasks": tasks,
|
||
"evaluator": evaluator,
|
||
"models": models,
|
||
"limits": plan.get("limits"),
|
||
}
|
||
|
||
|
||
def cells(plan, base):
|
||
out = []
|
||
for t in plan["tasks"]:
|
||
tid = task_mod.Task(os.path.join(base, t)).id
|
||
for lang in plan["languages"]:
|
||
for mdl in plan["models"]:
|
||
key = (mdl["agent"] + ":" + mdl["model"]) if mdl.get("agent") else mdl["model"]
|
||
for seed in range(plan.get("runs", 1)):
|
||
out.append({"task": t, "task_id": tid, "language": lang, "model": key, "seed": seed})
|
||
return out
|
||
|
||
|
||
def freeze_path(plan_path):
|
||
return os.path.splitext(plan_path)[0] + ".freeze.json"
|
||
|
||
|
||
def write(plan_path, order_seed=None):
|
||
plan = util.read_json(plan_path)
|
||
base = os.path.dirname(os.path.abspath(plan_path))
|
||
snap = snapshot(plan, base)
|
||
if snap["aji_commit"] is None or snap["aji_commit"].endswith("+dirty"):
|
||
raise SystemExit("freeze needs a clean, committed repository (no +dirty)")
|
||
seed = order_seed if order_seed is not None else random.SystemRandom().randrange(2 ** 32)
|
||
order = cells(plan, base)
|
||
random.Random(seed).shuffle(order)
|
||
frozen = {"schema": "aji-eval-freeze/1", "plan_hash": util.sha256_path(plan_path), "state": snap, "order_seed": seed, "order": order}
|
||
util.write_json(freeze_path(plan_path), frozen)
|
||
return freeze_path(plan_path), frozen
|
||
|
||
|
||
def check(plan_path):
|
||
"""Returns the frozen record, or exits naming what changed."""
|
||
path = freeze_path(plan_path)
|
||
frozen = util.read_json(path)
|
||
plan = util.read_json(plan_path)
|
||
base = os.path.dirname(os.path.abspath(plan_path))
|
||
problems = []
|
||
if util.sha256_path(plan_path) != frozen["plan_hash"]:
|
||
problems.append("plan file")
|
||
now = snapshot(plan, base)
|
||
for key, value in frozen["state"].items():
|
||
if now.get(key) != value:
|
||
problems.append(key)
|
||
if problems:
|
||
raise SystemExit(f"{plan_path}: frozen state changed ({', '.join(problems)}); a frozen experiment cannot continue")
|
||
return frozen
|