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
gateway: a chain connection is held to an integration's rule before the runner is called
richard-epsillab7912301c1d0
diff --git a/docs/self-hosting-guide.md b/docs/self-hosting-guide.mdindex 83111265..eeecec57 100644--- a/docs/self-hosting-guide.md+++ b/docs/self-hosting-guide.md@@ -327,9 +327,11 @@ OpenAI-compatible endpoint of your own takes the same pair with a `base_url` add-e HR_SECRET_GLOBAL_HARNESS_POLICY_CODEX='{"chain":["local"]}'```-Not every provider fits every backend, and a pairing that does not fit fails quietly: the turn-comes back empty after a long wait rather than erroring. The Integrations page does not have this-problem, because it only offers you providers that work.+Not every provider fits every backend. A pairing that does not fit is refused before the runner+is called, and the response's error names the connection and why (`a custom endpoint in the+openai format cannot drive codex, which speaks the responses format`); a provider the runner+itself refuses is answered at once with the runner's own sentence. The Integrations page only+offers you providers that work.| Connection `provider` | Backends that can use it ||---|---|diff --git a/gateway/app.py b/gateway/app.pyindex 28b76731..402ae3b6 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -4863,6 +4863,42 @@ def _integration_serves_backend(integ: dict, backend: str) -> bool:return bool(_INTEGRATION_WIRING.get((provider, backend)))+def _chain_refusal(conn: dict, backend: str) -> str:+ """Why a chain connection cannot drive `backend`, in the operator's words, or "" when it can.++ A connection from the environment (HR_SECRET_GLOBAL_HARNESS_CONN_*) in the integrations'+ vocabulary is held to the rule an integration is held to, in the same place: it drives a+ backend only where the wiring says so, and a custom endpoint only in a format the backend+ speaks. A provider the catalog does not know (a runner-native name such as openai-api or+ azure) passes, and the runner remains its judge, as before. Until this, a chain connection+ was sent to the runner verbatim, so a `custom` connector reached it as a provider no backend+ has and the refusal came back in the runner's vocabulary (#201)."""+ provider = str(conn.get("provider") or "").lower()+ if provider not in _PROVIDER_CATALOG:+ return ""+ if provider == "custom":+ fmt = str(conn.get("api_format") or "").strip().lower()+ if fmt not in _CUSTOM_FORMAT_BACKENDS:+ return f"a custom endpoint needs api_format, one of {', '.join(sorted(_CUSTOM_FORMAT_BACKENDS))}"+ if backend not in _CUSTOM_FORMAT_BACKENDS[fmt]:+ speaks = sorted(f for f, bs in _CUSTOM_FORMAT_BACKENDS.items() if backend in bs)+ return (f"a custom endpoint in the {fmt} format cannot drive {backend}, which speaks "+ + (f"the {' or '.join(speaks)} format" if speaks else "no custom format"))+ return ""+ if not _INTEGRATION_WIRING.get((provider, backend)):+ can = sorted({p for (p, b) in _INTEGRATION_WIRING if b == backend and p in _PROVIDER_CATALOG})+ return f"provider {provider} cannot drive {backend}; providers that can: {', '.join(can) or 'none'}"+ return ""+++def _chain_wired(conn: dict, backend: str) -> dict:+ """The chain connection under the runner's own name for its provider, as an integration is+ sent (see _integration_conn); api_format rides along for the backends that read it."""+ provider = str(conn.get("provider") or "").lower()+ mapped = _INTEGRATION_WIRING.get((provider, backend)) if provider in _PROVIDER_CATALOG else None+ return {**conn, "provider": mapped} if mapped and mapped != provider else conn++# Built-in agent tools an endpoint may refuse (a proxy that gates codex's web_search per model,# issue #150): named on the connection, comma-separated, and joined to the harness's own list on# every turn through it. Offered wherever a codex-driving provider is configured.@@ -7114,6 +7150,17 @@ async def _resp_execute(translator: _RespTranslator, *, org: str, member: str, s# the connection's default model).rec["tried"].append({"connection": name, "error": f"provider does not serve '{model_req}'"})continue+ if pre is None:+ # The rule an integration is held to, applied to a chain connection in the same+ # vocabulary: a pairing the backend cannot speak is refused here, before the runner+ # is called, in the operator's words, and the provider reaches the runner under the+ # runner's own name (#201: a custom connector went verbatim as "custom", a provider+ # no backend has, and the runner's refusal was retried for five minutes).+ why = _chain_refusal(conn, backend)+ if why:+ rec["tried"].append({"connection": name, "error": why})+ continue+ conn = _chain_wired(conn, backend)sandbox_auth = _auth_from_conn(conn, sid)if sandbox_auth is None:# Refusing beats running: the only alternative is handing the sandbox a real providerdiff --git a/gateway/tests/test_chain_pairing.py b/gateway/tests/test_chain_pairing.pynew file mode 100644index 00000000..e94b874d--- /dev/null+++ b/gateway/tests/test_chain_pairing.py@@ -0,0 +1,48 @@+"""A chain connection is held to the rule an integration is held to, before the runner is called.++The runner knows no provider called "custom": an integration maps it through the wiring to the+runner's own name (tokenrouter, openai-api) with api_format beside it, but a chain connection from+HR_SECRET_GLOBAL_HARNESS_CONN_* was sent verbatim, so a custom connector reached the runner as a+provider no backend has and its refusal came back in the runner's vocabulary (#201, reported by+master5d). The refusal is decided here, in the operator's words, and the provider is mapped as+an integration's is."""+import os+import pathlib+import sys++sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))+os.environ.setdefault("HR_BACKING", "local")+import app as gw # noqa: E402+++def test_a_custom_chat_endpoint_cannot_drive_codex_and_the_reason_is_in_the_operators_words():+ conn = {"name": "x", "provider": "custom", "api_format": "openai", "base_url": "http://h:4000/v1", "api_key": "k"}+ why = gw._chain_refusal(conn, "codex")+ assert why == "a custom endpoint in the openai format cannot drive codex, which speaks the responses format"+ assert gw._chain_refusal({**conn, "api_format": "responses"}, "codex") == ""+++def test_a_custom_endpoint_without_a_format_is_told_what_it_needs():+ assert gw._chain_refusal({"provider": "custom", "base_url": "http://h/v1"}, "pi").startswith("a custom endpoint needs api_format")+++def test_a_custom_endpoint_reaches_the_runner_under_the_runners_name_with_its_format():+ conn = {"name": "x", "provider": "custom", "api_format": "openai", "base_url": "http://h/v1", "api_key": "k"}+ for backend in ("pi", "hermes", "aider", "codex"):+ assert gw._chain_refusal({**conn, "api_format": "openai" if backend != "codex" else "responses"}, backend) == ""+ wired = gw._chain_wired({**conn, "api_format": "openai" if backend != "codex" else "responses"}, backend)+ assert wired["provider"] == gw._INTEGRATION_WIRING[("custom", backend)] and wired["api_format"]+ assert wired["api_key"] == "k" and wired["base_url"] == "http://h/v1"+++def test_a_catalog_provider_is_refused_where_the_wiring_has_no_row_and_named_where_it_has_one():+ assert gw._chain_refusal({"provider": "openai"}, "codex") == "" and gw._chain_wired({"provider": "openai"}, "codex")["provider"] == "openai"+ assert gw._chain_wired({"provider": "openai"}, "hermes")["provider"] == "openai-api"+ why = gw._chain_refusal({"provider": "typesafe"}, "codex")+ assert why.startswith("provider typesafe cannot drive codex; providers that can:") and "openai" in why+++def test_a_runner_native_name_passes_untouched_and_the_runner_stays_its_judge():+ for conn in ({"provider": "openai-api", "base_url": "http://h/v1"}, {"provider": "azure"}, {"provider": "made-up"}):+ assert gw._chain_refusal(conn, "codex") == ""+ assert gw._chain_wired(conn, "codex") is conn