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
fix(gateway): the delete tombstones the session before anything else
richard-epsillabd519ac3dd92
diff --git a/gateway/app.py b/gateway/app.pyindex 2eff3cfd..113c986a 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -3507,6 +3507,23 @@ async def delete_trace(sid: str, request: Request) -> dict:tarball, and tombstone the session vertex. /v1/sessions/{sid} is the protocol's name for it;/v1/traces/{sid} is the older path the Traces app calls, the same handler."""org, v = await _owned_session(request, sid)+ # The tombstone goes down FIRST. Stopping a live turn below triggers its finalize, and a+ # reconcile can land at any moment; both write session cards, and the indexer drops a write+ # whose session is tombstoned. Written last, the tombstone missed exactly those writes and+ # the cards came back after the delete had cleared them.+ # 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).+ #+ # `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.+ try:+ await _vg_upsert("HarnessSession", sid, {"status": "deleted", "shared": "0"})+ except Exception: # noqa: BLE001+ pass# §6: a session is deleted with nothing still writing into it. A live turn is stopped first,# the same way cancel stops it, so the sandbox cannot repopulate storage that has no owner.if {"running", "starting"} & {str(v.get("turn_status") or ""), str(v.get("status") or "")}:@@ -3548,20 +3565,7 @@ async def delete_trace(sid: str, request: Request) -> dict:except Exception: # noqa: BLE001passawait _media_session_purge(sid)- # 3) tombstone the session vertex + drop in-process state- 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).- #- # `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+ # 3) drop in-process state (the vertex was tombstoned first, above)_SHARE_STATE_CACHE.pop(sid, None)_SHARE_TOKEN_CACHE.clear()_session_trace.pop(sid, None)diff --git a/gateway/tests/test_session_delete_mirrors.py b/gateway/tests/test_session_delete_mirrors.pyindex 82b4cc4e..596def45 100644--- a/gateway/tests/test_session_delete_mirrors.py+++ b/gateway/tests/test_session_delete_mirrors.py@@ -57,3 +57,18 @@ def test_a_reindex_without_scope_fields_inherits_them_and_rewrites_the_mirrors()return statusesstatuses = asyncio.run(run())assert all(v == "done" for v in statuses.values()), f"a mirror kept the stale card: {statuses}"+++def test_a_card_written_for_a_tombstoned_session_is_dropped():+ async def run():+ sid = "hsesstombstonetest"+ base = "local/98211493921626_" + sid+ await A._vertex_upsert(sid, {"tenant": "local", "status": "deleted", "created_at_inv": "98211493921626",+ "trace_blob": base})+ await A._index_manifest(base, {"session_id": sid, "harness_id": "pi", "member_id": "m", "workspace": "dev", "status": "done"})+ present = {}+ for k in A._manifest_index_keys(base, "pi", "m", "dev"):+ present[k] = bool(await A._blob_get(k, kb=A.TRACE_KB))+ 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]}"