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
UHP: a task names its environment in metadata, where the harness is named (#331)
github-actions[bot]707f81dab8b8
diff --git a/docs/environments.md b/docs/environments.mdindex d64a8d94..9bf2c2b7 100644--- a/docs/environments.md+++ b/docs/environments.md@@ -76,7 +76,7 @@ harness object and on `POST /v1/responses`; `environment` on the session object.modes still hold for any non-root agent; root is the operator's own choice. Measured onhr-test 2026-09-28: before the groups, any session could list and read every environment'ssource and layers; after, a session reads its own and gets EACCES on the others.-- **The turn**: the gateway resolves the environment (request field, else the harness's) before+- **The turn**: the gateway resolves the environment (`metadata.environment` on the request, else the harness's) beforeanything is allocated, passes `{id, slug, entry}` to the runner, stamps the session vertex with`environment` and the turn record with the version. The runner resolves the mount before writingthe agent doc (a 409 there fails the turn before any process starts), then sets the variables.diff --git a/gateway/app.py b/gateway/app.pyindex dd19a4aa..f8a40661 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -5491,6 +5491,7 @@ class _RespTranslator:self.requested_model = ""self.model_fallback = Falseself.fallback_reason = ""+ self.environment = "" # the environment id the turn read: reported beside session_id# The connection that served this turn, stamped when the sandbox is dispatched. The session's# last_connection carried it before, one value per session; the turns feed and the support# matrix read it per turn (a report that said "every turn record" was reading the session).@@ -5513,6 +5514,8 @@ class _RespTranslator:meta: dict = {}if self.sid:meta["session_id"] = self.sid+ if self.environment:+ meta["environment"] = self.environment# run metadata: expose the effective vs requested model + fallback, so a caller can see the# gateway ran a different (authorized) model than it asked for.if self.requested_model and self.requested_model != self.model:@@ -7889,7 +7892,6 @@ class CreateResponseBody(BaseModel):backend: str | None = None # non-OpenAI convenience: force codex|claudemax_step: int | None = None # per-request agent step budget (claude --max-turns)timeout_seconds: int | None = None # per-request wall-clock cap for the turn- environment: str | None = None # an environment id for this task; overrides the harness's (UHP Environments)_IDEM_TERMINAL = {"completed", "failed", "incomplete", "cancelled", "error"}@@ -7980,7 +7982,7 @@ async def create_response(body: CreateResponseBody, request: Request):# The project layer this task reads: the request's, else the harness's. Resolved and checked# here, before anything is allocated, so a missing or unbuilt environment is a 4xx and not a# failed turn.- environment = await _environment_for_turn(org, body.environment or str((hv or {}).get("environment") or ""))+ environment = await _environment_for_turn(org, _task_environment_ref(body, 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@@ -8163,6 +8165,7 @@ async def create_response(body: CreateResponseBody, request: Request):_ignored = [f for f in ("tools", "include") if getattr(body, f, None) is not None]tr = _RespTranslator(resp_id, model_req or body.model or backend, body.previous_response_id, body.store, created_at, sid=sid, ignored=_ignored)tr.requested_model, tr.model_fallback, tr.fallback_reason = requested_model, model_fallback, model_fallback_reason+ tr.environment = str((environment or {}).get("id") or "")# Broadcast a synthetic turn-start so the bus alone can render a conversation turn from# scratch (the native Responses events don't echo the user's prompt).@@ -15394,6 +15397,13 @@ async def _environment_check_ref(org: str, env_id: str | None) -> None:raise uhp_error(404, "environment_not_found", "No environment with that id.", "environment")+def _task_environment_ref(body, hv: dict | None) -> str:+ """The environment a task reads: `metadata.environment` on the request (the Responses surface's+ extension point, where `harness_id` also travels: environments.md §5), else the harness's."""+ meta = getattr(body, "metadata", None) or {}+ return str(meta.get("environment") or (hv or {}).get("environment") or "").strip()++async def _environment_for_turn(org: str, env_id: str) -> dict | None:"""What a task reads, checked before the turn starts: the environment exists in this org andhas a built version. Returns {id, slug, entry, version, path} or None for a task with none."""diff --git a/gateway/tests/test_environments.py b/gateway/tests/test_environments.pyindex 28a479a1..d62a9dec 100644--- a/gateway/tests/test_environments.py+++ b/gateway/tests/test_environments.py@@ -192,3 +192,15 @@ def test_declared_packages_and_the_runtime_are_kept_and_handed_to_the_build(api,monkeypatch.setattr(app, "_env_runner", real)r = api.get("/v1/environments/runtimes")assert r.status_code == 200 and isinstance(r.json().get("python"), list) and "os" in r.json()+++def test_the_task_names_its_environment_in_metadata_like_the_harness():+ """The task request is a Responses request: its environment travels in metadata beside+ harness_id (environments.md §5), never as a top-level field; the harness's is the default."""+ from types import SimpleNamespace as NS+ hv = {"environment": "henv_harness"}+ assert app._task_environment_ref(NS(metadata={"harness_id": "chrn_1", "environment": "henv_task"}), hv) == "henv_task"+ assert app._task_environment_ref(NS(metadata={"harness_id": "chrn_1"}), hv) == "henv_harness"+ assert app._task_environment_ref(NS(metadata=None), hv) == "henv_harness"+ assert app._task_environment_ref(NS(metadata={}), None) == ""+ assert not hasattr(app.CreateResponseBody.model_fields, "environment") and "environment" not in app.CreateResponseBody.model_fieldsdiff --git a/protocol/conformance/pyproject.toml b/protocol/conformance/pyproject.tomlindex aa8a0e78..b12a3835 100644--- a/protocol/conformance/pyproject.toml+++ b/protocol/conformance/pyproject.toml@@ -1,6 +1,6 @@[project]name = "uhp-conformance"-version = "2026.9.28"+version = "2026.9.28.post1"description = "Conformance suite for the Unified Harness Protocol (UHP)"readme = "README.md"requires-python = ">=3.10"diff --git a/protocol/conformance/uhp_conformance/checks.py b/protocol/conformance/uhp_conformance/checks.pyindex 16575d51..759176ec 100644--- a/protocol/conformance/uhp_conformance/checks.py+++ b/protocol/conformance/uhp_conformance/checks.py@@ -1868,8 +1868,8 @@ def en05(ctx):ctx.client.delete(f"/v1/harnesses/{(r.json or {}).get('id')}")empty = ctx.client.post("/v1/environments", body={"name": f"uhp-conformance-empty-{uuid.uuid4().hex[:6]}"}).json or {}ctx.state.setdefault("_cleanup_environments", []).append(empty.get("id"))- r = ctx.client.post("/v1/responses", body={"input": PROMPT, "metadata": {"harness_id": h["id"]},- "environment": empty.get("id"), "stream": False})+ r = ctx.client.post("/v1/responses", body={"input": PROMPT, "stream": False,+ "metadata": {"harness_id": h["id"], "environment": empty.get("id")}})assert r.status == 409 and _error_code(r) == "environment_not_ready", (f"a task on an environment with nothing built must be refused with environment_not_ready before it starts: HTTP {r.status} {_error_code(r)!r}")return "harness reference reads back; unknown refused; unbuilt refused"@@ -1905,11 +1905,13 @@ def en07(ctx):assert "hello from the environment" in text, f"the agent could not read the file at {mount}: {text[-300:]!r}"assert "WRITE_RC=0" not in text or "denied" in text.lower() or "read-only" in text.lower(), (f"a write under {mount} must fail (the layer is read-only): {text[-300:]!r}")- sid = str(((resp.get("metadata") or {}).get("session_id")) or "")+ meta = resp.get("metadata") or {}+ assert meta.get("environment") == e["id"], f"the response must name the environment the task read in metadata.environment: {meta.get('environment')!r}"+ sid = str(meta.get("session_id") or "")if sid:s = ctx.client.get(f"/v1/sessions/{sid}").json or {}assert s.get("environment") == e["id"], f"the session must name the environment its turn read: {s.get('environment')!r}"- return f"read {mount}/data/hello.txt; write refused"+ return f"read {mount}/data/hello.txt; write refused; metadata.environment reported"@check("EN-08", "Configured environments are cleaned up", "full", f"{SPEC}/environments.md#2-the-environment-object")diff --git a/protocol/conformance/uhp_conformance/uhp-2026-09-28.schema.json b/protocol/conformance/uhp_conformance/uhp-2026-09-28.schema.jsonindex 7089aebe..b6a08ecd 100644--- a/protocol/conformance/uhp_conformance/uhp-2026-09-28.schema.json+++ b/protocol/conformance/uhp_conformance/uhp-2026-09-28.schema.json@@ -731,10 +731,13 @@},"metadata": {"type": "object",- "description": "Client metadata. `harness_id` selects the configured harness.",+ "description": "Client metadata, the extension point of the Responses surface. `harness_id` selects the\nconfigured harness; `environment` names the environment this task reads, overriding the\nharness's (capability `environments`), refused with `environment_not_found` or\n`environment_not_ready` before the task starts.\n","properties": {"harness_id": {"type": "string"+ },+ "environment": {+ "type": "string"}},"additionalProperties": true@@ -776,10 +779,6 @@],"description": "Wall-clock budget"},- "environment": {- "type": "string",- "description": "The environment this task reads, overriding the harness's. Refused with\n`environment_not_found` or `environment_not_ready` before the task starts.\n"- },"tools": {"type": "array","items": {@@ -882,6 +881,10 @@"session_id": {"type": "string"},+ "environment": {+ "type": "string",+ "description": "The environment the task read, when it read one (capability `environments`)."+ },"requested_model": {"type": "string","description": "Present when the server ran a different model than was requested."diff --git a/protocol/schema/uhp-2026-09-28.openapi.yaml b/protocol/schema/uhp-2026-09-28.openapi.yamlindex 6337b089..50beaa66 100644--- a/protocol/schema/uhp-2026-09-28.openapi.yaml+++ b/protocol/schema/uhp-2026-09-28.openapi.yaml@@ -1420,9 +1420,14 @@ components:model: { type: string, description: Canonical model id. Omitted means the harness default. }metadata:type: object- description: Client metadata. `harness_id` selects the configured harness.+ description: |+ Client metadata, the extension point of the Responses surface. `harness_id` selects the+ configured harness; `environment` names the environment this task reads, overriding the+ harness's (capability `environments`), refused with `environment_not_found` or+ `environment_not_ready` before the task starts.properties:harness_id: { type: string }+ environment: { type: string }additionalProperties: truestream: { type: boolean, default: false }previous_response_id: { type: [string, 'null'] }@@ -1431,11 +1436,6 @@ components:max_output_tokens: { type: [integer, 'null'] }max_step: { type: [integer, 'null'], description: Agent step (tool-call round) budget }timeout_seconds: { type: [integer, 'null'], description: Wall-clock budget }- environment:- type: string- description: |- The environment this task reads, overriding the harness's. Refused with- `environment_not_found` or `environment_not_ready` before the task starts.tools:type: arrayitems: { type: object, additionalProperties: true }@@ -1486,6 +1486,9 @@ components:type: objectproperties:session_id: { type: string }+ environment:+ type: string+ description: The environment the task read, when it read one (capability `environments`).requested_model:type: stringdescription: Present when the server ran a different model than was requested.diff --git a/protocol/schema/uhp-2026-09-28.schema.json b/protocol/schema/uhp-2026-09-28.schema.jsonindex 7089aebe..b6a08ecd 100644--- a/protocol/schema/uhp-2026-09-28.schema.json+++ b/protocol/schema/uhp-2026-09-28.schema.json@@ -731,10 +731,13 @@},"metadata": {"type": "object",- "description": "Client metadata. `harness_id` selects the configured harness.",+ "description": "Client metadata, the extension point of the Responses surface. `harness_id` selects the\nconfigured harness; `environment` names the environment this task reads, overriding the\nharness's (capability `environments`), refused with `environment_not_found` or\n`environment_not_ready` before the task starts.\n","properties": {"harness_id": {"type": "string"+ },+ "environment": {+ "type": "string"}},"additionalProperties": true@@ -776,10 +779,6 @@],"description": "Wall-clock budget"},- "environment": {- "type": "string",- "description": "The environment this task reads, overriding the harness's. Refused with\n`environment_not_found` or `environment_not_ready` before the task starts.\n"- },"tools": {"type": "array","items": {@@ -882,6 +881,10 @@"session_id": {"type": "string"},+ "environment": {+ "type": "string",+ "description": "The environment the task read, when it read one (capability `environments`)."+ },"requested_model": {"type": "string","description": "Present when the server ran a different model than was requested."diff --git a/protocol/versions/2026-09-28/environments.md b/protocol/versions/2026-09-28/environments.mdindex ff84a2ed..1bc01618 100644--- a/protocol/versions/2026-09-28/environments.md+++ b/protocol/versions/2026-09-28/environments.md@@ -198,12 +198,21 @@ A harness names the environment its tasks read, and a task may name a different``````json-{ "input": "Render the teaser for episode 12.", "metadata": { "harness_id": "chrn_…" },- "environment": "henv_2f1c9d4e8a7b4c3d9e6f5a4b3c2d1e0f" }+{ "input": "Render the teaser for episode 12.",+ "metadata": { "harness_id": "chrn_…", "environment": "henv_2f1c9d4e8a7b4c3d9e6f5a4b3c2d1e0f" } }```- `environment` on a harness ([Harnesses §2](harnesses.md#2-the-harness-object)) is the default- for every task of that harness; the task's own field overrides it for that task.+ for every task of that harness; `metadata.environment` on a task overrides it for that task.+ The response reports the environment the task read as `metadata.environment`, beside+ `metadata.session_id`.++> **Why is the task's environment in `metadata` rather than a top-level field?**+> For the reason the harness is ([Tasks §1.2](tasks.md#12-selecting-a-harness)): the task surface+> is a Responses request, and `metadata` is the extension point that surface defines for+> caller-supplied context. A harness and a session are this protocol's own objects, so on them+> `environment` is an ordinary field; a task request is not, so on it the environment travels+> where the harness does. Every Responses SDK can send it today.- A server MUST refuse a harness write that names an environment outside the caller's scope, ornone at all, with `environment_not_found`.- A server MUST refuse a task whose environment is not `ready` **before the task starts**:@@ -226,9 +235,9 @@ For a task that runs with an environment, a server MUST:`NODE_PATH` begin with the environment, `PROJECT_ROOT` names `mount`;4. tell the agent, in its instructions, where the project is, that it is read-only and shared, thatits dependencies are installed, where to write, and the `entry` when the owner gave one;-5. record which environment and version the turn read: the session object carries- `environment` ([Sessions §3](sessions.md#3-inspecting-a-session)), and the turn's record the- version.+5. record which environment and version the turn read: the response carries+ `metadata.environment`, the session object carries `environment`+ ([Sessions §3](sessions.md#3-inspecting-a-session)), and the turn's record the version.Two sessions on one environment MUST NOT be able to read each other's working directory or writethe environment. A session MUST NOT be able to read an environment its task did not name, nor to