# Evaluation Harness Non-normative. The language-neutral agent scaffold and run recorder of plan item E0-3 (protocol §3–§5, §13–§17, §27–§29). Code: [`tools/eval/`](../../tools/eval/). Python standard library only. ```sh cd tools/eval python3 -m ajieval run --task DIR --language aji_air --provider anthropic --model MODEL --class frontier \ --evaluator CMD --out runs/ python3 -m ajieval matrix PLAN.json # every cell of a plan; resumable python3 -m ajieval report runs/ [--json] # VSR, repair cycles, context, cost per correct solution python3 -m ajieval classify RUN_DIR CATEGORY [--caught-by verifier|runtime|test] [--cause CAUSE] python3 -m unittest discover tests # harness self-tests (needs `zig build`, Rust, Zig) ``` ## One run One model + one language + one task + one fresh workspace + one fresh agent context (protocol §3). The task's starter workspace for the language is copied into `RUN/workspace`, and the agent loop runs until the model calls `finish`, ends its turn without a tool call, or a budget runs out. Then the evaluator judges the final workspace and the first-generation snapshot. **One loop for every language.** The system prompt, the tools and the termination rules are the same for Aji, Rust and Zig. A language contributes only its profile ([`tools/eval/languages/`](../../tools/eval/languages/)): how to invoke the toolchain, where its pinned documentation is, and which commands count as verifier, compiler or test runs. Profiles carry no solution hints (protocol §5). **Tools.** `list_files`, `read_file`, `write_file`, `edit_file`, `run` (a shell command in the workspace) and `finish`. Paths are confined to `/work` (the repository, writable) and `/docs` (documentation, read-only). **Sandbox.** `bwrap` (bubblewrap) is the default: - no network (protocol §4); - read-only system and toolchain; - the workspace at `/work`; - documentation at `/docs`; - a fresh `/tmp` and `HOME`; - a clean environment. `--sandbox none` is for harness development only and is recorded. **Termination.** One of: | Reason | Meaning | |---|---| | `finished` | the model called `finish` | | `model_end` | the model ended its turn without a tool call; the scaffold does not nudge, so stopping early is part of the measurement | | `max_tokens` | the reply hit the output-token limit | | `budget_tool_calls`, `budget_tokens`, `wall_time` | a task limit ran out | | `provider_error` | the model provider failed | **Providers.** Each provider has a fixed role: | Provider | Use | |---|---| | `anthropic` | Anthropic Messages API (`ANTHROPIC_API_KEY`) | | `openai` | OpenAI-compatible chat completions (`OPENAI_API_KEY`); also local servers such as vLLM, llama.cpp or Ollama via `base_url` | | `scripted` | replays fixed turns (self-tests) | Per model, `extra` (JSON) is merged into every request body and recorded, for example `{"reasoning_effort": "medium"}`. `key_env` names the environment variable holding the key, and `token_param` chooses `max_tokens` or `max_completion_tokens`. Keys are never written to records. **Documentation** is pinned to the toolchain being run: | Language | Mounted under `/docs` | |---|---| | Aji | the Agent Reference Bundle | | Rust | the toolchain's offline documentation from the sysroot: std API, the Reference, the Book | | Zig | the matching language reference (`/docs/doc`) and standard library source (`/docs/std`) | An environment variable (`AJI_EVAL_*_DOCS`) overrides this. Each mount's hash is recorded next to the compiler version, and hashes of large trees are cached in `~/.cache/ajieval`. ## Task directory (the interface to the private benchmark repository) ```text /task.json id, version, set (dev|validation|test), family, prompt, languages {lang: {workspace, test}}, limits, concurrency /prompt.md language-neutral statement // starter repository per language: README with the interface, public tests, build files ``` `limits` may set: | Limit | Default | |---|---| | `tool_calls` | 150 | | `total_tokens` | 3 000 000 | | `wall_seconds` | 3 600 | | `command_timeout` | 300 | | `output_chars` | 20 000 | The `test` command is the public test. Invoking it counts as a test run. Hidden tests, evaluators and reference implementations never enter this repository (protocol §29). The only task kept here is the harness development task [`dev-tasks/dev-echo`](dev-tasks/dev-echo/), which belongs to no benchmark family. ## Evaluator contract The harness calls `CMD WORKSPACE LANGUAGE TASK_DIR` outside the agent's sandbox. The evaluator must print one JSON object: ```json {"accepted": true, "gates": {"verifier": true, "public_tests": true, "hidden_functional": true, "hidden_regression": true, "fuzz": true, "resources": true, "deterministic_runs": true, "schedule_exploration": true}} ``` `accepted` follows protocol §13: all mandatory gates pass, with no partial success. An evaluator that could not judge the solution because of its own environment (sandbox, toolchain, missing dependency) adds `"infrastructure": true`; the record then says `evaluation_status: infrastructure_failure` instead of a solution failure. **Evaluator environment.** The harness calls the evaluator with the caller's environment plus three variables that describe the language toolchain exactly as the agent's sandbox had it: | Variable | Contents | |---|---| | `AJIEVAL_LANGUAGE` | `aji_air`, `aji_source`, `rust` or `zig` | | `AJIEVAL_TOOLCHAIN_PATH` | the toolchain's PATH entries, `:`-separated | | `AJIEVAL_TOOLCHAIN_DIRS` | the directories to bind read-only, one per line | An evaluator that sandboxes the code it builds and runs should: - bind `AJIEVAL_TOOLCHAIN_DIRS` read-only and put `AJIEVAL_TOOLCHAIN_PATH` first on PATH, rather than relying on shims such as `~/.cargo/bin` or mise, which need the real HOME; - set a private `CARGO_HOME` and build with `--offline` (Rust); - build in a copy of the workspace without `target/`, `.zig-cache/` or `zig-out/`, which the agent built under `/work`; - report infrastructure failures distinctly from solution failures. The evaluator's full output is stored in the run directory as `evaluator.log`; the record keeps only the verdict. To debug an evaluator without an agent run, call it exactly as the harness does: ```sh python3 -m ajieval evaluate --task TASK_DIR --language rust --workspace DIR --evaluator CMD --log evaluator.log ``` The evaluator runs untrusted code, so it must sandbox that code itself. The record stores the hash of the evaluator, or of `--evaluator-hash-path`, and the full verdict. ## Run record (`RUN/run.json`, protocol §28) Every run directory contains: | Path | Contents | |---|---| | `run.json` | the record below | | `events.jsonl` | every model reply (content and token usage), tool call and result, patch (unified diff), and command (exit code, output) | | `workspace/` | the final repository | | `first_generation/` | the workspace before the first toolchain invocation (protocol §14) | `run.json` holds: - **Identity:** - task id, version, set and hash; - evaluator command and hash; - language, profile hash, toolchain versions, docs path and hash; - model provider, id, class and parameters; - scaffold version, commit and sandbox; - system prompt hash and task prompt hash; - limits, hardware, seed. - **Metrics:** - model and tool calls; - input, output and cached tokens; - patches, commands, check/build/test runs; - failed verifier cycles and failed test cycles (§15); - first check, build, public test and hidden test results (§14); - files opened, repository and documentation bytes read (§16); - elapsed time, termination. - **Outcome:** `cost_usd` from an optional pricing table (USD per million tokens, §17), `verdict`, `first_generation_verdict`, `accepted`, the hashes of the final repository, and `classification`. ## Failure classification `ajieval classify` records the primary category of a failed run (protocol §27). For Aji runs it also records where the failure was caught: verifier, runtime or test. For the smoke test it also records the cause, decided before any language change is considered (protocol §38): - `language` - `documentation` - `agent_bundle` - `diagnostics` - `harness` - `model_capability` - `task_ambiguity` ### Advisory suggestions and improvement triage ```sh python3 -m ajieval classify RUN_DIR --suggest [--auto-accept] # needs TYPESAFE_API_KEY python3 -m ajieval calibrate runs/ python3 -m ajieval triage runs/ [--plan PLAN.json] [--json] ``` `classify --suggest` asks TypeSafe Jev, a System One classifier, for the category, the place the failure was caught and the cause. The answer is stored as `classification_suggestion` with per-option probabilities and confidence; it is not a classification. The questions and their option descriptions are defined once, in `ajieval/jev.py`. The state sent is minimal: task id, outcome, diagnostic codes, and the tails of the last three failing commands. Only failed runs of the `dev` and `validation` sets are sent; a `test`-set run is refused before any request, because sending it to a third party would disclose the held-out corpus (protocol §29). `calibrate` compares suggestions with human classifications per question: agreement overall and among the suggestions the thresholds would accept. Thresholds, proposal minimums and routes live only in `tools/eval/triage.json`. Until it says `"calibrated": true`, `--auto-accept` does nothing. After that, a suggestion whose every confidence meets its threshold becomes the classification, marked `"source": "jev"`; human labels are never overwritten. `triage` groups classified failures by (cause, language, category). A group becomes a proposal only when it has at least `min_events` runs across `min_tasks` tasks and `min_agents` agents, so one model struggling on one task never proposes anything (protocol §38). Each proposal is routed by cause to a layer. Diagnostic text, agent bundle, documentation and harness changes go to a reviewed patch or issue. A `language` cause goes only to an open-question entry carrying the evidence; an RFC is the owner's decision. `model_capability` is logged only. With `--plan`, proposals are withheld while that frozen plan still has cells to run, because changing Aji mid-experiment is online tuning. Triage reports; it never edits the specification, the bundle or the code. ## Track B: native agents ```sh python3 -m ajieval native --task DIR --language aji_air --agent codex --model gpt-6.1-sol --effort high --label N1 \ --evaluator CMD --out runs/ ``` In Track B the agent product is the scaffold: Codex, Claude Code or OpenCode runs with its own prompt, tools and context management (protocol §39b). The harness only: - copies the pristine workspace; - starts the CLI with the shared task message (the same preamble as Track A plus the task); - collects the repository; - runs the same evaluator. These runs are never evidence for H4. **Isolation.** bubblewrap with a shared network, because the CLI must reach its model backend. The sandbox contains: - `/work` (read-write), `/docs` (read-only), the language toolchain and the CLI (read-only); - a fresh `HOME` holding only the CLI's credential file and a minimal configuration written by the harness. User-level skills, MCP servers, memory, custom agents, plugins and global instructions therefore do not exist. Neither the evaluator nor the Aji repository is visible. Per agent: | Agent | Configuration | Shell network | |---|---|---| | `codex` | `codex exec --json`; `approval_policy=never`; web search off; product features off (multi-agent, apps, browser, computer use, plugins, skills, goals, hooks…) | off (Codex `workspace-write` sandbox) | | `claude` | `claude -p --output-format stream-json`; tools limited to `Bash`, `Read`, `Edit` and `Write`; `--strict-mcp-config`; slash commands off | off (networkless shell wrapper) | | `opencode` | `opencode run --pure --format json`; no MCP; `webfetch`, `websearch` and `task` off; no LSP downloads | off (networkless shell wrapper) | | `gobang` | `gobang run --json-events --in-place /work`; configuration written to the fresh HOME; documentation at `/docs` | off (gobang's own bubblewrap sandbox; the model has no shell) | **Networkless shell.** Inside the sandbox, the real shell binaries (`/usr/bin/bash`; `sh` follows its symlink) are replaced by wrappers. Each wrapper runs the command in a nested bubblewrap with a fresh, empty network namespace and without the resolver socket. The CLI process keeps the network to reach its backend. Every process a tool starts through a shell, `python3` sockets included, has neither network nor DNS. The live check is the dev task [`dev-netprobe`](dev-tasks/dev-netprobe/), which all three agents pass. **Record (`aji-eval-native/1`).** The run directory holds: | Path | Contents | |---|---| | `run.json` | the record below | | `transcript.jsonl` | the CLI's JSON event stream | | `stderr.log` | the CLI's error output | | `patch.diff` | the diff from the initial to the final workspace | | `initial/`, `workspace/` | the pristine and the final repository | `run.json` holds: - the CLI version and path; - the requested model and the model from the transcript, where the CLI reports it; - the effort setting and the account mode (subscription or API key; only the source is recorded, never a credential); - the written configuration and the command line; - start and end time; - tool calls and token usage as reported by the CLI, normalized to input, output and cached input; - the evaluator verdict. A first-generation snapshot is not available in Track B. There is no cost in dollars either: on subscriptions there is no honest cost per solution, so Track B reports success, time, tool calls and context. Economics stays with Track A. ### gobang gobang (a sibling repository) is an Aji-native harness: the model works through typed tools bound to the toolchain instead of a shell, and gobang's own verification gate decides when it is done. It is another agent product in Track B, so its runs are never evidence for H4 either; what it measures is the harness, against the other agents, ideally on the same model. ```sh PATH=/path/to/gobang/zig-out/bin:$PATH ZAI_API_KEY=… python3 -m ajieval native --task DIR --language aji_source \ --agent gobang --model glm-5.3-flash --evaluator CMD --out runs/ ``` - **Model ids.** `claude-*` uses the Anthropic API (`ANTHROPIC_API_KEY`); any other id uses GLM via z.ai (`ZAI_API_KEY`); `fixture:PATH` replays a gobang scenario file without a network, for harness self-tests. - **Key.** Unlike the other agents, gobang has no credential file: the key's variable is passed into the sandbox with `--setenv` and named, never valued, in the configuration. Its value appears in no record. It is visible to the user's own processes in the bubblewrap command line while the run lasts. A missing key stops the run before anything is created. - **Isolation.** gobang runs aji and test commands in a nested bubblewrap sandbox with every namespace unshared, so tool processes have no network even though the sandbox shares it for the model API; there is no shell wrapper. - **Transcript.** `transcript.jsonl` is gobang's journal (`--json-events`). Tool calls, token usage (input including cached, cached, output) and the model come from its events. The repair metrics come from gobang's toolchain tools, not from guessed shell commands: `aji_check` and `aji_run` count as `aji check` and `aji run` with aji's exit code for their outcome, `run_tests` as the configured test commands. The documentation tools are presented as reads of `/docs/`, so the documentation metrics count them like a file read. - **State.** gobang keeps its session state under `/tmp/gobang` inside the sandbox, so the evaluated repository contains only the solution. `metrics.agent_facts` carries `gobang_state` and `gobang_reason` (COMPLETED, FAILED, BLOCKED, INFRA_FAILED …) and the hash of gobang's prompts. ## Agent and evaluation status (Track B, `metrics`) How the agent's session ended and what the evaluator says about the repository are recorded separately, so that a transport problem after a finished solution is not read as a failure of the solution, and a cut-off reply is not read as a normal exit. | Field | Values | |---|---| | `agent_status` | `exited`, `max_tokens` (the last model reply stopped at its length limit: `finish_reason`/`stop_reason` `length` or `max_tokens`), `provider_rate_limited` (HTTP 429 or a usage limit, then an error exit), `error_exit`, `wall_time` | | `evaluation_status` | `accepted`, `rejected`, `evaluator_error` (no verdict: timeout, no JSON), `infrastructure_failure` (`"infrastructure": true`), `not_evaluated` | `termination` keeps the process-level outcome, except that a cut-off final reply is recorded as `max_tokens` there too. `accepted` and the VSR come only from the evaluator. ## Context metrics (both tracks, `metrics.context`) | Metric | Measures | |---|---| | `provider_input_tokens` | what the provider counted: total, cached and uncached input, and output | | `cumulative_context_tokens` | the text returned to the agent through its tool loop (every tool output, plus the task message), counted each time it was returned | | `unique_reference_tokens` | the distinct documentation text the agent saw: distinct lines in the outputs of tool calls that touched `/docs` | | `reference_coverage` | for a single-file reference (the Aji bundle), the fraction of its lines that the agent saw | | `docs` | for a documentation directory (the Source Reference Bundle of `aji_source`), per file and per group of the profile's `doc_groups`; see below | **Directory documentation (`metrics.context.docs`).** | Field | Meaning | |---|---| | `quick_reference_tokens`, `source_docs_tokens`, `air_docs_tokens` | size of each group (`_tokens`) | | `full_source_docs_tokens` | every group except `air_docs` | | `read_tokens_by_group` | tokens of the group's lines that the agent saw | | `coverage_by_section` | per file: the fraction of its distinctive lines that the agent saw | | `files_opened`, `unique_docs_read` | the files whose `/docs/…` path occurs in a tool input, and how many there are | Lines are compared after removing line-number prefixes (`12→`, `12:`) and grep prefixes (`/docs/…:12:`, `…md-12-`, `…md:`), so reads through grep tools count. A line is *distinctive* when no other file of the mount contains it. A line seen in a tool output counts toward a group only if every file containing it belongs to that group. This keeps table rules, fences and sections copied into several files out of the attribution: the error-code table, for instance, is in both `diagnostics/` and `air/`. **Checkpoint rows (`ajieval checkpoint`).** One row per run with the fields of the M checkpoint and P6A-9 (plan, P6A-9), shareable as numbers, codes and documentation file names: - result, `first_public_check`, `repair_cycles`, `tool_calls`, `wall_seconds`, provider input (total, uncached), output tokens; - `docs`: unique tokens read per group, `files_opened`, `coverage_by_section`; - `diagnostics`: `E0001-E0006`, `E5001`, `E5002`, `E1001`, `E7005`, `other_E7xxx`, then `ownership`, `borrow` (including `memory.*`), `resource`, `concurrency`, `runtime_traps` by the code's kind in `reference/error-codes.md`, and `other` for every remaining code (effects, capabilities, unsafe…), so nothing is dropped; `ir_form_total` is the sum of the first three; - `program`: source bytes, and for `aji_source` the lowered AIR bytes and both `mechanical_air_eliminated` metrics. - B1 fields ([`b1-heldout-plan.md`](b1-heldout-plan.md) §5): - `pretest_static_safety_caught`: safety diagnostics reported during the run, before any test. The metric is not symmetric across languages: use it for the mechanism within Aji and Rust, never for a cross-language safety claim. For Aji these are codes of kind ownership, borrow, init, memory, island, resource, concurrency, atomic, task, sync or unsafe. For Rust: E0382, E0499, E0502, E0505, E0506, E0507, E0596, E0597, E0716, E0373, plus the `Send`/`Sync` messages. For Zig it is 0, since its safety checks are dynamic. - `unsafe_usage`: a static count in the final workspace. For Aji: `effects [unsafe]`, `ref unchecked` and `assume`. For Rust: `unsafe`. For Zig: `@ptrCast`, `@ptrFromInt`, `@intFromPtr`, `@alignCast`, `@constCast`, `@volatileCast` and `@setRuntimeSafety(false)`. - `failure_class`, `caught_by` and `atomic_error` come from `ajieval classify`. `--atomic-error memory_model|algorithmic` applies to failed runs of the atomic family. A field the record did not collect is `n/a`, never reconstructed. For an older `aji_air` run with the single-file bundle, `air_docs_unique` is the recorded `unique_reference_tokens` and `coverage_by_section` is the recorded `reference_coverage`; the source groups are `n/a`. Diagnostic codes come from the stored command outputs, as for `profile`. The lowered sizes use the current `zig-out/bin/aji`, so take them while the frontend is the one the runs used. **Task variants for `aji_source`.** A task supports the condition through a `languages.aji_source` entry: a starter workspace whose README names `main.aji` and the `main` signature, and a public test. `in` is a keyword in `.aji`, so a source entry point names that capability `input`, and the grant becomes `--grant input=io.read`. Example: [`dev-tasks/dev-echo/lang/aji_source/`](dev-tasks/dev-echo/lang/aji_source/). The evaluator gets `AJIEVAL_LANGUAGE=aji_source` and runs `aji check`/`aji run` on `main.aji`. The gap between provider input and cumulative context is history resending, mostly cached. The gap between cumulative context and unique reference is rereading and verbose output. The tokenizer is `cl100k_base` if tiktoken is installed, otherwise bytes / 4. Each record names the one it used. ## Freezing and running an experiment ```sh python3 -m ajieval freeze PLAN.json # PLAN.freeze.json: frozen state + random cell order python3 -m ajieval matrix PLAN.json # verifies the freeze, runs cells sequentially in frozen order python3 -m ajieval journal PLAN.json "observation" [--run RUN_ID] python3 -m ajieval summary RUNS_DIR # shareable: PASS/FAIL matrix, per-cell metrics, aggregates python3 -m ajieval checkpoint RUNS_DIR... [--json] # M checkpoint / P6A-9 rows (below) python3 -m ajieval vsr RUNS_DIR... [--tasks T1,T2] [--json] # B1 §6.1: VSR per agent × language, 95 % Wilson intervals python3 -m ajieval costs RUNS_DIR... [--tasks T1,T2] [--json] # B1 §5: totals over all runs per accepted run, per-run medians python3 -m ajieval profile RUNS_DIR # shareable: termination, output tokens, tool calls, solution size, lowered AIR size (aji_source), docs files read, IR-form and type-mismatch diagnostic counts, diagnostic-code occurrences ``` In Track B the repair metrics are derived from the transcript's shell commands, with their exit codes and outputs: - a command is a toolchain invocation if it contains a verifier, compiler or test command of the language profile, or the task's public test command; - a failing invocation whose output carries the language's diagnostic pattern is a failed verifier cycle; - any other failing invocation with a test is a failed test cycle; - first-attempt success is the outcome of the first public test. The freeze records: - the Aji commit (the repository must be clean), the `aji` binary and the bundle hash; - the language profiles, toolchain versions and documentation hashes; - for each native agent: the CLI version and binary hash, and a fingerprint of its configuration (config, command line template, task preamble, shell wrapper); - the harness commit, the task hashes, the evaluator hash and the limits; - the shuffled order of all cells. If any of it changes, `matrix` stops. Problems seen during the runs go to the journal (`/journal.md`) and are acted on only after the last run. How tasks and references are produced without contamination: [`benchmark-authoring.md`](benchmark-authoring.md). ## Smoke test (E-S) [`smoke-plan.example.json`](smoke-plan.example.json) is the shape of the 36-run plan (owner decision): - families: a binary/stream parser and a concurrent bounded pipeline; - languages: Aji/AIR, Rust and Zig; - model classes: frontier, mid and small/local; - runs: 2 independent runs per cell. The tasks, evaluators and baselines come from E0-2 and E0-4. The smoke test checks infrastructure, not the hypothesis. Its headline numbers are still read: Verified Success Rate, repair cycles, context consumed and cost per correct solution.