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
A backend wired to one provider runs through the integration that can drive it (#109)
github-actions[bot]c1d723cfd6fb
diff --git a/gateway/app.py b/gateway/app.pyindex 1c3009f4..3024ce37 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -1284,6 +1284,28 @@ def _codex_switch_refusal(models_seen, model_req: str) -> str:f"its tools are not available there. Start a new task for {model_req}.")+def _integration_driving(integrations: list[dict], backend: str, canonical: str, mapped: str | None) -> dict | None:+ """The integration a turn on `backend` for `canonical` runs through: the org's mapping when+ that integration can drive the backend, else the first integration on the org (by name) that+ can and serves the id. The map is the org's choice per model, made once for every backend; a+ backend wired to one provider (gemini: google) cannot honour a mapping to an aggregator, and+ without this fall-through it was unusable whenever the map named one, which the map does by+ default (measured 2026-09-06 on 0.13.24: every gemini backend id unavailable, the picker+ greyed, while the same ids ran when the map pointed at the Google integration)."""+ by_name = {str(i.get("name") or ""): i for i in integrations}+ first = by_name.get(mapped or "")+ if first is not None and _integration_serves_backend(first, backend):+ return first+ canon = (canonical or "").strip()+ for integ in sorted(integrations, key=lambda i: str(i.get("name") or "")):+ if integ is first or not _integration_serves_backend(integ, backend):+ continue+ models = _integration_models(integ)+ if canon in models or canon.lower() in models:+ return integ+ return None++async def _mapped_integration_conn(backend: str, canonical: str) -> dict | None:"""The synthetic connection for a model→integration mapping, or None when unmapped /unusable by this backend. Shaped exactly like a vault connection so the turn loop treats@@ -1295,11 +1317,10 @@ async def _mapped_integration_conn(backend: str, canonical: str) -> dict | None:iname = mm.get(canon) or mm.get(canon.lower())if not iname:return None- integ = next((i for i in await _integrations_doc() if (i.get("name") or "") == iname), None)+ integ = _integration_driving(await _integrations_doc(), backend, canon, iname)if not integ:return None- if not _integration_serves_backend(integ, backend):- return None+ iname = str(integ.get("name") or "")provider = _INTEGRATION_WIRING.get(((integ.get("provider") or "").lower(), backend))if not provider:return None@@ -5741,9 +5762,9 @@ async def _servable_models(org: str | None, backend: str) -> set[str] | None:if not table:return Noneservable |= set(table)+ integ_list = list(integrations.values())for canonical, iname in (await _effective_model_map()).items():- integ = integrations.get(iname)- if integ and _integration_serves_backend(integ, backend):+ if _integration_driving(integ_list, backend, canonical, iname):servable.add(canonical)return servablediff --git a/gateway/tests/test_backend_restricted_wiring.py b/gateway/tests/test_backend_restricted_wiring.pynew file mode 100644index 00000000..8f1911dc--- /dev/null+++ b/gateway/tests/test_backend_restricted_wiring.py@@ -0,0 +1,39 @@+"""A backend wired to one provider runs through the integration that can drive it, even when the org's+model map names one that cannot (2026-09-06: the gemini backend on a default map)."""+import asyncio+import sys+from pathlib import Path++sys.path.insert(0, str(Path(__file__).resolve().parents[1]))+import app as gw # noqa: E402++VERCEL = {"name": "Vercel AI Gateway", "provider": "vercel", "config": {"api_key": "v", "base_url": "https://ai-gateway.vercel.sh/v1"}}+GOOGLE = {"name": "Google AI Studio", "provider": "google", "config": {"api_key": "g", "base_url": "https://generativelanguage.googleapis.com/v1beta/openai"}}+++def test_the_mapped_integration_is_kept_when_it_drives_the_backend():+ assert gw._integration_driving([GOOGLE, VERCEL], "pi", "gemini-3.5-flash", "Vercel AI Gateway") is VERCEL+++def test_a_backend_the_mapping_cannot_drive_falls_through_to_one_that_can():+ assert gw._integration_driving([VERCEL, GOOGLE], "gemini", "gemini-3.5-flash", "Vercel AI Gateway") is GOOGLE+ assert gw._integration_driving([VERCEL], "gemini", "gemini-3.5-flash", "Vercel AI Gateway") is None+ # an integration that can drive the backend but does not serve the id is not it+ assert gw._integration_driving([VERCEL, GOOGLE], "gemini", "gpt-5.4", "Vercel AI Gateway") is None+++def test_the_turn_and_the_picker_agree(monkeypatch):+ async def mm(): return {"gemini-3.5-flash": "Vercel AI Gateway", "gpt-5.4": "Vercel AI Gateway"}+ async def docs(): return [VERCEL, GOOGLE]+ async def chain(org, backend, _): return []+ monkeypatch.setattr(gw, "_effective_model_map", mm)+ monkeypatch.setattr(gw, "_integrations_doc", docs)+ monkeypatch.setattr(gw, "_resolve_chain", chain)+ conn = asyncio.run(gw._mapped_integration_conn("gemini", "gemini-3.5-flash"))+ assert conn and conn["name"] == "integration:Google AI Studio" and conn["provider"] == "google"+ assert conn.get("model") == "gemini-3.5-flash"+ assert asyncio.run(gw._mapped_integration_conn("gemini", "gpt-5.4")) is None+ servable = asyncio.run(gw._servable_models("org1", "gemini"))+ assert "gemini-3.5-flash" in servable and "gpt-5.4" not in servable+ pi = asyncio.run(gw._mapped_integration_conn("pi", "gemini-3.5-flash"))+ assert pi and pi["name"] == "integration:Vercel AI Gateway"