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): an orphaned mirror card heals itself on the next list

richard-epsillacaeaa8b20ed3
diff --git a/gateway/app.py b/gateway/app.py
index b323e9ee..57cb19e1 100644
--- a/gateway/app.py
+++ b/gateway/app.py
@@ -3186,6 +3186,17 @@ async def _session_cards(org: str, limit: int, cursor: str, member: str, harness
b = await _blob_get(item["file_id"], kb=TRACE_KB)
if not b:
return None
+ # A mirror card whose flat card is gone is an orphan: a delete on an older version
+ # removed the flat card and left the mirror (the delete now clears every mirror, but an
+ # install upgrading brings its orphans with it). It is dropped here, and removed so the
+ # next list does not pay for it either. Only mirrors are checked: the flat index IS the
+ # manifest, so the read above already answered for it.
+ fid = str(item["file_id"])
+ if "/idx/" not in fid:
+ flat = f"{fid.split('/', 1)[0]}/idx/{fid.rsplit('/', 1)[-1]}"
+ if not await _blob_get(flat, kb=TRACE_KB):
+ await _blob_delete(fid, kb=TRACE_KB)
+ return None
try:
m = json.loads(b)
except Exception: # noqa: BLE001
diff --git a/gateway/tests/test_session_delete_mirrors.py b/gateway/tests/test_session_delete_mirrors.py
index d56151cf..d6868140 100644
--- a/gateway/tests/test_session_delete_mirrors.py
+++ b/gateway/tests/test_session_delete_mirrors.py
@@ -85,3 +85,17 @@ def test_a_status_write_after_the_tombstone_is_dropped_and_the_tombstone_stays()
return await A._vertex_get(sid)
v = asyncio.run(run())
assert v and v.get("status") == "deleted", f"the tombstone was overwritten: {v}"
+
+
+def test_an_orphaned_mirror_card_is_dropped_and_removed_on_list():
+ async def run():
+ base = "local/98211493921626_hsessorphanmirror"
+ card = {"session_id": "hsessorphanmirror", "harness_id": "orph", "member_id": "m", "workspace": "w", "status": "done", "title": "t"}
+ await A._index_manifest(base, dict(card))
+ flat, mirror = A._manifest_index_keys(base, "orph", "", "")
+ await A._blob_delete(flat, kb=A.TRACE_KB) # what an old delete left behind
+ listed = await A._session_cards("local", 20, "", "", "orph", "", False)
+ return [c["session_id"] for c in listed["sessions"]], bool(await A._blob_get(mirror, kb=A.TRACE_KB))
+ sids, mirror_still_there = asyncio.run(run())
+ assert "hsessorphanmirror" not in sids, "an orphaned mirror card was listed"
+ assert not mirror_still_there, "the orphan was listed away but not removed"