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
fix(runner): two more relay repairs found by the all-model qwen sweep
richard-epsilla92481f661e66
diff --git a/runner/server.py b/runner/server.pyindex 14b73cb0..5b4f79e7 100644--- a/runner/server.py+++ b/runner/server.py@@ -1922,8 +1922,13 @@ def _normalize_openai_chat_body(body: bytes) -> bytes:Surgical, matched to what was captured live: an assistant tool-call message whose `content`is the empty string becomes `content: null` (equally legal, and translators emit no textblock for it), and empty `{"type": "text", "text": ""}` parts are dropped from list-shaped- content (if that empties a tool-call message's list, it becomes null too). Anything else —- other roles, non-empty text, unparseable bodies — passes through byte-identical."""+ content (if that empties a tool-call message's list, it becomes null too). An EMPTY+ `reasoning_content` is deleted outright: qwen-code echoes DeepSeek's extension field back+ verbatim, and LLMTR's validator requires it non-empty when present ('String must contain at+ least 1 character(s)', measured live on deepseek-v4-pro 2026-08-27 — the turn died right+ after its tool call). A non-empty one is meaningful interleaved thinking and passes through.+ Anything else — other roles, non-empty text, unparseable bodies — passes through+ byte-identical."""try:obj = json.loads(body)if not isinstance(obj, dict) or not isinstance(obj.get("messages"), list):@@ -1943,6 +1948,10 @@ def _normalize_openai_chat_body(body: bytes) -> bytes:elif content == "" and m.get("tool_calls"):m["content"] = Nonechanged = True+ if m.get("role") == "assistant" and m.get("reasoning_content") in ("", None) \+ and "reasoning_content" in m:+ del m["reasoning_content"]+ changed = Trueif not changed:return bodyreturn json.dumps(obj, separators=(",", ":")).encode()@@ -1973,6 +1982,25 @@ def _stringify_tool_content(body: bytes) -> bytes:return body+def _drop_stream_options(body: bytes) -> bytes:+ """Remove `stream_options` from one chat-completions body.++ Spec-legal and honored by most models, but LLMTR's openai/gpt-5.x upstream 400s any+ streaming request carrying it (isolated live 2026-08-27: the identical body succeeds the+ moment stream_options goes; every other model there accepts it). The error is the generic+ 'The model provider rejected the request', so there is nothing to pattern-match — the relay+ instead retries a 400 once without the field, and keeps doing so for the route only when+ that retry is what made it work. Cost: streamed responses stop carrying usage totals."""+ try:+ obj = json.loads(body)+ if isinstance(obj, dict) and "stream_options" in obj:+ del obj["stream_options"]+ return json.dumps(obj, separators=(",", ":")).encode()+ except Exception: # noqa: BLE001 — a body we cannot parse is a body we must not alter+ pass+ return body++def _rename_max_tokens(body: bytes) -> bytes:"""max_tokens -> max_completion_tokens in one chat-completions body.@@ -2103,13 +2131,19 @@ class _HermesRelayHandler(http.server.BaseHTTPRequestHandler):body = _rename_max_tokens(body)if flags.get("stringify_tool_content"):body = _stringify_tool_content(body)+ if flags.get("drop_stream_options"):+ body = _drop_stream_options(body)headers["content-length"] = str(len(body))resp = None+ tried_slim = Falsefor attempt in (0, 1):req = urllib.request.Request(base.rstrip("/") + tail, data=body,method=self.command, headers=headers)try:resp = urllib.request.urlopen(req, timeout=600)+ if attempt == 1 and tried_slim:+ # the blind no-stream_options retry is what made this route work+ flags["drop_stream_options"] = Truebreakexcept urllib.error.HTTPError as e:data = e.read()@@ -2128,6 +2162,14 @@ class _HermesRelayHandler(http.server.BaseHTTPRequestHandler):body = stringifiedheaders["content-length"] = str(len(body))continue+ slim = _drop_stream_options(body) if body is not None else None+ if attempt == 0 and e.code == 400 and slim is not None and slim != body:+ tried_slim = True+ # Generic 400 with stream_options aboard: blind single retry without it+ # (LLMTR's gpt-5.x upstream names nothing better). Sticks only if it works.+ body = slim+ headers["content-length"] = str(len(body))+ continue# pass provider errors through verbatimself.send_response(e.code)self.send_header("content-type", e.headers.get("content-type") or "application/json")diff --git a/runner/tests/test_hermes_relay.py b/runner/tests/test_hermes_relay.pyindex bdefad65..ad64408c 100644--- a/runner/tests/test_hermes_relay.py+++ b/runner/tests/test_hermes_relay.py@@ -232,3 +232,66 @@ def test_relay_retries_a_tool_content_rejection_and_sticks():assert len(calls) == 3 and calls[2]["messages"][1]["content"] == "TOOL-Q"finally:up.shutdown()++# ── empty reasoning_content (qwen x deepseek-v4-pro on LLMTR, 2026-08-27) ───────────────────────+# qwen echoes DeepSeek's reasoning_content back verbatim; when it is empty, LLMTR's validator+# 400s with 'String must contain at least 1 character(s)' — measured live, right after the tool.++def test_normalize_drops_empty_reasoning_content_only():+ from server import _normalize_openai_chat_body+ body = json.dumps({"messages": [+ {"role": "assistant", "content": None, "reasoning_content": "",+ "tool_calls": [{"id": "c1", "type": "function",+ "function": {"name": "f", "arguments": "{}"}}]},+ {"role": "assistant", "content": "hi", "reasoning_content": "kept: real thinking"},+ ]}).encode()+ out = json.loads(_normalize_openai_chat_body(body))+ assert "reasoning_content" not in out["messages"][0]+ assert out["messages"][1]["reasoning_content"] == "kept: real thinking"+++# ── stream_options drop-on-rejection (qwen x LLMTR gpt-5.x, 2026-08-27) ─────────────────────────+# LLMTR's openai/gpt-5.x upstream 400s any streaming body carrying stream_options, with only the+# generic 'model provider rejected the request' — so the relay retries a 400 once without the+# field and remembers the fix only when that retry succeeded.++def test_relay_retries_a_stream_options_rejection_and_sticks():+ calls = []++ class Upstream(BaseHTTPRequestHandler):+ protocol_version = "HTTP/1.1"++ def do_POST(self): # noqa: N802+ body = json.loads(self.rfile.read(int(self.headers["content-length"])))+ calls.append(body)+ if "stream_options" in body:+ data = b'{"error": {"message": "The model provider rejected the request."}}'+ self.send_response(400)+ else:+ data = b'{"ok": true}'+ self.send_response(200)+ self.send_header("content-type", "application/json")+ self.send_header("content-length", str(len(data)))+ self.end_headers()+ self.wfile.write(data)++ def log_message(self, *a):+ pass++ up = ThreadingHTTPServer(("127.0.0.1", 0), Upstream)+ threading.Thread(target=up.serve_forever, daemon=True).start()+ try:+ base, tok = _hermes_relay_route(f"http://127.0.0.1:{up.server_address[1]}/v1", "sk-real")+ body = json.dumps({"model": "m", "stream": True, "stream_options": {"include_usage": True},+ "messages": [{"role": "user", "content": "hi"}]}).encode()+ req = urllib.request.Request(base + "/chat/completions", data=body, method="POST",+ headers={"authorization": f"Bearer {tok}",+ "content-type": "application/json"})+ assert json.loads(urllib.request.urlopen(req, timeout=10).read()) == {"ok": True}+ assert len(calls) == 2 and "stream_options" not in calls[1]+ urllib.request.urlopen(urllib.request.Request(+ base + "/chat/completions", data=body, method="POST",+ headers={"authorization": f"Bearer {tok}", "content-type": "application/json"}), timeout=10)+ assert len(calls) == 3 and "stream_options" not in calls[2] # sticky: no second 400+ finally:+ up.shutdown()