harness: ajieval checkpoint (M checkpoint / P6A-9 rows; n/a for fields a record lacks)

This commit is contained in:
dev committed 2026-10-05 13:28:57 +03:00
1 parent c1391eb3c5
commit 4aa9183e78
4 files changed
+151

No files matched your search

+4
View File
@@ -203,6 +203,10 @@ def main(argv=None):
pf = sub.add_parser("profile", help="per-run cost profile: termination, output tokens, solution size, diagnostic codes")
pf.add_argument("paths", nargs="+")
pf.set_defaults(fn=lambda a: print(report.profile(a.paths)))
cp = sub.add_parser("checkpoint", help="per-run rows for the M checkpoint and P6A-9: results, cost, docs by group, diagnostic buckets, program size; n/a where a record lacks a field")
cp.add_argument("paths", nargs="+")
cp.add_argument("--json", action="store_true")
cp.set_defaults(fn=lambda a: print(report.checkpoint(a.paths, a.json)))
c = sub.add_parser("classify", help="record the primary failure category of a run (protocol §27)")
c.add_argument("run")
+126
View File
@@ -232,3 +232,129 @@ def profile(paths):
f"{files} / {lines} / {nbytes} | {f'{lowered[0]} / {lowered[1]}' if lowered else '-'} | "
f"{docs.get('unique_docs_read', '-')} | {ir} | {ty} | {', '.join(f'{k} {v}' for k, v in codes.items()) or '-'} |")
return "\n".join(out)
# ---------------------------------------------------------------- M checkpoint / P6A-9 rows
def _code_kinds():
"""code -> kind from docs/reference/error-codes.md (`ownership.use_after_move`, …)."""
import re
kinds = {}
with open(os.path.join(util.REPO, "docs", "reference", "error-codes.md"), encoding="utf-8") as f:
for line in f:
m = re.match(r"\| ([ET]\d{4}) \| ([a-z_]+)\.", line)
if m:
kinds[m.group(1)] = m.group(2)
return kinds
def _diagnostic_buckets(codes):
"""The checkpoint's diagnostic fields. Every code lands in exactly one
bucket; codes in none of the named ones are counted in `other`, never
dropped."""
kinds = _code_kinds()
b = {k: 0 for k in ("E0001-E0006", "E5001", "E5002", "E1001", "E7005", "other_E7xxx", "ownership", "borrow",
"resource", "concurrency", "runtime_traps", "other")}
for code, n in codes.items():
kind = kinds.get(code, "")
if code in ("E0001", "E0002", "E0003", "E0004", "E0005", "E0006"):
b["E0001-E0006"] += n
elif code in ("E5001", "E5002", "E1001", "E7005"):
b[code] += n
elif code.startswith("E7"):
b["other_E7xxx"] += n
elif code.startswith("T"):
b["runtime_traps"] += n
elif kind == "ownership":
b["ownership"] += n
elif kind in ("borrow", "memory", "island"):
b["borrow"] += n
elif kind == "resource":
b["resource"] += n
elif kind in ("concurrency", "atomic", "task", "sync", "io"):
b["concurrency"] += n
else:
b["other"] += n
b["ir_form_total"] = b["E0001-E0006"] + b["E5001"] + b["E5002"]
return b
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
"n/a", never reconstructed. Shareable: numbers, codes and documentation
file names only."""
from . import languages
na = "n/a"
rows = []
for p in paths:
for f in sorted(glob.glob(os.path.join(p, "**", "run.json"), recursive=True)):
if "/superseded/" in f:
continue
r = util.read_json(f)
d = os.path.dirname(f)
lang = r["language"]["name"]
m = r["metrics"]
ctx = m.get("context") or {}
pin = ctx.get("provider_input_tokens") or {}
docs = ctx.get("docs")
cyc = None if m.get("failed_verifier_cycles") is None else m["failed_verifier_cycles"] + (m.get("failed_test_cycles") or 0)
if docs is not None:
rb = docs.get("read_tokens_by_group") or {}
doc_fields = {"quick_reference_unique": rb.get("quick_reference", na), "source_docs_unique": rb.get("source_docs", na),
"air_docs_unique": rb.get("air_docs", na), "files_opened": docs.get("files_opened", na),
"coverage_by_section": docs.get("coverage_by_section", na)}
elif lang == "aji_air":
# Single-file AIR bundle: everything read was AIR documentation,
# as recorded at the time (unique_reference_tokens, reference_coverage).
doc_fields = {"quick_reference_unique": na, "source_docs_unique": na,
"air_docs_unique": ctx.get("unique_reference_tokens", na), "files_opened": na,
"coverage_by_section": {"reference-bundle.md": ctx["reference_coverage"]} if ctx.get("reference_coverage") is not None else na}
else:
doc_fields = {k: na for k in ("quick_reference_unique", "source_docs_unique", "air_docs_unique", "files_opened", "coverage_by_section")}
exts = set(languages.load(lang).get("source_extensions", []))
_, _, nbytes = _source_size(d, exts)
program = {"source_bytes": nbytes, "lowered_air_bytes": na, "mechanical_air_eliminated_raw": na, "mechanical_air_eliminated_normalized": na}
if lang == "aji_source":
low = _lowered_size(d)
if low:
program.update({"lowered_air_bytes": low[0], "lowered_air_bytes_normalized": low[1],
"mechanical_air_eliminated_raw": round(1 - nbytes / low[0], 4) if low[0] else na,
"mechanical_air_eliminated_normalized": round(1 - nbytes / low[1], 4) if low[1] else na})
def v(x):
return na if x is None else x
rows.append({
"task": r["task"]["id"], "agent": _agent_key(r),
"condition": {"aji_air": "air", "aji_source": "source"}.get(lang, lang),
"result": "PASS" if r.get("accepted") else ("FAIL" if r.get("accepted") is False else na),
"first_public_check": v(m.get("first_public_test_passed")), "repair_cycles": v(cyc),
"tool_calls": v(m.get("tool_calls")), "wall_seconds": v(m.get("elapsed_seconds")),
"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)),
"program": program,
})
return rows
def checkpoint(paths, as_json=False):
rows = checkpoint_rows(paths)
if as_json:
return json.dumps(rows, indent=2)
out = []
for r in sorted(rows, key=lambda r: (r["task"], r["agent"], r["condition"])):
out.append(f"## {r['task']} · {r['agent']} · {r['condition']}\n")
for k in ("result", "first_public_check", "repair_cycles", "tool_calls", "wall_seconds",
"provider_input_total", "provider_input_uncached", "output_tokens"):
out.append(f"- {k}: {r[k]}")
for group in ("docs", "diagnostics", "program"):
out.append(f"- {group}:")
for k, x in r[group].items():
out.append(f" - {k}: {json.dumps(x) if isinstance(x, (dict, list)) else x}")
out.append("")
return "\n".join(out)
+11
View File
@@ -264,6 +264,17 @@ class NativeTest(unittest.TestCase):
self.assertEqual(native.normalize_usage({"input": 40, "cache_read": 60, "cache_creation": 0, "output": 5})["input"], 100)
class CheckpointTest(unittest.TestCase):
def test_diagnostic_buckets(self):
b = report._diagnostic_buckets({"E0001": 2, "E0006": 1, "E5001": 3, "E5002": 1, "E1001": 4, "E7005": 2, "E7003": 1,
"E2001": 1, "E2101": 2, "E2104": 1, "E3002": 1, "E4304": 1, "T0001": 1, "E3101": 5})
self.assertEqual(b["E0001-E0006"], 3)
self.assertEqual(b["ir_form_total"], 7)
self.assertEqual((b["E1001"], b["E7005"], b["other_E7xxx"]), (4, 2, 1))
self.assertEqual((b["ownership"], b["borrow"], b["resource"], b["concurrency"], b["runtime_traps"]), (1, 3, 1, 1, 1))
self.assertEqual(b["other"], 5) # effects and capabilities are not dropped
class CyclesTest(unittest.TestCase):
def test_repair_cycles_from_commands(self):
from ajieval import native