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.

fix(gateway): the word refused is not a key refusal (#78)

github-actions[bot]0c4f3b99218b
diff --git a/gateway/app.py b/gateway/app.py
index 4c17c5f7..a69db9b5 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -2949,7 +2949,7 @@ def _with_provider_base(conn: dict | None) -> dict | None:
_PROVIDER_REFUSAL_RE = re.compile(r"\b(401|403|429)\b|unauthori[sz]ed|incorrect api key|invalid_api_key|invalid api key|"
- r"insufficient_quota|rate limit|quota|forbidden|refused", re.IGNORECASE)
+ r"insufficient_quota|rate limit|quota|forbidden", re.IGNORECASE)
def _provider_refused(err: str) -> bool:
diff --git a/gateway/tests/test_turn_failure_message.py b/gateway/tests/test_turn_failure_message.py
index 7811a127..e91f5a5d 100644
--- a/gateway/tests/test_turn_failure_message.py
+++ b/gateway/tests/test_turn_failure_message.py
@@ -35,3 +35,12 @@ def test_refusal_is_judged_on_the_providers_first_line_only():
assert not gw._provider_refused(compact)
assert gw._provider_refused("OpenAI API error (401): Incorrect API key provided")
assert gw._provider_refused("Error: 429 insufficient_quota\nReconnecting... 1/5")
+
+
+def test_a_models_content_refusal_is_not_a_key_refusal():
+ # pi, glm-5.3-flash switching to claude-opus-5 on the OSS matrix (2026-09-06): the provider's
+ # first line was "The model refused to complete the request", and the word alone read as a
+ # refused key. A key refusal is an auth or quota line, never the word.
+ assert not gw._provider_refused("The model refused to complete the request")
+ assert not gw._provider_refused("Your tokenrouter key was refused: The model refused to complete the request")
+ assert gw._provider_refused("403 Forbidden: key disabled")