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, runner: a refused follow-up leaves the session alone; codex waits each MCP server's start-up (#188)
github-actions[bot]a3cdaa949e27
diff --git a/gateway/app.py b/gateway/app.pyindex 969db329..2edde026 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -2614,6 +2614,11 @@ async def _reconcile_response(rid: str, rec: dict) -> dict:v = await _vertex_get(sid) or {}vs = str(v.get("status") or "")settled = None+ if vs in ("done", "failed", "cancelled") and time.time() - _hb_seconds(v) < _RECONCILE_STALE_S:+ # The session is terminal but its owner heartbeated moments ago: the owner is finalizing+ # (collecting files, writing the checkpoint) and will write the full record itself,+ # output, usage and served model included. Only an orphan is settled from the session.+ return recif vs in ("done", "failed", "cancelled"):settled = _RESP_STATUS_MAP.get(vs)# "completed" is a claim about THIS response, not about the session. A record with no@@ -2631,9 +2636,7 @@ async def _reconcile_response(rid: str, rec: dict) -> dict:# sheets kit polled mid-finalize, was handed a terminal 'incomplete', and wrote "the# turn ended without an answer" into every cell of a run whose answers the agent had# already produced. Leave a live turn alone; the sweep still settles a dead one once- # the heartbeat goes stale.- if time.time() - _hb_seconds(v) < _RECONCILE_STALE_S:- return rec+ # the heartbeat goes stale (the guard above).settled = "incomplete"# NO reason is claimed here, deliberately. This branch cannot tell a turn that was# CUT (finalize died before the output landed) from one that ended cleanly having@@ -6624,12 +6627,12 @@ async def _resp_execute(translator: _RespTranslator, *, org: str, member: str, s# cancel_session resolve THIS turn's resp_id and latch the per-response cancel (the ONE cancel# mechanism), so the turn loop needs no per-poll vertex status read (HR-INF-010). Not re-written# here: accept already set it to this same resp_id and nothing clears it.- await _vertex_upsert(sid, {"status": "running", "turn_status": "starting",- "heartbeat": str(time.time()), "runner_turn_id": "",- **({"trace_blob": tr["prefix"]} if tr.get("prefix") else {})})# Session execution lease (HR-INF-012), acquired BEFORE hydrate — hydrate wipes /workspace, so# an overlapping turn is the real corruption risk. observe mode only LOGS a conflict; enforce# rejects it. rec carries the fence for heartbeat renewal + the checkpoint backstop.+ # Admission comes before the session is stamped as running: a refused turn used to leave a+ # finished session at running/starting with a fresh heartbeat, the orphan sweep then took it+ # for a dead turn, and a client retrying its follow-up never got back in (omp, 2026-09-15).rec["lease_fence"] = 0if LEASE_MODE != "off" and control_store.enabled():try:@@ -6651,6 +6654,9 @@ async def _resp_execute(translator: _RespTranslator, *, org: str, member: str, sreturn "failed", [], recexcept Exception: # noqa: BLE001 — lease is best-effort; never block a turn on itpass+ await _vertex_upsert(sid, {"status": "running", "turn_status": "starting",+ "heartbeat": str(time.time()), "runner_turn_id": "",+ **({"trace_blob": tr["prefix"]} if tr.get("prefix") else {})})await _hydrate(sid, rec)if rec.get("hydrate_failed_with_checkpoint"):# The task has a checkpoint and it could not be restored: the turn does not run. Running itdiff --git a/gateway/tests/test_incomplete_reason.py b/gateway/tests/test_incomplete_reason.pyindex fb7ec9e9..fba85c13 100644--- a/gateway/tests/test_incomplete_reason.py+++ b/gateway/tests/test_incomplete_reason.py@@ -47,3 +47,45 @@ def test_the_empty_output_settle_never_claims_a_cause():window = src[i:i + 1200]assert '"reason"' not in window.split("else:")[0], ("the empty-output settle claims a reason it cannot know")+++def test_a_finishing_owner_is_not_settled_from_under(monkeypatch):+ """The session flips to done before its owner has written the checkpoint and the full+ response record; a poller's reconcile in that window used to settle the record 'incomplete'+ and a replica cached that for good. A fresh heartbeat means the owner is alive: leave it."""+ import asyncio, time+ calls = []+ async def _vertex_get(vid):+ return {"id": vid, "status": "done", "heartbeat": str(time.time() - 5)}+ async def _blob_put(*a, **k):+ calls.append("put"); return True+ monkeypatch.setattr(A, "_vertex_get", _vertex_get)+ monkeypatch.setattr(A, "_blob_put", _blob_put)+ rec = {"id": "resp_x", "status": "running", "_session_id": "hsess1", "output": []}+ out = asyncio.run(A._reconcile_response("resp_x", rec))+ assert out["status"] == "running" and calls == []+ # the same session with a dead owner is settled, as before+ async def _vertex_get_dead(vid):+ return {"id": vid, "status": "done", "heartbeat": str(time.time() - 10_000)}+ async def _blob_get(*a, **k):+ return None+ async def _vg_upsert(*a, **k):+ return None+ monkeypatch.setattr(A, "_vertex_get", _vertex_get_dead)+ monkeypatch.setattr(A, "_blob_get", _blob_get)+ monkeypatch.setattr(A, "_vg_upsert", _vg_upsert)+ out = asyncio.run(A._reconcile_response("resp_x", dict(rec)))+ assert out["status"] == "incomplete" and calls == ["put"]+++def test_a_refused_turn_leaves_the_session_as_it_found_it():+ """The lease is checked before the session is stamped running/starting: a follow-up refused+ as 'already in progress' must not leave a finished session looking live, or the orphan sweep+ adopts it and every retry is refused in turn (omp follow-ups, 2026-09-15)."""+ import inspect+ src = inspect.getsource(A._resp_execute)+ admit = src.index("control_store.lease_admit(")+ stamp = src.index('"turn_status": "starting"')+ assert admit < stamp, "the session must be stamped only after admission"+ refused = src.index('"a turn is already in progress for this session"')+ assert refused < stamp, "a refused turn returns before the stamp"diff --git a/runner/server.py b/runner/server.pyindex e0a2d805..11d06ef5 100644--- a/runner/server.py+++ b/runner/server.py@@ -1565,12 +1565,18 @@ CODEX_PROVIDERS = {# because Codex reserves its built-in ids: a [model_providers.openai] block is rejected outright# ("Built-in providers cannot be overridden"), which broke every bring-your-own OpenAI key. All# providers are namespaced rather than just that one, so a future reserved id can't break us again.+# mcp_optional_startup_grace_ms = 0: codex builds its initial tool catalog after a shared grace of+# one second by default and drops any MCP server still starting; the runner's SSE bridge takes about+# that long to open its remote connection, so a plugin's SSE server was in the catalog on one turn+# and missing on the next (hosted, 2026-09-15). Zero makes codex wait each server's own+# startup_timeout_sec (10 s) instead._CODEX_CONFIG_TMPL = """model = "{model}"model_provider = "{provider}"model_reasoning_effort = "{effort}"approval_policy = "never"sandbox_mode = "danger-full-access"model_context_window = {ctx}+mcp_optional_startup_grace_ms = 0[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 f8e853bb..aa414b93 100644--- a/runner/tests/test_codex_reasoning_strip.py+++ b/runner/tests/test_codex_reasoning_strip.py@@ -184,3 +184,6 @@ def test_codex_config_declares_the_catalog_window_and_no_feature_overrides(tmp_pimport tomllibparsed = tomllib.loads(cfg)assert parsed["model_providers"]["hr-openai"]["wire_api"] == "responses"+ # codex waits each MCP server's own startup timeout for the initial tool catalog, not the+ # one-second shared grace that dropped the SSE bridge on alternate turns+ assert parsed["mcp_optional_startup_grace_ms"] == 0