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.

gateway: the reference must be drivable by the suite it defines conformance for

richard-epsilla87994e295649
diff --git a/gateway/app.py b/gateway/app.py
index 6b94c2eb..22ff1d1e 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -3460,9 +3460,18 @@ async def delete_trace(sid: str, request: Request) -> dict:
try:
# Mark deleted but DON'T blank trace_blob — a blank prefix silently disables the trace if the
# session is later resumed (the prefix is deterministic from created_at_inv anyway).
- await _vg_upsert("HarnessSession", sid, {"status": "deleted"})
+ #
+ # `shared: "0"` is part of the tombstone, not hygiene. The share resolver matches on
+ # {share_token, shared: "1"} and never looks at status, so a deleted session's link kept
+ # resolving — and the turns behind it are rebuilt from response records, which this
+ # function does not remove. Verified live: DELETE answered 200 and the share link went on
+ # serving the full conversation. Sessions §6 says deletion MUST make the session
+ # unreadable, and the published link is the reader its owner is least likely to remember.
+ await _vg_upsert("HarnessSession", sid, {"status": "deleted", "shared": "0"})
except Exception: # noqa: BLE001
pass
+ _SHARE_STATE_CACHE.pop(sid, None)
+ _SHARE_TOKEN_CACHE.clear()
_session_trace.pop(sid, None)
return {"id": sid, "object": "session", "deleted": True}
@@ -6542,26 +6551,62 @@ async def artifact_by_path(sid: str, path: str, request: Request) -> Response:
class ShareBody(BaseModel):
- enabled: bool
+ enabled: bool = True
+
+
+def _share_out(enabled: bool, token: str) -> dict:
+ """The share object, self-describing. Sessions §5 names the mint endpoint but not where the
+ view is served, so the object says so itself: `url` is where this share reads back, relative
+ to whatever base the caller is already using — the gateway cannot know its public origin (the
+ console proxy deliberately strips Host and x-forwarded-*), and a path survives every fronting
+ (direct, or via /api/harness which relays /share/* through). `id` is the token because the
+ token IS the share's identity; a conformance probe that presents it as an API bearer must be
+ refused, and giving it a second name would only hide that from the check."""
+ out = {"object": "session.share", "enabled": enabled, "token": token}
+ if token:
+ out["id"] = token
+ out["url"] = f"/share/{token}"
+ return out
@app.post("/v1/sessions/{sid}/share")
-async def set_session_share(sid: str, body: ShareBody, request: Request) -> dict:
+async def set_session_share(sid: str, request: Request, body: ShareBody | None = None) -> dict:
+ """Publish (or with enabled:false, revoke) the read-only shared view of a session.
+
+ The body is OPTIONAL, defaulting to enabled. Sessions §5 documents `POST .../share` with no
+ body — publishing is the whole meaning of the request — and requiring `{"enabled": true}`
+ made this endpoint 422 a caller speaking the specification's own dialect (the conformance
+ suite among them)."""
p = await _principal(request)
v = await _vertex_get(sid)
if not v or str(v.get("tenant") or "") != p.get("org"):
raise uhp_error(404, "session_not_found", "No session with that id.", "session_id")
- if body.enabled:
+ if body is None or body.enabled:
token = str(v.get("share_token") or "") or ("shr" + uuid.uuid4().hex)
await _vertex_upsert(sid, {"share_token": token, "shared": "1",
"shared_at": str(time.time())})
_SHARE_STATE_CACHE.pop(sid, None)
_SHARE_TOKEN_CACHE.clear()
- return {"enabled": True, "token": token}
+ return _share_out(True, token)
await _vertex_upsert(sid, {"shared": "0"})
_SHARE_STATE_CACHE.pop(sid, None)
_SHARE_TOKEN_CACHE.clear()
- return {"enabled": False, "token": str(v.get("share_token") or "")}
+ return _share_out(False, str(v.get("share_token") or ""))
+
+
[email protected]("/v1/sessions/{sid}/share")
+async def revoke_session_share(sid: str, request: Request) -> dict:
+ """Revocation, at the address of the thing being revoked. §5 says a share MUST be revocable
+ and names no path; DELETE on the share endpoint is the reading a client tries first, and it
+ was answering 405 while the real revocation hid inside POST {"enabled": false}. Both work."""
+ p = await _principal(request)
+ v = await _vertex_get(sid)
+ if not v or str(v.get("tenant") or "") != p.get("org"):
+ raise uhp_error(404, "session_not_found", "No session with that id.", "session_id")
+ await _vertex_upsert(sid, {"shared": "0"})
+ _SHARE_STATE_CACHE.pop(sid, None)
+ _SHARE_TOKEN_CACHE.clear()
+ return _share_out(False, str(v.get("share_token") or "")) | {"deleted": True}
@app.get("/v1/sessions/{sid}/share")
@@ -6570,7 +6615,7 @@ async def get_session_share(sid: str, request: Request) -> dict:
v = await _vertex_get(sid)
if not v or str(v.get("tenant") or "") != p.get("org"):
raise uhp_error(404, "session_not_found", "No session with that id.", "session_id")
- return {"enabled": str(v.get("shared") or "") == "1", "token": str(v.get("share_token") or "")}
+ return _share_out(str(v.get("shared") or "") == "1", str(v.get("share_token") or ""))
async def _share_sid(token: str) -> str | None:
@@ -6597,6 +6642,14 @@ _SHARE_META_FIELDS = ("session_id", "title", "status", "model", "backend",
"harness_id", "harness_name", "event_count", "elapsed", "finished_at")
[email protected]("/share/{token}")
+async def share_view(token: str) -> dict:
+ """The shared view's root: what the published URL opens. The subroutes carry the pieces
+ (meta / turns / files); this is the object a link-holder lands on, and the address every
+ read-only guarantee in Sessions §5 is measured at."""
+ return {"object": "session.shared", **(await share_meta(token))}
+
+
@app.get("/share/{token}/meta")
async def share_meta(token: str) -> dict:
sid = await _share_sid(token)
diff --git a/gateway/tests/test_share_selfhost.py b/gateway/tests/test_share_selfhost.py
index f324b361..684f1519 100644
--- a/gateway/tests/test_share_selfhost.py
+++ b/gateway/tests/test_share_selfhost.py
@@ -58,3 +58,64 @@ def test_switching_sharing_off_revokes_the_link(api):
def test_an_unknown_token_is_not_found(api):
assert asyncio.run(gw._share_sid("shr" + "0" * 32)) is None
assert api.get("/share/shr" + "0" * 32 + "/meta").status_code == 404
+
+
+def test_a_bodyless_post_publishes_the_share(api):
+ """Sessions §5 documents `POST .../share` with no body — publishing is the request's whole
+ meaning — and this endpoint 422'd that dialect, which is how the entire conformance R-series
+ skipped against the reference server."""
+ sid = "hsessshare" + os.urandom(4).hex()
+ _session(sid)
+ r = api.post(f"/v1/sessions/{sid}/share")
+ assert r.status_code == 200, r.text
+ d = r.json()
+ assert d["enabled"] is True and d["token"]
+ assert d["id"] == d["token"], "the token is the share's identity, under one name"
+ assert d["url"] == f"/share/{d['token']}", "the object must say where its view is served"
+ assert api.get(f"/v1/sessions/{sid}/share").json()["url"] == d["url"], (
+ "GET must report the same link POST published")
+
+
+def test_the_published_url_opens_with_no_credential(api):
+ sid = "hsessshare" + os.urandom(4).hex()
+ _session(sid)
+ url = api.post(f"/v1/sessions/{sid}/share").json()["url"]
+ r = api.get(url) # no auth beyond the link itself: the token is the credential
+ assert r.status_code == 200, r.text
+ assert r.json()["object"] == "session.shared"
+ assert r.json()["session_id"] == sid
+
+
+def test_delete_on_the_share_endpoint_revokes(api):
+ """§5 requires revocability and names no path. DELETE on the share endpoint is the reading a
+ client tries first, and it answered 405 while revocation hid inside POST {"enabled": false}."""
+ sid = "hsessshare" + os.urandom(4).hex()
+ _session(sid)
+ url = api.post(f"/v1/sessions/{sid}/share").json()["url"]
+ assert api.get(url).status_code == 200
+ r = api.delete(f"/v1/sessions/{sid}/share")
+ assert r.status_code == 200 and r.json()["enabled"] is False
+ assert api.get(url).status_code == 404, "a revoked link must stop resolving"
+
+
+def test_deleting_the_session_takes_its_share_with_it(api, monkeypatch):
+ """The R-07 defect, verified live before this fix: DELETE /v1/traces answered 200 and the
+ share link went on serving the full conversation, because the resolver matches on
+ {share_token, shared: "1"} and the tombstone never touched `shared` — while the turns behind
+ the view are rebuilt from response records, which deletion does not remove. Sessions §6:
+ deletion MUST make the session unreadable, and the published link is the reader its owner is
+ least likely to remember."""
+ sid = "hsessshare" + os.urandom(4).hex()
+ _session(sid)
+
+ async def owned(request, s):
+ return ORG, {"id": s, "tenant": ORG}
+ monkeypatch.setattr(gw, "_owned_session", owned)
+
+ url = api.post(f"/v1/sessions/{sid}/share").json()["url"]
+ assert api.get(url).status_code == 200
+ assert api.delete(f"/v1/traces/{sid}").status_code == 200
+ assert api.get(url).status_code == 404, "a deleted session's share link must die with it"
+ assert api.get(url + "/turns").status_code == 404, (
+ "the turns behind the view are rebuilt from response records deletion does not remove — "
+ "the resolver is the only gate, so it must refuse")
diff --git a/ui/src/middleware.ts b/ui/src/middleware.ts
index fe760da7..27115183 100644
--- a/ui/src/middleware.ts
+++ b/ui/src/middleware.ts
@@ -54,6 +54,11 @@ function isPublic(path: string): boolean {
// only for a token whose owner has sharing switched on, and with nothing but that session.
|| path.startsWith('/share/')
|| path.startsWith('/api/share/')
+ // The same share surface through the API base: a share object's `url` is relative to the
+ // base the client already uses, so a conformance client on /api/harness resolves it to
+ // /api/harness/share/{token} — the gateway's own public share routes, relayed. The token is
+ // the credential there exactly as it is on /share/ and /api/share/ above.
+ || path.startsWith('/api/harness/share/')
|| path.startsWith('/_next/')
// An /api path is never a static asset, whatever it ends with. Neither is /data — those are
// files a TASK produced, and agents write .png, .svg, .css and .js routinely. Matching those