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:
dev committed 2026-10-06 08:39:55 +03:00
1 parent 7bbbe34b94
commit 035ea19834
7 files changed
+319 -2

No files matched your search

+10
View File
@@ -126,6 +126,8 @@ def cmd_classify(a):
path = os.path.join(a.run, "run.json")
rec = util.read_json(path)
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)
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("--cause", choices=CAUSES)
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)
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.fn(a)
+110 -1
View File
@@ -280,6 +280,108 @@ def _diagnostic_buckets(codes):
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):
"""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
@@ -327,6 +429,7 @@ def checkpoint_rows(paths):
def v(x):
return na if x is None else x
codes = _diagnostic_codes(r, d)
rows.append({
"task": r["task"]["id"], "agent": _agent_key(r),
"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")),
"output_tokens": v(m.get("output_tokens")),
"docs": doc_fields,
"diagnostics": _diagnostic_buckets(_diagnostic_codes(r, d)),
"diagnostics": _diagnostic_buckets(codes),
"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