B1 pre-registration Accepted (D1-D5; D4 with the no-tuning rule); cost proxies over all runs, safety metric renamed

This commit is contained in:
dev committed 2026-10-06 10:11:47 +03:00
1 parent 035ea19834
commit 6366d6c014
6 files changed
+134 -29

No files matched your search

+6
View File
@@ -226,6 +226,12 @@ def main(argv=None):
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)))
cs = sub.add_parser("costs", help="B1 §5: cost proxies per agent × language (totals over all runs per accepted run; per-run medians)")
cs.add_argument("paths", nargs="+")
cs.add_argument("--tasks", help="comma-separated task ids to include")
cs.add_argument("--json", action="store_true")
cs.set_defaults(fn=lambda a: print(report.cost_proxies(a.paths, set(a.tasks.split(",")) if a.tasks else None, a.json)))
a = p.parse_args(argv)
a.fn(a)
+51 -3
View File
@@ -280,8 +280,11 @@ 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.
# B1 (docs/evaluation/b1-heldout-plan.md §5): pre-test statically caught
# safety errors, i.e. safety diagnostics a compiler or verifier reported
# before any test ran. Fixed before the freeze. Not symmetric across
# languages (Zig has none by definition): a mechanism measure for Aji and
# Rust, never a cross-language safety claim.
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")
@@ -382,6 +385,51 @@ def vsr_table(paths, tasks=None, as_json=False):
return "\n".join(out)
def _median(xs):
xs = sorted(x for x in xs if x is not None)
if not xs:
return None
m = len(xs) // 2
return xs[m] if len(xs) % 2 else (xs[m - 1] + xs[m]) / 2
def cost_proxies(paths, tasks=None, as_json=False):
"""B1 §5 (D5): per agent stack × language, totals over ALL runs divided
by accepted runs (the price of failures included), and per-run medians.
No dollar cost: subscriptions have no honest price per solution."""
runs = [r for r in load(paths) if tasks is None or r["task"]["id"] in tasks]
cells = {}
for r in runs:
cells.setdefault((_agent_key(r), r["language"]["name"]), []).append(r)
rows = []
for (agent, lang), rs in sorted(cells.items()):
acc = sum(1 for r in rs if r.get("accepted"))
unc = [((r["metrics"].get("context") or {}).get("provider_input_tokens") or {}).get("uncached") for r in rs]
out = [r["metrics"].get("output_tokens") for r in rs]
wall = [r["metrics"].get("elapsed_seconds") for r in rs]
tools = [r["metrics"].get("tool_calls") for r in rs]
def per_acc(xs):
if acc == 0 or any(x is None for x in xs):
return None
return round(sum(xs) / acc, 1)
rows.append({"agent": agent, "language": lang, "runs": len(rs), "accepted": acc,
"uncached_input_per_accepted": per_acc(unc), "output_tokens_per_accepted": per_acc(out),
"wall_seconds_per_accepted": per_acc(wall),
"median_uncached_input_per_run": _median(unc), "median_output_tokens_per_run": _median(out),
"median_wall_seconds_per_run": _median(wall), "median_tool_calls_per_run": _median(tools)})
if as_json:
return json.dumps(rows, indent=1)
head = ["agent", "language", "runs", "accepted", "uncached_input_per_accepted", "output_tokens_per_accepted",
"wall_seconds_per_accepted", "median_uncached_input_per_run", "median_output_tokens_per_run",
"median_wall_seconds_per_run", "median_tool_calls_per_run"]
lines = ["| " + " | ".join(head) + " |", "|" + "---|" * len(head)]
for row in rows:
lines.append("| " + " | ".join("n/a" if row[h] is None else str(row[h]) for h in head) + " |")
return "\n".join(lines)
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
@@ -443,7 +491,7 @@ def checkpoint_rows(paths):
"diagnostics": _diagnostic_buckets(codes),
"program": program,
# B1 §5 (n/a in records without the data).
"statically_prevented_safety": statically_prevented(r, d, codes),
"pretest_static_safety_caught": 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")),
+19
View File
@@ -41,5 +41,24 @@ class B1Metrics(unittest.TestCase):
self.assertEqual(report.unsafe_usage({"language": {"name": "zig"}}, d), 1)
def test_cost_proxies_count_failures(self):
import json
def rec(d, n, accepted, unc, out, wall):
os.makedirs(d)
json.dump({"task": {"id": "T"}, "language": {"name": "rust"}, "track": "B",
"agent": {"name": "claude", "model": "m", "label": "N2"}, "accepted": accepted,
"metrics": {"output_tokens": out, "elapsed_seconds": wall, "tool_calls": 3,
"context": {"provider_input_tokens": {"uncached": unc}}}}, open(os.path.join(d, "run.json"), "w"))
with tempfile.TemporaryDirectory() as root:
rec(os.path.join(root, "a"), 1, True, 100, 10, 60)
rec(os.path.join(root, "b"), 2, False, 300, 30, 120)
row = json.loads(report.cost_proxies([root], as_json=True))[0]
# The failed run's cost is charged to the one accepted run.
self.assertEqual(row["uncached_input_per_accepted"], 400)
self.assertEqual(row["output_tokens_per_accepted"], 40)
self.assertEqual(row["median_wall_seconds_per_run"], 90)
if __name__ == "__main__":
unittest.main()