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 turn addressed to a harness that does not exist is refused, not run on the default (#252)

github-actions[bot]b5ac7844e8c4
diff --git a/gateway/app.py b/gateway/app.py
index 89107aca..9eaea966 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -2905,6 +2905,23 @@ async def _drain_inflight() -> None:
pass
+def _turn_harness_check(harness_id: str, hv: dict | None) -> None:
+ """A turn addressed to a harness runs on THAT harness or not at all. A deleted one answers the
+ same 404 as the read endpoints. An id that names no harness at all used to run as a turn with
+ no harness config, on the default backend, billed to the caller: a typo in a product's
+ configuration ran a generic agent and charged for it, and nothing said so (found by the
+ coding-agent plugin's own verification, 2026-09-23). A base id (codex, claude-code, ...) is a
+ harness without a vertex and stays allowed; anything else has to exist."""
+ if not harness_id:
+ return
+ if hv is None:
+ if harness_id in _BASE_CATALOG:
+ return
+ raise uhp_error(404, "harness_not_found", "No harness with that id.", "harness_id")
+ if str(hv.get("deleted")) in ("1", "true", "True"):
+ raise uhp_error(404, "harness_not_found", "No harness with that id.", "harness_id")
+
+
async def _harness_vertex(harness_id: str) -> dict | None:
"""Read a Harness vertex (HR tenant) as a flat dict — its config (mcp_servers, skills props)."""
# harness_id is caller-controlled (metadata / X-Harness-Id) and now drives BILLING — keep it to
@@ -7753,8 +7770,7 @@ async def create_response(body: CreateResponseBody, request: Request):
# ALLOWED — sibling products legitimately run a user's harness under a platform credential, and
# the marketplace model is exactly "callers run it, the owner pays infra". Until entitlements
# land, the unguessable harness id is the run capability.
- if hv and str(hv.get("deleted")) in ("1", "true", "True"):
- raise uhp_error(404, "harness_not_found", "No harness with that id.", "harness_id")
+ _turn_harness_check(harness_id, hv)
# HR-INF-023: credit admission. BILLING is the harness OWNER's org — the Developer who built the
# harness funds its infra consumption (hv["org"], stamped at harness creation), regardless of who
# calls it. A turn with no harness vertex (built-in, or an ad-hoc/chained turn that carries no
diff --git a/gateway/tests/test_turn_harness.py b/gateway/tests/test_turn_harness.py
new file mode 100644
index 00000000..a9b85a48
--- /dev/null
+++ b/gateway/tests/test_turn_harness.py
@@ -0,0 +1,25 @@
+"""A turn addressed to a harness runs on that harness or not at all."""
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+import pytest
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
+import app as gw # noqa: E402
+
+
+def test_an_unknown_harness_id_is_refused_and_a_base_id_or_no_id_is_not():
+ """A typo'd chrn_ id used to run on the default backend and bill the caller; now it is a 404 like
+ a deleted harness. A base id is a harness without a vertex and still runs; no id at all is an
+ ad-hoc turn and still runs."""
+ gw._turn_harness_check("", None)
+ base = next(iter(gw._BASE_CATALOG))
+ gw._turn_harness_check(base, None)
+ gw._turn_harness_check("chrn_0123456789abcdef", {"id": "chrn_0123456789abcdef", "org": "org.a", "deleted": "0"})
+ with pytest.raises(Exception) as e:
+ gw._turn_harness_check("chrn_doesnotexist0000", None)
+ assert "harness_not_found" in str(getattr(e.value, "detail", e.value)) or "No harness" in str(e.value)
+ with pytest.raises(Exception):
+ gw._turn_harness_check("chrn_0123456789abcdef", {"id": "chrn_0123456789abcdef", "deleted": "1"})