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
workspaces: a list the store could not read is a 503, never an organization with none (#569)
github-actions[bot]00054dcc9594
diff --git a/gateway/app.py b/gateway/app.pyindex e60661a9..f3bf925f 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -19959,8 +19959,17 @@ def _workspace_out(v: dict) -> dict:async def _workspace_rows(org: str) -> list[dict]:- rows = [v for v in await _vg_list_by_org("Workspace", org)- if str(v.get("deleted") or "0") != "1"]+ """The organization's workspaces, or a 503 when they could not be read. Every caller acts on the+ answer: the list backfills the default when it is missing (an upsert, so over a renamed default it+ put back "Default Workspace"), create picks a free id from it (so it could take an existing one's and+ write over it), and rename looks the workspace up in it. A failed read taken as "none" did each."""+ try:+ found = await _vg_list_by_org_strict("Workspace", org)+ except Exception as e: # noqa: BLE001 — the strict read raises only when the store could not answer+ print(f"[workspaces] the workspace list could not be read org={org}: {type(e).__name__}", flush=True)+ raise uhp_error(503, "server_error",+ "Your workspaces could not be read just now. Try again in a moment.") from e+ rows = [v for v in found if str(v.get("deleted") or "0") != "1"]rows.sort(key=lambda v: (str(v.get("ws_id")) != _WORKSPACE_DEFAULT_ID,str(v.get("created_at") or "")))return rowsdiff --git a/gateway/tests/test_workspaces_read_failure.py b/gateway/tests/test_workspaces_read_failure.pynew file mode 100644index 00000000..0b48fd79--- /dev/null+++ b/gateway/tests/test_workspaces_read_failure.py@@ -0,0 +1,100 @@+"""A workspace list the store could not read is never taken for an organization with none.++`_workspace_rows` read through the forgiving `find`, which answers a failed read with the same `[]` as+an organization that holds no workspace. Each of its three callers acts on that answer:+ the list backfills the default when it is missing, with an upsert, so a renamed default went back to+ "Default Workspace" and every other workspace vanished from the answer;+ create picks a free id against the ids it read, so "Research" took `research` again and wrote over it;+ rename looked the workspace up, and answered 404 for one that is there.+The read is strict now (#562's `_vg_list_by_org_strict`): a failure is a 503, nothing is written, and an+organization that really has no workspace still gets its default.+"""+import os+import sys++import pytest+from fastapi.testclient import TestClient++sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))+import app as gw # noqa: E402++ORG = "local"+++def world(monkeypatch):+ store: dict[str, dict] = {}+ broken = {"on": False}++ async def fake_upsert(label, vid, props, *, raise_on_fail=False):+ store[vid] = {**props}++ async def plain_list(label, org):+ # the forgiving read: a failure is the same [] as nothing there+ if broken["on"]:+ return []+ return [v for v in store.values() if v.get("org") == org and label == "Workspace"]++ async def strict_find(label, eq=None, neq=None):+ if broken["on"]:+ raise RuntimeError("store unreachable")+ return [v for v in store.values() if v.get("org") == (eq or {}).get("org") and label == "Workspace"]++ async def fake_principal(request):+ return {"org": ORG, "member": "local@localhost", "workspace": "", "workspace_default": False}++ monkeypatch.setattr(gw, "_vg_upsert", fake_upsert)+ monkeypatch.setattr(gw, "_vg_list_by_org", plain_list)+ monkeypatch.setattr(gw.BACKING.graph, "find_strict", strict_find)+ monkeypatch.setattr(gw, "_principal", fake_principal)+ return TestClient(gw.app), store, broken+++def _renamed_default_and_research(api):+ assert api.get("/v1/hr/workspaces").status_code == 200+ assert api.patch("/v1/hr/workspaces/default", json={"name": "Acme HQ"}).status_code == 200+ assert api.post("/v1/hr/workspaces", json={"name": "Research", "description": "papers"}).status_code == 200+++def test_a_list_that_could_not_be_read_is_said_and_writes_nothing(world):+ api, store, broken = world+ _renamed_default_and_research(api)+ kept = {k: dict(v) for k, v in store.items()}+ broken["on"] = True+ r = api.get("/v1/hr/workspaces")+ assert r.status_code == 503, r.text+ assert r.json()["error"]["message"] == "Your workspaces could not be read just now. Try again in a moment."+ assert store == kept, "the default was written back over the renamed one"+ broken["on"] = False+ names = {w["id"]: w["name"] for w in api.get("/v1/hr/workspaces").json()["workspaces"]}+ assert names == {"default": "Acme HQ", "research": "Research"}+++def test_create_over_a_list_that_could_not_be_read_takes_no_ones_id(world):+ api, store, broken = world+ _renamed_default_and_research(api)+ kept = {k: dict(v) for k, v in store.items()}+ broken["on"] = True+ assert api.post("/v1/hr/workspaces", json={"name": "Research", "description": "overwritten"}).status_code == 503+ assert api.post("/v1/hr/workspaces", json={"name": "x", "id": "research"}).status_code == 503+ assert store == kept+ broken["on"] = False+ # and with the list readable, a second Research is a new workspace beside the first+ assert api.post("/v1/hr/workspaces", json={"name": "Research"}).json()["id"] == "research-2"+++def test_rename_over_a_list_that_could_not_be_read_is_not_a_missing_workspace(world):+ api, store, broken = world+ _renamed_default_and_research(api)+ broken["on"] = True+ r = api.patch("/v1/hr/workspaces/research", json={"name": "Lab"})+ assert r.status_code == 503, r.text+ broken["on"] = False+ assert api.patch("/v1/hr/workspaces/research", json={"name": "Lab"}).json()["name"] == "Lab"+++def test_an_organization_with_no_workspace_still_gets_its_default(world):+ api, store, _ = world+ d = api.get("/v1/hr/workspaces").json()+ assert [w["id"] for w in d["workspaces"]] == ["default"]+ assert store[f"ws.{ORG}.default"]["name"] == "Default Workspace"