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 tombstone is final; no later status write revives a deleted session

richard-epsilla593b86d629d2
diff --git a/gateway/app.py b/gateway/app.py
index 113c986a..b323e9ee 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -1944,7 +1944,25 @@ async def _checkpoint(sid: str, rec: dict) -> None:
# ── HarnessSession vertex (best-effort; never blocks a turn) ──────────────────────
+async def _session_write_allowed(sid: str, props: dict) -> bool:
+ """A tombstone is final. Nothing after a delete may change a session's status: the finalize
+ of a turn the delete itself stopped, a reconcile, a cancel settling late — each used to land
+ "cancelled" or "done" over "deleted", and the session was readable again with fresh cards.
+ Only status writes are checked (the one field that can revive), so the hot per-event upserts
+ cost nothing extra."""
+ st = props.get("status")
+ if st is None or st == "deleted":
+ return True
+ try:
+ cur = await BACKING.graph.get(sid)
+ except Exception: # noqa: BLE001
+ return True
+ return not (cur and str(cur.get("status") or "") == "deleted")
+
+
async def _vertex_upsert(sid: str, props: dict) -> None:
+ if not await _session_write_allowed(sid, props):
+ return
await BACKING.graph.upsert("HarnessSession", sid, props)
@@ -4059,6 +4077,8 @@ async def _vg_upsert(label: str, vid: str, props: dict, *, raise_on_fail: bool =
Best-effort by default; VG is closed-world on labels so an unregistered label silently no-ops.
raise_on_fail=True (the API-KEY mint/revoke path): a swallowed failure would make a revoke
silently revert or a shown-once key permanently 401, so surface it as a 502 to the caller."""
+ if label == "HarnessSession" and not await _session_write_allowed(vid, props):
+ return
try:
await BACKING.graph.upsert(label, vid, props, raise_on_fail=raise_on_fail)
except HTTPException:
diff --git a/gateway/tests/test_session_delete_mirrors.py b/gateway/tests/test_session_delete_mirrors.py
index 596def45..d56151cf 100644
--- a/gateway/tests/test_session_delete_mirrors.py
+++ b/gateway/tests/test_session_delete_mirrors.py
@@ -72,3 +72,16 @@ def test_a_card_written_for_a_tombstoned_session_is_dropped():
return present
present = asyncio.run(run())
assert not any(present.values()), f"a write for a deleted session landed: {[k for k, v in present.items() if v]}"
+
+
+def test_a_status_write_after_the_tombstone_is_dropped_and_the_tombstone_stays():
+ async def run():
+ sid = "hsessfinaltombstone"
+ await A._vertex_upsert(sid, {"tenant": "local", "status": "running"})
+ await A._vg_upsert("HarnessSession", sid, {"status": "deleted", "shared": "0"})
+ await A._vertex_upsert(sid, {"status": "cancelled", "turn_status": "cancelled"}) # the late finalize
+ await A._vg_upsert("HarnessSession", sid, {"status": "done"}) # a late reconcile
+ await A._vertex_upsert(sid, {"elapsed": "1.5"}) # a field write, not a revival
+ return await A._vertex_get(sid)
+ v = asyncio.run(run())
+ assert v and v.get("status") == "deleted", f"the tombstone was overwritten: {v}"