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: a session is found by the head of its stored prompt, which the list truncates
Hao Lu3af27a9b42ea
diff --git a/scripts/benchmark/run.py b/scripts/benchmark/run.pyindex d69601d1..ce36c4ed 100644--- a/scripts/benchmark/run.py+++ b/scripts/benchmark/run.py@@ -139,6 +139,14 @@ def tool_outcomes(trace_ndjson: str) -> dict:return {"trace_tool_calls": calls, "tool_results": results, "tool_failed": failed}+def prompt_matches(stored: str, prompt: str) -> bool:+ """Whether a session's stored prompt is this prompt. The session list keeps the prompt's head+ (1500 characters, measured), sometimes behind an attachment line, so the stored head — whole,+ or after that line — must be found in the prompt sent; its tail is not there to compare."""+ probes = [stored[:800]] + ([stored.split("\n\n", 1)[1][:600]] if "\n\n" in stored else [])+ return any(p and p in prompt for p in probes)++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@@ -146,11 +154,10 @@ def recover_session(before: set[str], harness_id: str, prompt: str, t0: float, wprompt tells the sessions apart; a session whose stored prompt cannot be read is taken onlywhen it is the sole new one."""deadline = t0 + wait_s- mark = prompt.strip()[-160:]while time.time() < deadline:new = [s for s in api("GET", "/v1/sessions?limit=100").get("sessions", [])if s["session_id"] not in before and harness_id in (s.get("harness_id"), s.get("backend"))]- mine = [s for s in new if mark and mark in str(s.get("user_prompt") or "")]+ mine = [s for s in new if prompt_matches(str(s.get("user_prompt") or ""), prompt)]if not mine and len(new) == 1:mine = newif not mine:diff --git a/scripts/benchmark/test_run.py b/scripts/benchmark/test_run.pyindex f54a41ed..bb381bf1 100644--- a/scripts/benchmark/test_run.py+++ b/scripts/benchmark/test_run.py@@ -10,7 +10,18 @@ import syssys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))from render import render # noqa: E402-from run import network_use, tool_outcomes, usage_of # noqa: E402+from run import network_use, prompt_matches, tool_outcomes, usage_of # noqa: E402+++def test_a_truncated_stored_prompt_still_identifies_its_session():+ """The session list keeps 1500 characters of the prompt (measured); the first recovery matched+ on the prompt's tail and found nothing for a long instruction."""+ boiler = "You are working in a workspace. " * 20+ a = boiler + "### instruction\nSort column B by the helper column J " + "x" * 2000+ b = boiler + "### instruction\nCombine the RANGES sheet into LISTS " + "y" * 2000+ assert prompt_matches(a[:1500], a) and not prompt_matches(a[:1500], b)+ assert prompt_matches("[Attached files saved in your working directory: input.xlsx]\n\n" + a[:1400], a)+ assert not prompt_matches("", a)def test_a_web_tool_or_a_shell_that_reaches_out_is_network_use():