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.

kits: a launch whose harness list could not be read is refused, not provisioned a second time (#562)

Rudy Mizrahi Celekli716ce2989458
diff --git a/gateway/app.py b/gateway/app.py
index 7e83a394..7519938a 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -18581,6 +18581,19 @@ async def _vg_list_by_org(label: str, org: str) -> list[dict]:
return await BACKING.graph.find(label, {"org": org})
+async def _vg_list_by_org_strict(label: str, org: str) -> list[dict]:
+ """`_vg_list_by_org`, except that an empty answer is established to be empty rather than taken
+ on trust. The plain read swallows a failed read and returns the same `[]` as "the organization
+ holds none" (backing.GraphStore.probe: "the normal read paths swallow errors and return
+ empty"), which a caller that provisions on an empty list must not act on. Only an empty answer
+ pays for the strict re-read, and only an empty answer needs it: `find_strict` either answers
+ with every row of the label or raises."""
+ rows = await _vg_list_by_org(label, org)
+ if not rows:
+ rows = await BACKING.graph.find_strict(label, {"org": org})
+ return rows
+
+
def _harness_props(body: HarnessBody) -> dict:
base = _require_supported_base(body.base) # refuse at create, not at the first task
return {"name": body.name, "base": base, "base_label": body.base_label or base,
@@ -20189,7 +20202,17 @@ async def launch_kit(kit_id: str, request: Request, body_in: KitLaunchBody | Non
# Per workspace (see list_kits): launching in a second workspace makes that workspace its own
# Harness rather than handing back the first workspace's, which its members could not see.
ws, wsd = str(p.get("workspace") or ""), bool(p.get("workspace_default"))
- existing = next((r for r in await _vg_list_by_org("Harness", org)
+ # Read strictly: this list is what makes launch idempotent, and a read that failed looks
+ # exactly like an organization with no Harnesses, so provisioning on it is how the second
+ # press leaves someone with two.
+ try:
+ rows = await _vg_list_by_org_strict("Harness", org)
+ except Exception as e: # noqa: BLE001
+ print(f"[kits] {kit_id}: the harness list could not be read org={org}: {type(e).__name__}", flush=True)
+ raise uhp_error(503, "server_error",
+ "Your Harnesses could not be read just now, so nothing was launched. "
+ "Try again in a moment.") from e
+ existing = next((r for r in rows
if str(r.get("kit") or "") == kit_id and str(r.get("deleted") or "0") != "1"
and _workspace_keep(str(r.get("workspace") or ""), ws, wsd)),
None)
diff --git a/gateway/tests/test_kits_workspace.py b/gateway/tests/test_kits_workspace.py
index edbbdbca..50c4c8bb 100644
--- a/gateway/tests/test_kits_workspace.py
+++ b/gateway/tests/test_kits_workspace.py
@@ -147,3 +147,33 @@ def test_a_launch_on_a_base_and_model_nothing_serves_is_422_model_unavailable(wo
assert e.value.status_code == 422
assert e.value.detail["code"] == "model_unavailable" and e.value.detail["param"] == "model"
assert "deepseek-v4-pro" in e.value.detail["message"] # the words are unchanged
+
+
+def test_a_kit_whose_harness_list_could_not_be_read_is_not_launched(world, monkeypatch):
+ """Launch is idempotent on the harness list alone, and the forgiving read answers a failed
+ read with the same empty list as an organization that holds no Harness — so provisioning on
+ it is exactly how "the second press must not leave them with two Harnesses" is broken. A read
+ the store could not answer refuses the launch instead, with nothing written."""
+ store, who = world
+
+ async def unreadable(label, eq=None, neq=None):
+ raise RuntimeError("graph plane unreachable")
+ monkeypatch.setattr(gw.BACKING.graph, "find_strict", unreadable)
+ with pytest.raises(gw.HTTPException) as e:
+ asyncio.run(gw.launch_kit("slides", _Req(), None))
+ assert e.value.status_code == 503 and e.value.detail["type"] == "server_error"
+ assert not store # refused BEFORE anything was provisioned
+
+
+def test_an_organization_holding_no_harness_still_launches_the_kit_once(world, monkeypatch):
+ """The distinction the strict read keeps: an empty list the store answered with is a first
+ launch, not a failure. The first press provisions, the second hands the same Harness back."""
+ store, who = world
+
+ async def nothing(label, eq=None, neq=None):
+ return []
+ monkeypatch.setattr(gw.BACKING.graph, "find_strict", nothing)
+ first = asyncio.run(gw.launch_kit("slides", _Req(), None))
+ again = asyncio.run(gw.launch_kit("slides", _Req(), None))
+ assert first["created"] and not again["created"]
+ assert again["harnessId"] == first["harnessId"] and len([v for v in store.values() if v.get("kit") == "slides"]) == 1