B1: pre-registration of the first held-out benchmark after Phase 5 (Proposed); harness metrics
docs/evaluation/b1-heldout-plan.md: Rust, Zig, Aji/source x 3 native agents x 6 tasks (families A/B/C, capability descriptions only) x 3 runs = 162; metrics, analysis plan, decision rules; owner decisions D1-D5 requested. Phases 7 and 8 on hold. ajieval: statically prevented safety diagnostics, unsafe usage, atomic error kind in classify, vsr table with Wilson intervals.
This commit is contained in:
1 parent
7bbbe34b94
commit
035ea19834
7 files changed
+319
-2
No files matched your search
@@ -4,6 +4,7 @@ Non-normative. Empirical validation of the Aji hypothesis stated in [spec 14](..
|
|||||||
|
|
||||||
| Document | Purpose |
|
| Document | Purpose |
|
||||||
|---|---|
|
|---|---|
|
||||||
|
| [b1-heldout-plan.md](b1-heldout-plan.md) | B1 pre-registration: the first held-out benchmark after Phase 5 (Rust, Zig, Aji/source × 3 native agents × 6 tasks × 3 runs); design, metrics, analysis plan, decisions D1–D5 |
|
||||||
| [benchmark-authoring.md](benchmark-authoring.md) | Separation of roles for E0-2 and E-G: benchmark author and reference writers in clean contexts; brief; gate checklist |
|
| [benchmark-authoring.md](benchmark-authoring.md) | Separation of roles for E0-2 and E-G: benchmark author and reference writers in clean contexts; brief; gate checklist |
|
||||||
| [results/](results/) | Recorded experiment outcomes (shareable numbers only; private tasks under aliases) |
|
| [results/](results/) | Recorded experiment outcomes (shareable numbers only; private tasks under aliases) |
|
||||||
| [harness.md](harness.md) | Agent scaffold and run recorder (E0-3): task format, evaluator contract, run record, commands |
|
| [harness.md](harness.md) | Agent scaffold and run recorder (E0-3): task format, evaluator contract, run record, commands |
|
||||||
|
|||||||
@@ -0,0 +1,146 @@
|
|||||||
|
# B1: the first held-out benchmark after Phase 5 (pre-registration)
|
||||||
|
|
||||||
|
Status: **Proposed.** Accepted by the owner before the benchmark author starts. Frozen at `ajieval freeze`. After that nothing in this document changes until the last run.
|
||||||
|
Decision context: owner, 2026-10-06. Phase 5 is closed. Phases 7 and 8 are on **hold** until B1 is analyzed.
|
||||||
|
|
||||||
|
```text
|
||||||
|
Phase 5 exit → B1 (this document) → analysis H1/H2/H4/H5 → decision: Phase 7 or Phase 8
|
||||||
|
```
|
||||||
|
|
||||||
|
## 1. Questions
|
||||||
|
|
||||||
|
1. Does Aji/source raise verified success over Rust and Zig on systems tasks that load ownership, concurrency and atomics (H1)?
|
||||||
|
2. Does it reduce repair work (H2)?
|
||||||
|
3. How does success degrade from the strongest to the weakest agent stack in each language? The question is whether the degradation curve is flatter for Aji: the shape of degradation, not only the end points (H4).
|
||||||
|
4. What does a correct solution cost in tokens and time (H5 proxies; see D5)?
|
||||||
|
|
||||||
|
## 2. Design
|
||||||
|
|
||||||
|
| Variable | Values |
|
||||||
|
|---|---|
|
||||||
|
| Language (condition) | Rust, Zig, Aji/source. Aji/AIR is not in the main matrix (D2). |
|
||||||
|
| Agent stack (Track B, native agents) | N1 Codex + `gpt-6.1-sol` (high), N2 Claude Code + `claude-opus-5-5` (high), N3 OpenCode + `zai-coding-plan/glm-5.3-flash`, configured as in P6A-9 |
|
||||||
|
| Task | 6 private held-out tasks, 2 per family (§3) |
|
||||||
|
| Repetition | 3 independent runs per cell |
|
||||||
|
|
||||||
|
**Matrix:** 6 tasks × 3 languages × 3 agents × 3 runs = **162 runs**.
|
||||||
|
|
||||||
|
**Procedure** (as for P6A-9):
|
||||||
|
|
||||||
|
- The cells run one at a time, in an order shuffled once at freeze time. Each run gets a fresh workspace and HOME.
|
||||||
|
- Nothing changes between `ajieval freeze` and the last run: Aji, the bundles, the harness, the agent configurations, the tasks and the evaluators.
|
||||||
|
- No commit is made to this repository during that time.
|
||||||
|
- Observations go only to `ajieval journal`.
|
||||||
|
- An HTTP 429 is journaled and waited out. A completed run is never re-run.
|
||||||
|
- An infrastructure failure that invalidates a run stops the matrix and is reported before anything else.
|
||||||
|
|
||||||
|
Expected wall time is about 40 hours of sequential runs.
|
||||||
|
|
||||||
|
**Toolchain:** a tag cut after the B1 harness changes (`b1-frozen`). Both the AIR and the source bundle hashes are recorded.
|
||||||
|
|
||||||
|
## 3. Task families
|
||||||
|
|
||||||
|
These are capability descriptions for the independent author. They name **no** construct of Aji or of any other language.
|
||||||
|
|
||||||
|
- **A: ownership, resources, bounded memory.**
|
||||||
|
- Data structures and streams whose memory must stay within a stated bound.
|
||||||
|
- Resources (files, buffers) acquired and released on every path, including failure paths.
|
||||||
|
- Malformed input handled without crashing.
|
||||||
|
- Nothing may be used after release or released twice.
|
||||||
|
- **B: structured concurrency, cancellation, isolated object graphs.**
|
||||||
|
- Several workers exchange work and results.
|
||||||
|
- Cancellation or early stop arrives in the middle of work.
|
||||||
|
- Every worker must be accounted for at the end.
|
||||||
|
- Linked or cyclic data built by one worker is handed to another or shared read-only.
|
||||||
|
- **C: atomic synchronization, publication, compare-and-swap.**
|
||||||
|
- Lock-free counters, flags or slots shared by several workers.
|
||||||
|
- Data published by one worker and consumed by another.
|
||||||
|
- Retry loops on a contended value.
|
||||||
|
- Results must be exact under every interleaving the hidden tests force.
|
||||||
|
|
||||||
|
Each task must be solvable in Rust, Zig and Aji/source. More than one implementation strategy must be valid, and the statement is language-neutral (`benchmark-authoring.md`).
|
||||||
|
|
||||||
|
## 4. Difficulty
|
||||||
|
|
||||||
|
| Level | Target |
|
||||||
|
|---|---|
|
||||||
|
| easy | the frontier stacks nearly always pass |
|
||||||
|
| medium | the weakest stack understands the task and writes a program, but systems errors (ownership, races, orderings, resource paths) are common in at least one language |
|
||||||
|
| hard | beyond the weakest stack |
|
||||||
|
|
||||||
|
**H4 is tested on the medium level.** A task on which the weakest stack spends its whole budget reasoning and writes no program measures nothing about the language; task C in P6A-9 showed this. Distribution: 1 easy, 4 medium, 1 hard, with at least one medium task per family (D3). Calibration: D4.
|
||||||
|
|
||||||
|
## 5. Metrics
|
||||||
|
|
||||||
|
Per run, from the run record (protocol §13–§16, §27):
|
||||||
|
|
||||||
|
- verified success: the evaluator accepts the final repository;
|
||||||
|
- first-attempt success;
|
||||||
|
- repair cycles;
|
||||||
|
- tool calls;
|
||||||
|
- uncached provider input;
|
||||||
|
- output tokens;
|
||||||
|
- wall time;
|
||||||
|
- failure class and where the failure was caught (compiler or verifier, runtime, test).
|
||||||
|
|
||||||
|
New in B1 (implemented in `ajieval`, §8):
|
||||||
|
|
||||||
|
- **Statically prevented safety failures.** Safety diagnostics the compiler or verifier reported during the run, before any test ran. The code sets are fixed before freeze, one per language:
|
||||||
|
- Aji: ownership, borrow, resource, island, concurrency, atomic and unsafe codes;
|
||||||
|
- Rust: borrow-checker, move, lifetime and `Send`/`Sync` codes;
|
||||||
|
- Zig: none (its safety checks are dynamic).
|
||||||
|
|
||||||
|
This metric says *where* a defect was stopped. It is not a success measure.
|
||||||
|
- **Race and atomic-ordering failures.** Failed runs classified `CONCURRENCY`, `DEADLOCK` or `ATOMIC_ORDERING`.
|
||||||
|
- **Unsafe usage.** A static count in the final program:
|
||||||
|
- Aji: functions declaring `unsafe`, `ref unchecked`, `assume`;
|
||||||
|
- Rust: `unsafe` blocks and functions;
|
||||||
|
- Zig: a fixed list of unchecked builtins and pointer casts.
|
||||||
|
- **Atomic error kind.** For failed runs of family C: `memory_model` (a wrong ordering or publication) or `algorithmic` (a wrong protocol under sequential consistency). The classifier decides from the evaluator's failing gate and the final program. The language developer never sees the program.
|
||||||
|
|
||||||
|
## 6. Analysis plan (fixed before the runs)
|
||||||
|
|
||||||
|
1. **The main table:** verified success rate (VSR) per agent stack × language, each cell n = 18 (6 tasks × 3 runs), with 95 % Wilson intervals. Separately for the medium tasks and for each family.
|
||||||
|
2. **Degradation shape:** for each language, VSR along N1/N2 → N3, and the difference to the best baseline per agent stack. A flatter Aji curve is the signal. With three stacks this is three points, not a capability curve (D1).
|
||||||
|
3. **H1** (protocol §35): for the weakest stack, Aji VSR ≥ the best Rust/Zig VSR + 15 percentage points on families A and B. B1 reports this as *preliminary*: n = 18 per cell is too small for confirmation.
|
||||||
|
4. **H2:** median repair cycles among accepted runs, Aji ≤ 70 % of the best baseline.
|
||||||
|
5. **H4 (descriptive, D1):** N3 + Aji is compared with N1/N2 + Rust/Zig, non-inferior within 5 percentage points. The strongest form is N3 + Aji ≈ N1/N2 + Rust/Zig.
|
||||||
|
6. **Variance:** the spread across the three runs of each cell is reported. A cell whose three runs disagree is shown as such.
|
||||||
|
7. **Failures:** every failed run is classified (§27 category, where caught, §38 cause) before the summary is shared. No language change is decided from B1 before this classification.
|
||||||
|
8. **Negative results** are kept and reported (protocol §37).
|
||||||
|
|
||||||
|
## 7. Decision rules after B1 (owner's text)
|
||||||
|
|
||||||
|
- If H1 and H4 give a strong signal, go to **Phase 7**: the next question is whether verified semantics compile to real native code without killing performance.
|
||||||
|
- If the bottleneck is agent and tool interaction rather than the runtime, **Phase 8** may come first.
|
||||||
|
- If H4 does not show, do not invest in the backend yet. First understand why the verifier and the source language do not compensate for the capability gap.
|
||||||
|
|
||||||
|
A positive B1 is followed by a full confirmatory experiment: 8–12 tasks × 3 languages × 4 capability levels (one stack between N2 and N3, or below N3) × at least 6 runs.
|
||||||
|
|
||||||
|
## 8. Roles and integrity
|
||||||
|
|
||||||
|
As `benchmark-authoring.md`:
|
||||||
|
|
||||||
|
- **Independent benchmark author:** a clean context in the private repository, briefed from §3–§4 only.
|
||||||
|
- **Reference writers:** one clean context per language (Rust, Zig, Aji/source), each seeing only the statement, the starter workspace and that language's frozen documentation.
|
||||||
|
- **Clean operator:** freeze, matrix, classification.
|
||||||
|
|
||||||
|
The language developer receives only numbers, codes, gate names, hashes and file names. B1's tasks become dev material once their results are used for a design decision (protocol §7).
|
||||||
|
|
||||||
|
## Decisions requested from the owner
|
||||||
|
|
||||||
|
- **D1. Track B and H4.** Protocol §39a says Track B results are never evidence for H4, because they measure model and agent stack together.
|
||||||
|
- Proposal: B1 reports H4 as *stack-level capability compression* (descriptive, labeled H4-B).
|
||||||
|
- Confirmatory H4 stays with Track A: one scaffold, direct APIs, 4 capability levels. That is the follow-up experiment.
|
||||||
|
- The alternative is to amend §39a.
|
||||||
|
- **D2. Aji/AIR.** Not in the main matrix.
|
||||||
|
- Proposal: leave it out entirely. AIR has served its research role (P6A-9), and every AIR run costs as much as a main run.
|
||||||
|
- The option: 1 run per cell as a diagnostic control (+54 runs).
|
||||||
|
- **D3. Difficulty distribution.** Proposal: 1 easy, 4 medium, 1 hard, with at least one medium per family.
|
||||||
|
- **D4. Calibration without selection bias.** If tasks are tuned until Rust/Zig fail often on the same agents, and then Aji is measured on those agents, the comparison is biased toward Aji: a selection effect. Proposal:
|
||||||
|
- calibration is **language-symmetric**: the operator makes one pilot run per stack in **each** of the three languages (54 runs);
|
||||||
|
- the criteria use only language-blind aggregates. For example, medium means N3 writes a compiling or verified program in ≥ 2 of the 3 languages, and N1/N2 pass in ≥ 2 of 3;
|
||||||
|
- pilot runs are discarded, never reported to the language developer, and never reused as B1 runs.
|
||||||
|
|
||||||
|
The cheaper alternative is the author's judgment plus the reference writers' cycle counts, with no pilots.
|
||||||
|
- **D5. H5.** On subscriptions there is no honest cost per solution (protocol §39a). Proposal: B1 reports output tokens, uncached input and wall time per *accepted* run as proxies. Cost in dollars waits for Track A.
|
||||||
@@ -255,6 +255,10 @@ Lines are compared after removing line-number prefixes (`12→`, `12:`) and grep
|
|||||||
- `docs`: unique tokens read per group, `files_opened`, `coverage_by_section`;
|
- `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;
|
- `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.
|
- `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):
|
||||||
|
- `statically_prevented_safety`: safety diagnostics reported during the run. 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.
|
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.
|
||||||
|
|
||||||
@@ -270,6 +274,7 @@ python3 -m ajieval matrix PLAN.json # verifies the freeze, runs cells seque
|
|||||||
python3 -m ajieval journal PLAN.json "observation" [--run RUN_ID]
|
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 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 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 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
|
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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -157,4 +157,5 @@ Targets for Phase 6A, measured on dev tasks:
|
|||||||
| P6A | done (exit review in `phase-6-source-language.md`; P6A-9 [results](../evaluation/results/2026-10-05-p6a-9.md)): the agent-facing source language over AIR is the architecture |
|
| P6A | done (exit review in `phase-6-source-language.md`; P6A-9 [results](../evaluation/results/2026-10-05-p6a-9.md)): the agent-facing source language over AIR is the architecture |
|
||||||
| P4 | done (exit review in the phase file) |
|
| P4 | done (exit review in the phase file) |
|
||||||
| P5 | done (exit review in the phase file): atomics through every layer; litmus 20/20 exact against the independent oracle; race detector on every run test |
|
| P5 | done (exit review in the phase file): atomics through every layer; litmus 20/20 exact against the independent oracle; race detector on every run test |
|
||||||
| P7, P8 | not started |
|
| B1 | the first held-out benchmark after Phase 5 (owner decision, 2026-10-06): pre-registration [`b1-heldout-plan.md`](../evaluation/b1-heldout-plan.md) is Proposed; the independent author starts after its acceptance |
|
||||||
|
| P7, P8 | on hold until B1 is analyzed (owner decision, 2026-10-06) |
|
||||||
@@ -126,6 +126,8 @@ def cmd_classify(a):
|
|||||||
path = os.path.join(a.run, "run.json")
|
path = os.path.join(a.run, "run.json")
|
||||||
rec = util.read_json(path)
|
rec = util.read_json(path)
|
||||||
rec["classification"] = {"category": a.category, "caught_by": a.caught_by, "cause": a.cause, "note": a.note}
|
rec["classification"] = {"category": a.category, "caught_by": a.caught_by, "cause": a.cause, "note": a.note}
|
||||||
|
if a.atomic_error:
|
||||||
|
rec["classification"]["atomic_error"] = a.atomic_error
|
||||||
util.write_json(path, rec)
|
util.write_json(path, rec)
|
||||||
print(json.dumps(rec["classification"]))
|
print(json.dumps(rec["classification"]))
|
||||||
|
|
||||||
@@ -214,8 +216,16 @@ def main(argv=None):
|
|||||||
c.add_argument("--caught-by", choices=["verifier", "runtime", "test"])
|
c.add_argument("--caught-by", choices=["verifier", "runtime", "test"])
|
||||||
c.add_argument("--cause", choices=CAUSES)
|
c.add_argument("--cause", choices=CAUSES)
|
||||||
c.add_argument("--note")
|
c.add_argument("--note")
|
||||||
|
# B1 §5: for failed runs of the atomic family.
|
||||||
|
c.add_argument("--atomic-error", choices=["memory_model", "algorithmic"])
|
||||||
c.set_defaults(fn=cmd_classify)
|
c.set_defaults(fn=cmd_classify)
|
||||||
|
|
||||||
|
v = sub.add_parser("vsr", help="B1 §6.1: verified success rate per agent × language with 95 %% Wilson intervals")
|
||||||
|
v.add_argument("paths", nargs="+")
|
||||||
|
v.add_argument("--tasks", help="comma-separated task ids to include (e.g. the medium ones)")
|
||||||
|
v.add_argument("--json", action="store_true")
|
||||||
|
v.set_defaults(fn=lambda a: print(report.vsr_table(a.paths, set(a.tasks.split(",")) if a.tasks else None, a.json)))
|
||||||
|
|
||||||
a = p.parse_args(argv)
|
a = p.parse_args(argv)
|
||||||
a.fn(a)
|
a.fn(a)
|
||||||
|
|
||||||
|
|||||||
@@ -280,6 +280,108 @@ def _diagnostic_buckets(codes):
|
|||||||
return b
|
return b
|
||||||
|
|
||||||
|
|
||||||
|
# B1 (docs/evaluation/b1-heldout-plan.md §5): safety diagnostics a compiler
|
||||||
|
# or verifier reported before any test ran. Fixed before the freeze.
|
||||||
|
AJI_SAFETY_KINDS = {"ownership", "borrow", "init", "memory", "island", "resource", "concurrency", "atomic", "task", "sync", "unsafe"}
|
||||||
|
RUST_SAFETY_CODES = {"E0382", "E0499", "E0502", "E0505", "E0506", "E0507", "E0596", "E0597", "E0716", "E0373"}
|
||||||
|
RUST_SEND_SYNC = ("cannot be sent between threads safely", "cannot be shared between threads safely")
|
||||||
|
|
||||||
|
|
||||||
|
def statically_prevented(r, run_dir, codes=None):
|
||||||
|
"""Safety diagnostics reported during the run (codes only). Zig has no
|
||||||
|
static safety diagnostics: 0 by definition."""
|
||||||
|
lang = r["language"]["name"]
|
||||||
|
codes = codes if codes is not None else _diagnostic_codes(r, run_dir)
|
||||||
|
if lang in ("aji_air", "aji_source"):
|
||||||
|
kinds = _code_kinds()
|
||||||
|
return sum(n for c, n in codes.items() if c.startswith("E") and kinds.get(c) in AJI_SAFETY_KINDS)
|
||||||
|
if lang == "rust":
|
||||||
|
n = sum(v for c, v in codes.items() if c in RUST_SAFETY_CODES)
|
||||||
|
return n + _rust_send_sync(r, run_dir)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def _rust_send_sync(r, run_dir):
|
||||||
|
from . import native
|
||||||
|
|
||||||
|
if r.get("track") == "B":
|
||||||
|
outputs = [o for _, _, o in native.command_events(r["agent"]["name"], os.path.join(run_dir, "transcript.jsonl"))]
|
||||||
|
else:
|
||||||
|
outputs = [json.loads(l).get("output") or "" for l in open(os.path.join(run_dir, "events.jsonl")) if '"event": "command"' in l]
|
||||||
|
return sum(o.count(m) for o in outputs for m in RUST_SEND_SYNC)
|
||||||
|
|
||||||
|
|
||||||
|
# Unchecked operations in the final program (B1 §5): a static count.
|
||||||
|
ZIG_UNCHECKED = ("@ptrCast", "@ptrFromInt", "@intFromPtr", "@alignCast", "@constCast", "@volatileCast", "@setRuntimeSafety(false)")
|
||||||
|
|
||||||
|
|
||||||
|
def unsafe_usage(r, run_dir):
|
||||||
|
import re
|
||||||
|
|
||||||
|
lang = r["language"]["name"]
|
||||||
|
ws = os.path.join(run_dir, "workspace")
|
||||||
|
exts = {"rust": (".rs",), "zig": (".zig",), "aji_source": (".aji",), "aji_air": (".air",)}.get(lang, ())
|
||||||
|
n = 0
|
||||||
|
for root, _, files in os.walk(ws):
|
||||||
|
if any(p in root for p in ("/target", "/.zig-cache", "/zig-out")):
|
||||||
|
continue
|
||||||
|
for fn in files:
|
||||||
|
if not fn.endswith(exts):
|
||||||
|
continue
|
||||||
|
text = open(os.path.join(root, fn), encoding="utf-8", errors="replace").read()
|
||||||
|
text = re.sub(r"//[^\n]*", "", text) if lang != "aji_air" else re.sub(r";[^\n]*", "", text)
|
||||||
|
if lang == "rust":
|
||||||
|
n += len(re.findall(r"\bunsafe\b", text))
|
||||||
|
elif lang == "zig":
|
||||||
|
n += sum(text.count(b) for b in ZIG_UNCHECKED)
|
||||||
|
elif lang == "aji_source":
|
||||||
|
n += len(re.findall(r"effects \[[^\]]*\bunsafe\b", text)) + len(re.findall(r"\bref unchecked\b|\bassume\(", text))
|
||||||
|
else:
|
||||||
|
n += len(re.findall(r"effects \[[^\]]*\bunsafe\b", text)) + len(re.findall(r"borrow\.index\.unchecked|\bassume ", text))
|
||||||
|
return n
|
||||||
|
|
||||||
|
|
||||||
|
def wilson(k, n, z=1.96):
|
||||||
|
"""95 % Wilson score interval for k successes in n runs."""
|
||||||
|
if n == 0:
|
||||||
|
return (0.0, 0.0)
|
||||||
|
p = k / n
|
||||||
|
d = 1 + z * z / n
|
||||||
|
c = p + z * z / (2 * n)
|
||||||
|
h = z * ((p * (1 - p) / n + z * z / (4 * n * n)) ** 0.5)
|
||||||
|
return ((c - h) / d, (c + h) / d)
|
||||||
|
|
||||||
|
|
||||||
|
def vsr_table(paths, tasks=None, as_json=False):
|
||||||
|
"""B1 §6.1: verified success rate per agent stack × language with 95 %
|
||||||
|
Wilson intervals; `tasks` restricts to a set of task ids (for example
|
||||||
|
the medium ones). Numbers only."""
|
||||||
|
runs = [r for r in load(paths) if tasks is None or r["task"]["id"] in tasks]
|
||||||
|
cells = {}
|
||||||
|
for r in runs:
|
||||||
|
key = (_agent_key(r), r["language"]["name"])
|
||||||
|
k, n = cells.get(key, (0, 0))
|
||||||
|
cells[key] = (k + (1 if r.get("accepted") else 0), n + 1)
|
||||||
|
agents = sorted({a for a, _ in cells})
|
||||||
|
langs = sorted({l for _, l in cells})
|
||||||
|
if as_json:
|
||||||
|
return json.dumps([{"agent": a, "language": l, "accepted": cells[(a, l)][0], "runs": cells[(a, l)][1],
|
||||||
|
"vsr": cells[(a, l)][0] / cells[(a, l)][1], "ci95": wilson(*cells[(a, l)])}
|
||||||
|
for a in agents for l in langs if (a, l) in cells], indent=1)
|
||||||
|
out = ["| agent | " + " | ".join(langs) + " |", "|---|" + "---:|" * len(langs)]
|
||||||
|
for a in agents:
|
||||||
|
row = []
|
||||||
|
for l in langs:
|
||||||
|
if (a, l) not in cells:
|
||||||
|
row.append("—")
|
||||||
|
continue
|
||||||
|
k, n = cells[(a, l)]
|
||||||
|
lo, hi = wilson(k, n)
|
||||||
|
row.append(f"{100 * k / n:.0f} % ({k}/{n}; {100 * lo:.0f}–{100 * hi:.0f})")
|
||||||
|
out.append(f"| {a} | " + " | ".join(row) + " |")
|
||||||
|
return "\n".join(out)
|
||||||
|
|
||||||
|
|
||||||
def checkpoint_rows(paths):
|
def checkpoint_rows(paths):
|
||||||
"""One row per run with the fields of the M checkpoint and P6A-9 (plan,
|
"""One row per run with the fields of the M checkpoint and P6A-9 (plan,
|
||||||
P6A-9). Only what the record holds: a field the run did not collect is
|
P6A-9). Only what the record holds: a field the run did not collect is
|
||||||
@@ -327,6 +429,7 @@ def checkpoint_rows(paths):
|
|||||||
def v(x):
|
def v(x):
|
||||||
return na if x is None else x
|
return na if x is None else x
|
||||||
|
|
||||||
|
codes = _diagnostic_codes(r, d)
|
||||||
rows.append({
|
rows.append({
|
||||||
"task": r["task"]["id"], "agent": _agent_key(r),
|
"task": r["task"]["id"], "agent": _agent_key(r),
|
||||||
"condition": {"aji_air": "air", "aji_source": "source"}.get(lang, lang),
|
"condition": {"aji_air": "air", "aji_source": "source"}.get(lang, lang),
|
||||||
@@ -337,8 +440,14 @@ def checkpoint_rows(paths):
|
|||||||
"provider_input_total": v(pin.get("total")), "provider_input_uncached": v(pin.get("uncached")),
|
"provider_input_total": v(pin.get("total")), "provider_input_uncached": v(pin.get("uncached")),
|
||||||
"output_tokens": v(m.get("output_tokens")),
|
"output_tokens": v(m.get("output_tokens")),
|
||||||
"docs": doc_fields,
|
"docs": doc_fields,
|
||||||
"diagnostics": _diagnostic_buckets(_diagnostic_codes(r, d)),
|
"diagnostics": _diagnostic_buckets(codes),
|
||||||
"program": program,
|
"program": program,
|
||||||
|
# B1 §5 (n/a in records without the data).
|
||||||
|
"statically_prevented_safety": statically_prevented(r, d, codes),
|
||||||
|
"unsafe_usage": unsafe_usage(r, d) if os.path.isdir(os.path.join(d, "workspace")) else na,
|
||||||
|
"failure_class": v((r.get("classification") or {}).get("category")),
|
||||||
|
"caught_by": v((r.get("classification") or {}).get("caught_by")),
|
||||||
|
"atomic_error": v((r.get("classification") or {}).get("atomic_error")),
|
||||||
})
|
})
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
"""B1 metrics (docs/evaluation/b1-heldout-plan.md §5–§6)."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from ajieval import report
|
||||||
|
|
||||||
|
|
||||||
|
class B1Metrics(unittest.TestCase):
|
||||||
|
def test_wilson(self):
|
||||||
|
lo, hi = report.wilson(9, 18)
|
||||||
|
self.assertAlmostEqual((lo + hi) / 2, 0.5, places=6)
|
||||||
|
self.assertTrue(0.28 < lo < 0.30 and 0.70 < hi < 0.72)
|
||||||
|
self.assertEqual(report.wilson(0, 0), (0.0, 0.0))
|
||||||
|
lo, hi = report.wilson(18, 18)
|
||||||
|
self.assertAlmostEqual(hi, 1.0)
|
||||||
|
self.assertTrue(lo > 0.8)
|
||||||
|
|
||||||
|
def test_statically_prevented(self):
|
||||||
|
rust = {"language": {"name": "rust"}}
|
||||||
|
aji = {"language": {"name": "aji_source"}}
|
||||||
|
zig = {"language": {"name": "zig"}}
|
||||||
|
# E0382 (use after move) and E0499 (two mutable borrows) count; E0308 (types) does not.
|
||||||
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
open(os.path.join(d, "events.jsonl"), "w").close()
|
||||||
|
self.assertEqual(report.statically_prevented(rust, d, {"E0382": 2, "E0499": 1, "E0308": 5}), 3)
|
||||||
|
# E2001 (ownership), E4202 (atomic) count; E7005 (source type) and E1001 do not.
|
||||||
|
self.assertEqual(report.statically_prevented(aji, d, {"E2001": 1, "E4202": 2, "E7005": 3, "E1001": 1}), 3)
|
||||||
|
self.assertEqual(report.statically_prevented(zig, d, {"error": 4}), 0)
|
||||||
|
|
||||||
|
def test_unsafe_usage(self):
|
||||||
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
ws = os.path.join(d, "workspace")
|
||||||
|
os.makedirs(os.path.join(ws, "src"))
|
||||||
|
open(os.path.join(ws, "src", "main.rs"), "w").write("// unsafe in a comment\nfn f() { unsafe { g() } }\nunsafe fn g() {}\n")
|
||||||
|
self.assertEqual(report.unsafe_usage({"language": {"name": "rust"}}, d), 2)
|
||||||
|
open(os.path.join(ws, "main.aji"), "w").write("fn f(s: slice<u8>) -> u8\neffects [unsafe]\n{\n ref unchecked x = s[0];\n *x\n}\n")
|
||||||
|
self.assertEqual(report.unsafe_usage({"language": {"name": "aji_source"}}, d), 2)
|
||||||
|
open(os.path.join(ws, "main.zig"), "w").write("const p: *u8 = @ptrCast(q); // @ptrCast\n")
|
||||||
|
self.assertEqual(report.unsafe_usage({"language": {"name": "zig"}}, d), 1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user