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.

fix(gateway): a stored destination heals its label once the cloud can name it

richard-epsilla9efe45dc020f
diff --git a/gateway/app.py b/gateway/app.py
index 412c118a..722ffdb0 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -11812,6 +11812,30 @@ def _cloud_status(hid: str, records: dict, fp: str | None, target: dict) -> dict
async def cloud_targets_get(request: Request) -> dict:
await _principal(request)
doc = await _cloud_targets()
+ # Self-heal a label: a target stored while the hosted side could not name its workspace keeps
+ # empty fields, and the hosted side has since learned to answer (names are stamped on keys at
+ # mint and were backfilled). Re-resolve only while a field is missing, best effort: a dead key
+ # keeps its stored shape and stays listed, and removal is always available.
+ changed = False
+ for tkey, t in list(doc["targets"].items()):
+ if t.get("workspace_name") and t.get("member"):
+ continue
+ try:
+ me = await _cloud_me(t.get("base_url") or _CLOUD_UPLOAD_DEFAULT_BASE, t.get("api_key") or "")
+ except HTTPException:
+ continue
+ t.update({"org": me.get("org") or t.get("org") or "", "org_name": me.get("org_name") or "",
+ "workspace": me.get("workspace") or t.get("workspace") or "",
+ "workspace_name": me.get("workspace_name") or "", "member": me.get("member") or ""})
+ new_key = _cloud_tkey(t)
+ if new_key != tkey:
+ doc["targets"].pop(tkey, None)
+ doc["targets"][new_key] = t
+ if doc.get("last") == tkey:
+ doc["last"] = new_key
+ changed = True
+ if changed:
+ await _cloud_targets_save(doc)
return {"targets": [_cloud_target_public(t) for t in doc["targets"].values()], "last": doc.get("last") or ""}
diff --git a/gateway/tests/test_cloud_upload.py b/gateway/tests/test_cloud_upload.py
index ffbf662a..7e7718ba 100644
--- a/gateway/tests/test_cloud_upload.py
+++ b/gateway/tests/test_cloud_upload.py
@@ -221,3 +221,18 @@ def test_the_same_harness_uploads_to_every_workspace_a_key_points_at(api, cloud)
api.post("/v1/cloud-upload/targets", json={"api_key": "sk-hr-good", "base_url": CLOUD})
r3 = api.post(f"/v1/harnesses/{hid}/upload").json()
assert r3["action"] == "replace" and r3["remote_id"] == hid
+
+
+def test_a_target_stored_before_the_cloud_knew_its_name_heals_on_listing(api, cloud):
+ """A key added while the hosted side answered empty names keeps working and picks up the
+ name the moment the hosted side can answer, with no re-adding."""
+ cloud.keys["sk-hr-good"] = {**cloud.keys["sk-hr-good"], "workspace_name": "", "member": ""}
+ api.post("/v1/cloud-upload/targets", json={"api_key": "sk-hr-good", "base_url": CLOUD})
+ assert api.get("/v1/cloud-upload/targets").json()["targets"][0]["label"] == "Cloud workspace"
+ cloud.keys["sk-hr-good"] = {**cloud.keys["sk-hr-good"], "workspace_name": "Test Workspace", "member": "richard"}
+ j = api.get("/v1/cloud-upload/targets").json()
+ assert j["targets"][0]["label"] == "Test Workspace (richard)"
+ # healed persistently: no further /v1/me calls once complete
+ n = len([c for c in cloud.calls if c[1] == "/v1/me"])
+ api.get("/v1/cloud-upload/targets")
+ assert len([c for c in cloud.calls if c[1] == "/v1/me"]) == n