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: Codex compacts locally; a refused key is judged on the provider's first line (#73)
github-actions[bot]3e8cda6f0502
diff --git a/gateway/app.py b/gateway/app.pyindex 7cfb3bb6..b96e8443 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -2945,6 +2945,14 @@ _PROVIDER_REFUSAL_RE = re.compile(r"\b(401|403|429)\b|unauthori[sz]ed|incorrectr"insufficient_quota|rate limit|quota|forbidden|refused", re.IGNORECASE)+def _provider_refused(err: str) -> bool:+ """Whether a failure on the org's own connection is the provider refusing the key. Judged on+ the first line only: that is the line the runner chose as the provider's answer, and a+ diagnostic further down (a retry, a JSON body, an earlier label) must not turn a Codex+ compaction failure or a bad request into "your key was refused"."""+ return bool(_PROVIDER_REFUSAL_RE.search((err or "").split("\n", 1)[0]))++def _turn_failure_message(rec: dict) -> str:"""What a failed turn says: the org's own key's refusal in plain words when that is why, elsethe list of connections tried."""@@ -5704,7 +5712,7 @@ async def _resp_execute(translator: _RespTranslator, *, org: str, member: str, sbreak_last_err = str(rec["tried"][-1].get("error") or "") if rec["tried"] else ""if (not terminal and rec["tried"] and rec["tried"][-1].get("connection") == name- and rec["tried"][-1].get("status") and _PROVIDER_REFUSAL_RE.search(_last_err)):+ and rec["tried"][-1].get("status") and _provider_refused(_last_err)):# The provider refused this key. That is configuration, not an outage to route around:# falling through to the next connection ran the task on another key while the user# believed this one worked. On a self-hosted install every key is the operator's own,diff --git a/gateway/tests/test_turn_failure_message.py b/gateway/tests/test_turn_failure_message.pyindex dd1443e0..7811a127 100644--- a/gateway/tests/test_turn_failure_message.py+++ b/gateway/tests/test_turn_failure_message.py@@ -25,3 +25,13 @@ def test_nothing_tried_still_says_something():def test_only_a_refusal_reads_as_a_refused_key():assert gw._PROVIDER_REFUSAL_RE.search("OpenAI API error (401): invalid api key")assert not gw._PROVIDER_REFUSAL_RE.search("no rollout found for thread id 01a06ea9")+++def test_refusal_is_judged_on_the_providers_first_line_only():+ compact = ("ERROR codex_core::session::turn: Failed to run pre-sampling compact\n"+ "Error running remote compact task: { \"error\": { \"message\": \"X-OpenAI-Internal-Codex-Responses-Lite "+ "requires `reasoning.context` to be `all_turns`.\", \"type\": \"invalid_request_error\" } }\n"+ "Reconnecting... 1/5 (rate limit? no: quota)")+ 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")diff --git a/runner/server.py b/runner/server.pyindex 0f55406f..9e491b1b 100644--- a/runner/server.py+++ b/runner/server.py@@ -363,7 +363,9 @@ QWEN_DEFAULT_MODEL = os.environ.get("QWEN_DEFAULT_MODEL", "qwen3.7-max")CLINE_DEFAULT_MODEL = os.environ.get("CLINE_DEFAULT_MODEL", "gpt-5.4")DSH_DEFAULT_MODEL = os.environ.get("DSH_DEFAULT_MODEL", "deepseek-v4-pro")CODEX_REASONING_EFFORT = os.environ.get("CODEX_REASONING_EFFORT", "medium")-CODEX_CONTEXT_WINDOW = os.environ.get("CODEX_CONTEXT_WINDOW", "400000")+# The window Codex plans compaction against. Its own catalog says 272k for every gpt-5.x; a larger+# number here made it compact late and let a long thread overflow the real window first.+CODEX_CONTEXT_WINDOW = os.environ.get("CODEX_CONTEXT_WINDOW", "272000")# Provider defaults (overridable per-turn via auth.base_url). Wired from pool env.OPENAI_BASE_URL = os.environ.get("OPENAI_BASE_URL", "https://api.openai.com/v1")AZURE_OPENAI_BASE_URL = os.environ.get("AZURE_OPENAI_BASE_URL", "")@@ -1257,6 +1259,12 @@ model_reasoning_effort = "{effort}"approval_policy = "never"sandbox_mode = "danger-full-access"model_context_window = {ctx}+[features]+# Compaction happens locally. Remote compaction is a call to OpenAI's own backend+# (/responses/compact under the Responses-Lite header) that an API key at api.openai.com refused+# ("requires reasoning.context to be all_turns") and that Azure, TokenRouter, OpenRouter and+# Vercel do not serve at all; local compaction works on every provider we front.+remote_compaction_v2 = false[model_providers.{provider}]name = "{name}"base_url = "{base_url}"diff --git a/runner/tests/test_codex_reasoning_strip.py b/runner/tests/test_codex_reasoning_strip.pyindex a3cdd2d3..6e8aad88 100644--- a/runner/tests/test_codex_reasoning_strip.py+++ b/runner/tests/test_codex_reasoning_strip.py@@ -199,3 +199,15 @@ def test_app_server_resumes_the_rollout_that_is_here(tmp_path):(sess / "rollout-b.jsonl").write_text('{"type": "session_meta", "payload": {"id": "t-new"}}\n')assert _codex_resume_thread_id(home, "t-old") == "t-old", "the wanted rollout is here"assert _codex_resume_thread_id(home, "t-missing") == "t-new", "not here: the newest rollout is this conversation"+++def test_codex_config_compacts_locally(tmp_path, monkeypatch):+ """Remote compaction is off in every Codex config the runner writes: it is an OpenAI-backend+ call that other providers do not serve and that an API key was refused on."""+ import server as rs+ env = {"HOME": str(tmp_path)}+ cfg_dir = rs._codex_prepare_env("openai", rs.Auth(api_key="k"), "gpt-5.5", str(tmp_path), env)+ cfg = (cfg_dir / "config.toml").read_text()+ assert "[features]\n" in cfg and "remote_compaction_v2 = false" in cfg+ import tomllib+ assert tomllib.loads(cfg)["features"]["remote_compaction_v2"] is False