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
runner: the relay drops reasoning_effort for a model whose provider refuses its thinking shape (#315)
github-actions[bot]c2146a779acd
diff --git a/runner/server.py b/runner/server.pyindex 9b4dfeea..6d1bc6fb 100644--- a/runner/server.py+++ b/runner/server.py@@ -3011,6 +3011,19 @@ def _stringify_assistant_content(body: bytes) -> bytes:return body+_EFFORT_SHAPE_REFUSED_RE = re.compile(rb"is not supported for this model\. Use .{0,80}adaptive", re.S)+++def _effort_shape_refused(data: bytes) -> bool:+ """Whether a chat-completions request's `reasoning_effort` came back as Anthropic's refusal of+ the legacy thinking block: '"thinking.type: enabled" is not supported for this model. Use+ "thinking.type: adaptive" and "output_config.effort"'. The harness sent effort the OpenAI way+ (OpenHands sends `reasoning_effort: high` for every model, and its SDK already treats Claude 5+ as adaptive); the aggregator's chat-completions translation made it the block Claude 5, 4.7 and+ 4.8 refuse (TokenRouter, measured on hr-test 0.25.13, 2026-09-28)."""+ return bool(_EFFORT_SHAPE_REFUSED_RE.search(data or b""))++def _set_reasoning_effort_none(body: bytes) -> bytes:"""Set `reasoning_effort: "none"` in one chat-completions body.@@ -3598,6 +3611,8 @@ class _HermesRelayHandler(http.server.BaseHTTPRequestHandler):body = _drop_stream_options(body)if flags.get(f"reasoning_effort_none:{_body_model}"):body = _set_reasoning_effort_none(body)+ if flags.get(f"drop_reasoning_effort:{_body_model}"):+ body = _drop_top_level_field(body, "reasoning_effort")for field in flags.get("drop_fields", ()):body = _drop_top_level_field(body, field)headers["content-length"] = str(len(body))@@ -3655,6 +3670,18 @@ class _HermesRelayHandler(http.server.BaseHTTPRequestHandler):body = effortheaders["content-length"] = str(len(body))continue+ if (attempt < 2 and e.code == 400 and body is not None and b"reasoning_effort" in body+ and _effort_shape_refused(data)):+ # An aggregator that turns `reasoning_effort` into Anthropic's legacy thinking+ # block is refused by the newer Claude models. The effort goes, for this model on+ # this route, and the request goes again at the model's own default; the broker+ # does the same for brokered traffic.+ flags[f"drop_reasoning_effort:{_body_model}"] = True+ body = _drop_top_level_field(body, "reasoning_effort")+ headers["content-length"] = str(len(body))+ print(f"[relay] provider refused reasoning_effort's thinking shape for model={_body_model}; "+ f"sent again without it", flush=True)+ continueif e.code in (400, 422):# The provider's own words, kept here for every provider: a harness shows a# refusal as "400 (no body)" (Gemini CLI) or cuts it to a few dozen charactersdiff --git a/runner/tests/test_relay_effort_shape.py b/runner/tests/test_relay_effort_shape.pynew file mode 100644index 00000000..f6832c9b--- /dev/null+++ b/runner/tests/test_relay_effort_shape.py@@ -0,0 +1,67 @@+"""The relay drops `reasoning_effort` for a model whose provider refuses the thinking shape the+aggregator made of it, remembers that for the model on the route, and sends again."""+import json+import pathlib+import sys+import threading+import urllib.request+from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer++sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))+from server import _effort_shape_refused, _hermes_relay_route # noqa: E402++# TokenRouter's words for anthropic/claude-opus-5 on hr-test 0.25.13 (2026-09-28), field names masked as sent+REFUSAL = (b'{"error":{"message":"\\"***.***.enabled\\" is not supported for this model. Use \\"***.***.adaptive\\" '+ b'and \\"output_config.effort\\" to control thinking behavior.","type":"invalid_request_error","param":"","code":null}}')+++def test_the_refusal_is_the_thinking_shape_and_nothing_else():+ assert _effort_shape_refused(REFUSAL)+ assert _effort_shape_refused(b'{"error": {"message": "\\"thinking.type: enabled\\" is not supported for this model. Use \\"thinking.type: adaptive\\" and \\"output_config.effort\\"."}}')+ assert not _effort_shape_refused(b'{"error": {"message": "reasoning_effort is not supported for this model."}}')+ assert not _effort_shape_refused(b"") and not _effort_shape_refused(None)+++def test_relay_drops_the_effort_for_that_model_and_remembers_it():+ 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 body.get("model", "").startswith("anthropic/") and "reasoning_effort" in body:+ data = REFUSAL+ 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-key")+ headers = {"authorization": f"Bearer {tok}", "content-type": "application/json"}++ def send(model):+ body = json.dumps({"model": model, "reasoning_effort": "high", "messages": [{"role": "user", "content": "hi"}]}).encode()+ return json.loads(urllib.request.urlopen(urllib.request.Request(base + "/chat/completions", data=body, method="POST", headers=headers), timeout=10).read())++ assert send("anthropic/claude-opus-5") == {"ok": True}+ assert len(calls) == 2 and "reasoning_effort" in calls[0] and "reasoning_effort" not in calls[1]+ # the route remembers it for that model: the next request goes once, already without the effort+ assert send("anthropic/claude-opus-5") == {"ok": True}+ assert len(calls) == 3 and "reasoning_effort" not in calls[2]+ # another model on the same route keeps its effort: the refusal was the model's, not the route's+ assert send("openai/gpt-6") == {"ok": True}+ assert len(calls) == 4 and calls[3]["reasoning_effort"] == "high"+ finally:+ up.shutdown()