Skip to content

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.

A chat request refused for its effort's thinking shape goes again without the effort (#312)

github-actions[bot]77837e56b054
diff --git a/gateway/app.py b/gateway/app.py
index de8b0fa3..2a41bebf 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -3417,6 +3417,23 @@ def _strip_unsupported(body: bytes, provider: str = "", byok: bool = False, path
return json.dumps(doc).encode() if changed else body
+_EFFORT_SHAPE_REFUSED_RE = re.compile(r"is not supported for this model\. Use .{0,80}adaptive", re.S)
+
+
+def _effort_shape_refused(refused: bytes) -> bool:
+ """Whether an OpenAI-shape 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 the block Claude 5, 4.7
+ and 4.8 refuse (TokenRouter, measured on hr-test 0.25.12, 2026-09-28)."""
+ try:
+ text = refused.decode("utf-8", "replace")
+ except Exception: # noqa: BLE001
+ return False
+ return bool(_EFFORT_SHAPE_REFUSED_RE.search(text))
+
+
_GOOGLE_UNKNOWN_RE = re.compile(r'Unknown name \\?"([A-Za-z_][A-Za-z0-9_]*)\\?"(?! at \')')
@@ -3883,6 +3900,23 @@ async def llm_broker(path: str, request: Request):
headers={k: val for k, val in up.headers.items()
if k.lower() not in ("content-length", "transfer-encoding", "connection",
"content-encoding")})
+ if up.status_code == 400 and body and b"reasoning_effort" in body:
+ # An aggregator that turns `reasoning_effort` into Anthropic's legacy thinking block is
+ # refused by the newer Claude models; the request goes again without the effort, at the
+ # model's own default, the way a field Google does not know goes again without it.
+ refused = await up.aread()
+ await up.aclose()
+ if _effort_shape_refused(refused):
+ body = _without_field(body, "reasoning_effort")
+ print(f"[broker] {provider} refused reasoning_effort's thinking shape for {_body_model_name(body)!r}; "
+ f"sent again without it sid={sid}", flush=True)
+ req = rc.build_request(request.method, url, headers=headers, content=body or None)
+ up = await rc.send(req, stream=True)
+ else:
+ return Response(content=refused, status_code=400, media_type=up.headers.get("content-type"),
+ headers={k: val for k, val in up.headers.items()
+ if k.lower() not in ("content-length", "transfer-encoding", "connection",
+ "content-encoding")})
# A Google answer's tool calls carry the signatures the next request must replay.
tap = _GoogleSigTap(up.headers.get("content-type", "")) if (provider == "google" and up.status_code < 400) else None
diff --git a/gateway/tests/test_broker_google_unknown.py b/gateway/tests/test_broker_google_unknown.py
index a9ac59e3..93f20e48 100644
--- a/gateway/tests/test_broker_google_unknown.py
+++ b/gateway/tests/test_broker_google_unknown.py
@@ -5,7 +5,7 @@ import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
-from app import _google_unknown_field, _without_field # noqa: E402
+from app import _effort_shape_refused, _google_unknown_field, _without_field # noqa: E402
STORE = json.dumps([{"error": {"code": 400, "message": 'Invalid JSON payload received. Unknown name "store": Cannot find field.', "status": "INVALID_ARGUMENT"}}]).encode()
SEED = json.dumps({"error": {"code": 400, "message": 'Invalid JSON payload received. Unknown name "seed": Cannot find field.'}}).encode()
@@ -30,3 +30,17 @@ def test_without_field_drops_only_that_field():
assert "store" not in out and out["seed"] == 7 and out["messages"]
assert _without_field(body, "absent") == body
assert _without_field(b"not json", "store") == b"not json"
+
+
+def test_anthropics_refusal_of_the_effort_thinking_shape_is_recognised():
+ """TokenRouter's chat-completions translation of `reasoning_effort` for Claude 5 came back as
+ Anthropic's '"thinking.type: enabled" is not supported for this model. Use "thinking.type:
+ adaptive" and "output_config.effort"' (hr-test 0.25.12, 2026-09-28); the broker sends the
+ request again without the effort. Any other 400 is handed back as it came."""
+ refusal = (b'{"error":{"message":"\\"thinking.type: enabled\\" is not supported for this model. Use '
+ b'\\"thinking.type: adaptive\\" and \\"output_config.effort\\" to control reasoning.","type":"invalid_request_error"}}')
+ assert _effort_shape_refused(refusal)
+ assert not _effort_shape_refused(b'{"error":{"message":"Function tools with reasoning_effort are not supported"}}')
+ assert not _effort_shape_refused(b"")
+ body = json.dumps({"model": "claude-opus-5", "reasoning_effort": "high", "messages": []}).encode()
+ assert json.loads(_without_field(body, "reasoning_effort")) == {"model": "claude-opus-5", "messages": []}
diff --git a/runner/openhands_driver.py b/runner/openhands_driver.py
index 349c900d..3ca05328 100644
--- a/runner/openhands_driver.py
+++ b/runner/openhands_driver.py
@@ -227,16 +227,7 @@ def _agent_spec(job: dict) -> dict:
# still cover a blip. Persisted with the agent like the rest of the spec.
spec: dict = {"llm": {"model": job["model"], "base_url": None, "usage_id": "harness",
"num_retries": 2, "retry_min_wait": 2, "retry_max_wait": 8,
- "retry_multiplier": 2,
- # The SDK sends its reasoning effort to a Claude model as extended
- # thinking, and picks the shape from LiteLLM's model metadata; a model
- # served through the proxy under our own id has none, so the legacy
- # `thinking.type: enabled` went out and Anthropic refused every Claude
- # model in the catalog ("not supported for this model. Use adaptive and
- # output_config.effort", hosted, 2026-09-28). The override names the
- # shape Anthropic takes now.
- **({"capability_overrides": {"thinking_mode": "adaptive"}}
- if str(job["model"]).rsplit("/", 1)[-1].startswith("claude-") else {})},
+ "retry_multiplier": 2},
"tools": tools,
# THE AGENT DOC IS CONTEXT, NOT A FILE THE MODEL MAY OR MAY NOT OPEN. The SDK
# loads the workspace's AGENTS.md (and .agents/skills/) as repo skills only when
diff --git a/runner/tests/test_openhands_backend.py b/runner/tests/test_openhands_backend.py
index 70aa2c26..cac5f9c3 100644
--- a/runner/tests/test_openhands_backend.py
+++ b/runner/tests/test_openhands_backend.py
@@ -494,13 +494,3 @@ def test_a_file_editor_view_is_a_read_card():
assert call[0][1]["name"] == "Edit"
-
-def test_a_claude_model_is_told_its_thinking_shape_and_others_are_not():
- """Anthropic refused every Claude model behind the proxy with "thinking.type: enabled is not
- supported for this model. Use adaptive and output_config.effort" (hosted, 2026-09-28): the SDK
- reads the shape off LiteLLM's metadata, which knows nothing of a model served under our id.
- The spec names the shape for a Claude model and says nothing otherwise."""
- for m in ("litellm_proxy/claude-opus-5", "litellm_proxy/claude-sonnet-5", "claude-fable-5-1"):
- assert drv._agent_spec({"model": m})["llm"]["capability_overrides"] == {"thinking_mode": "adaptive"}, m
- for m in ("litellm_proxy/gpt-5.4", "openai/gpt-5.5", "deepseek-v4-pro", "kimi-k3"):
- assert "capability_overrides" not in drv._agent_spec({"model": m})["llm"], m