HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
benchmark: failed tool calls from the stored trace, and wall time summed per row
Hao Luac5f838ce6e2
diff --git a/scripts/benchmark/README.md b/scripts/benchmark/README.mdindex c66a80ac..71243241 100644--- a/scripts/benchmark/README.md+++ b/scripts/benchmark/README.md@@ -10,8 +10,11 @@ already stores. The rules below decide a row; `test_run.py` pins them.For every harness and model named, each task of a pack runs in a fresh session: the pack stagesthe task's files and instruction as the first turn, the turn runs, the files it produced come backfrom the session, and the suite's own grader decides. A record carries the verdict (`resolved`,-`reward` in [0, 1], the grader's reason), wall time, tool calls and tool names, fresh / cached /-output tokens, the connection and the served model the turn record stamps, and the files.+`reward` in [0, 1], the grader's reason), wall time, tool calls and tool names, how many of those+calls failed (the CLI flagged the result, or a shell exited non-zero or raised — read from the+stored trace), fresh / cached / output tokens, the connection and the served model the turn record+stamps, and the files. The table sums wall time and tool calls per row and gives the failed calls+as a rate.Packs live in `packs/`, one module each, and never re-implement a grader: the suite's data andgrader stay outside this repository, at `PACK_ROOT`, under the suite's own licence.diff --git a/scripts/benchmark/render.py b/scripts/benchmark/render.pyindex 69de079d..7919852b 100644--- a/scripts/benchmark/render.py+++ b/scripts/benchmark/render.py@@ -36,8 +36,8 @@ def render(records: list[dict]) -> str:"the pack's own grader decides; every number is read from the turn record.", ""]for (prov, pack), rows in sorted(by.items()):out += [f"## Provider: {prov} — pack: {pack}", "",- "| Harness | Model | Tasks | Resolved | Reward | Median wall | Median tool calls | Fresh in | Cached in | Output | Served by | Notes |",- "|---|---|---|---|---|---|---|---|---|---|---|---|"]+ "| Harness | Model | Tasks | Resolved | Reward | Wall (sum) | Median wall | Tool calls | Calls failed | Fresh in | Cached in | Output | Served by | Notes |",+ "|---|---|---|---|---|---|---|---|---|---|---|---|---|---|"]findings, errors = [], []groups = collections.defaultdict(list)for r in rows:@@ -67,16 +67,25 @@ def render(records: list[dict]) -> str:served = sorted({str(r.get("connection") or "").replace("integration:", "") for r in ran if r.get("connection")}) or ["?"]resolved = sum(1 for r in clean if r.get("resolved"))reward = statistics.mean(float(r.get("reward") or 0) for r in clean) if clean else None+ wall_sum = sum(float(r.get("wall_s") or 0) for r in clean)+ calls = sum(int(r.get("tool_calls") or 0) for r in clean)+ # failed calls are known only for runs whose trace was read; the rate is over those+ with_trace = [r for r in clean if r.get("tool_results") is not None]+ results_n = sum(int(r.get("tool_results") or 0) for r in with_trace)+ failed_n = sum(int(r.get("tool_failed") or 0) for r in with_trace)+ if with_trace and len(with_trace) < len(clean):+ notes.append(f"tool outcomes read on {len(with_trace)} of {len(clean)} runs")+ failed_cell = f"{failed_n} ({100 * failed_n / results_n:.0f}%)" if results_n else "-"out.append(f"| {h} | {m} | {len(clean)} | {resolved} ({100 * resolved / len(clean):.0f}%) | "- f"{'-' if reward is None else f'{reward:.2f}'} | {fmt_s(median(r.get('wall_s') for r in clean))} | "- f"{'-' if not clean else f'{median(r.get('tool_calls') for r in clean):.0f}'} | "+ f"{'-' if reward is None else f'{reward:.2f}'} | {fmt_s(wall_sum)} | {fmt_s(median(r.get('wall_s') for r in clean))} | "+ f"{calls} | {failed_cell} | "f"{fmt_k(sum(x.get('fresh_input', 0) for x in u)) if u else '-'} | "f"{fmt_k(sum(x.get('cached_input', 0) for x in u)) if u else '-'} | "f"{fmt_k(sum(x.get('output', 0) for x in u)) if u else '-'} | {', '.join(served)} | "f"{' ; '.join(notes).replace('|', '/')} |"if clean else- f"| {h} | {m} | 0 | - | - | - | - | - | - | - | {', '.join(served)} | {' ; '.join(notes) or 'no counted runs'} |")+ f"| {h} | {m} | 0 | - | - | - | - | - | - | - | - | - | {', '.join(served)} | {' ; '.join(notes) or 'no counted runs'} |")out.append("")if findings:out += ["Findings, runs served by another connection, as another model, or that reached the network — listed, not scored:", ""]diff --git a/scripts/benchmark/run.py b/scripts/benchmark/run.pyindex 22209879..d69601d1 100644--- a/scripts/benchmark/run.py+++ b/scripts/benchmark/run.py@@ -101,6 +101,44 @@ def usage_of(u: dict | None) -> dict:"prompt_total": fresh + cached + written}+# ── tool outcomes ─────────────────────────────────────────────────────────────────────────────────+# The canonical stream pairs every tool_use with a tool_result. is_error is what the CLI flagged;+# it is not the whole story: opencode returns a shell that died with "[exit code: 1]" and a+# Traceback as an ordinary result (measured 2026-09-18), so a non-zero exit code or an interpreter+# traceback in the result counts as a failed call too. What is counted is calls that did not do+# what the agent asked, whatever the agent did next.+FAILED_RESULT = re.compile(r"\[exit code:? [1-9]\d*\]|\bexit(?:ed with)? code[:=]? ?[1-9]\d*\b"+ r"|Traceback \(most recent call last\)|\bcommand not found\b", re.I)+++def tool_outcomes(trace_ndjson: str) -> dict:+ calls = results = failed = 0+ for line in trace_ndjson.splitlines():+ line = line.strip()+ if not line:+ continue+ try:+ e = json.loads(line)+ except ValueError:+ continue+ m = e.get("message") if isinstance(e, dict) else None+ content = m.get("content") if isinstance(m, dict) else None+ if not isinstance(content, list):+ continue+ for b in content:+ if not isinstance(b, dict):+ continue+ if b.get("type") == "tool_use":+ calls += 1+ elif b.get("type") == "tool_result":+ results += 1+ body = b.get("content")+ text = body if isinstance(body, str) else json.dumps(body)[:4000]+ if b.get("is_error") or FAILED_RESULT.search(text[:4000]):+ failed += 1+ return {"trace_tool_calls": calls, "tool_results": results, "tool_failed": failed}++def recover_session(before: set[str], harness_id: str, prompt: str, t0: float, wait_s: int = 1800) -> dict | None:"""The session this harness opened for this prompt since t0 that was not there before, onceit has finished: an instance whose console proxy cuts a synchronous request at five minutes@@ -170,6 +208,14 @@ def run_task(pack, root: str, task: dict, label: str, harness_id: str, model: stassistant=(turn.get("assistant") or "")[:200])if rec.get("turn_error") is None and turn.get("error"):rec["turn_error"] = turn.get("error")+ # tool outcomes come from the stored trace: each tool_use has its tool_result, and a result the+ # CLI flagged or a shell that exited non-zero is a failed call (the record's own count of calls+ # stays the turn record's)+ try:+ trace = api("GET", f"/v1/traces/{sid}/all?org={os.environ.get('ORG', 'local')}", raw=True).decode("utf-8", "replace")+ rec.update(tool_outcomes(trace))+ except Exception as e: # noqa: BLE001 — a trace that cannot be read leaves the outcome columns empty, noted+ rec["trace_error"] = repr(e)[:120]# the produced files, downloaded from the session so the pack grades what was storedtdir = os.path.join(workdir, provider, label, model, pack.NAME, task["id"])os.makedirs(tdir, exist_ok=True)diff --git a/scripts/benchmark/test_run.py b/scripts/benchmark/test_run.pyindex cda364db..f54a41ed 100644--- a/scripts/benchmark/test_run.py+++ b/scripts/benchmark/test_run.py@@ -10,7 +10,7 @@ import syssys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))from render import render # noqa: E402-from run import network_use, usage_of # noqa: E402+from run import network_use, tool_outcomes, usage_of # noqa: E402def test_a_web_tool_or_a_shell_that_reaches_out_is_network_use():@@ -46,10 +46,28 @@ def test_usage_keeps_fresh_cached_and_output_apart():assert usage_of(None)["prompt_total"] == 0+def test_a_flagged_or_non_zero_tool_result_is_a_failed_call():+ """The result shapes as the trace stores them: opencode returns a shell that died as an+ ordinary result carrying "[exit code: 1]" with is_error false (measured 2026-09-18)."""+ ok = {"type": "user", "message": {"content": [{"type": "tool_result", "tool_use_id": "1", "is_error": False,+ "content": "sheets: ['Sheet1'] dims A1:D53706"}]}}+ died = {"type": "user", "message": {"content": [{"type": "tool_result", "tool_use_id": "2", "is_error": False,+ "content": "[stderr] Traceback (most recent call last):\n ModuleNotFoundError: No module named 'openpyxl'\n[exit code: 1]"}]}}+ flagged = {"type": "user", "message": {"content": [{"type": "tool_result", "tool_use_id": "3", "is_error": True, "content": "denied"}]}}+ use = lambda i: {"type": "assistant", "message": {"content": [{"type": "tool_use", "id": i, "name": "bash", "input": {}}]}}+ trace = "\n".join(json.dumps(e) for e in [use("1"), ok, use("2"), died, use("3"), flagged,+ {"type": "assistant", "message": {"content": [{"type": "thinking", "thinking": "..."}]}}])+ assert tool_outcomes(trace) == {"trace_tool_calls": 3, "tool_results": 3, "tool_failed": 2}+ # a result that merely mentions an exit code of zero, or none, is a success+ fine = {"type": "user", "message": {"content": [{"type": "tool_result", "tool_use_id": "4", "is_error": False, "content": "done [exit code: 0]"}]}}+ assert tool_outcomes(json.dumps(use("4")) + "\n" + json.dumps(fine))["tool_failed"] == 0++def _rec(**kw):base = {"provider": "deepseek", "pack": "spreadsheetbench", "harness": "opencode", "model": "m", "task": "t","resolved": True, "reward": 1.0, "wall_s": 10.0, "tool_calls": 3, "connection": "integration:deepseek",- "served": "deepseek-flash", "usage": {"fresh_input": 100, "cached_input": 1000, "output": 10}}+ "served": "deepseek-flash", "usage": {"fresh_input": 100, "cached_input": 1000, "output": 10},+ "tool_results": 3, "tool_failed": 1}base.update(kw)return base@@ -76,6 +94,16 @@ def test_tokens_are_reported_apart_never_summed():assert "| 2k | 2.00M | 1k |" in row, row+def test_wall_is_summed_and_failed_calls_are_a_rate():+ md = render([_rec(task="a", wall_s=10.0, tool_calls=3, tool_results=3, tool_failed=1),+ _rec(task="b", wall_s=30.0, tool_calls=5, tool_results=5, tool_failed=1)])+ row = next(line for line in md.splitlines() if line.startswith("| opencode |"))+ assert "| 40 s | 20 s | 8 | 2 (25%) |" in row, row+ md = render([_rec(task="a", tool_results=3, tool_failed=1), {**_rec(task="b"), "tool_results": None, "tool_failed": None}])+ row = next(line for line in md.splitlines() if line.startswith("| opencode |"))+ assert "tool outcomes read on 1 of 2 runs" in row, row++def test_a_runner_error_is_listed_as_an_error_not_a_fail():md = render([_rec(task="a"), {"provider": "deepseek", "pack": "spreadsheetbench", "harness": "opencode", "model": "m","task": "b", "error": "request failed and no session found: 502"}])