The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: canonical delete takes the whole compression chain, root included
Tekniuma942a715b363
diff --git a/hermes_state_mutation_guards.py b/hermes_state_mutation_guards.pyindex cc58c9f52af..85e0bc9715e 100644--- a/hermes_state_mutation_guards.py+++ b/hermes_state_mutation_guards.py@@ -55,9 +55,9 @@ def require_idle(db, conn, session_ids):def delete_targets(conn, session_id):- from hermes_state_sessions import _collect_delegate_child_ids+ from hermes_state_sessions import _collect_delegate_child_ids, _expand_compression_lineage_idsimport json- from hermes_state_compression import _CHAIN_STEP_SQL+ from hermes_state_compression import _CHAIN_CAPfrom hermes_state_local import POLICY_PREFIXfrom hermes_state_local_lineage import validate_local_lineagetargets = {session_id}@@ -70,11 +70,13 @@ def delete_targets(conn, session_id):# Canonical admissions bind to the compression root for every producer, not only# local receipts: every physical continuation of a target goes with it, or the next# message on the route re-admits the "deleted" conversation through the surviving child.+ # The walk also runs BACKWARD to the root (#57543): a sidebar row carries the chain tip's+ # id, and a surviving root re-projects as the "deleted" conversation on the next reload.frontier = list(targets)- while frontier:- row = conn.execute(_CHAIN_STEP_SQL, (frontier.pop(),)).fetchone()- if row is not None and row[0] not in targets:- targets.add(row[0])- frontier.append(row[0])+ for _ in range(_CHAIN_CAP):+ frontier = [sid for sid in _expand_compression_lineage_ids(conn, frontier) if sid not in targets]+ if not frontier:+ break+ targets.update(frontier)targets.update(_collect_delegate_child_ids(conn, targets))return [session_id, *sorted(targets - {session_id})]diff --git a/tests/hermes_cli/test_web_server_session_search.py b/tests/hermes_cli/test_web_server_session_search.pyindex d41a7a23e0f..366e1633412 100644--- a/tests/hermes_cli/test_web_server_session_search.py+++ b/tests/hermes_cli/test_web_server_session_search.py@@ -197,8 +197,14 @@ def test_desktop_session_search_attaches_profile_to_rich_results(monkeypatch):"archived": False,}- monkeypatch.setattr("hermes_state.SessionDB", _RichFakeSessionDB)- monkeypatch.setattr("hermes_cli.profiles.profile_exists", lambda name: True)+ # Browsing never initializes a store: serve the fake as the profile's existing store,+ # as the requested-profile test above does.+ monkeypatch.setattr(_rt_sessions, "_cron_profile_home", lambda profile: (profile, None))+ monkeypatch.setattr(+ _rt_sessions,+ "_open_session_db_for_profile",+ lambda profile, *, read_only: _RichFakeSessionDB(read_only=read_only),+ )response = asyncio.run(_rt_sessions.search_sessions(q="20260603", limit=1, profile="personal"))assert response["results"][0]["profile"] == "personal"assert response["results"][0]["title"] == "Custom Title"@@ -256,6 +262,10 @@ class _DeepLineageSessionDB(_FakeSessionDB):def test_deep_lineage_search_resolves_tip_from_matched_id(monkeypatch):+ from hermes_state import SessionDB++ # Search projection is mocked, but an owner must initialize the store.+ SessionDB().close()monkeypatch.setattr("hermes_state.SessionDB", _DeepLineageSessionDB)response = asyncio.run(_rt_sessions.search_sessions(q="content", limit=2))diff --git a/tests/hermes_cli/test_web_server_sessions_compression.py b/tests/hermes_cli/test_web_server_sessions_compression.pyindex 1ae4a1b910a..04eeba5cbd8 100644--- a/tests/hermes_cli/test_web_server_sessions_compression.py+++ b/tests/hermes_cli/test_web_server_sessions_compression.py@@ -76,11 +76,17 @@ class TestSessionStatsCompressionChildren(_SessionsCompressionEndpoints):class TestDeleteSessionCompressionChain(_SessionsCompressionEndpoints):"""``DELETE /api/sessions/{session_id}`` — single-row flavour of #57543."""- def test_delete_removes_whole_compression_chain(self):+ def test_delete_removes_whole_compression_chain(self, monkeypatch):"""The list row the user clicked carries the chain tip's id; deleting itmust take the root with it, or the conversation resurfaces as theprevious chain link on the next reload."""+ from types import SimpleNamespace++ from gateway.session_authority import LiveSession, SessionAuthority+ from hermes_cli.web_server import app+ from hermes_constants import get_hermes_homefrom hermes_state import SessionDB+ from hermes_state_runtime import begin_runtime_epochdb = SessionDB()try:@@ -89,15 +95,20 @@ class TestDeleteSessionCompressionChain(_SessionsCompressionEndpoints):db.create_session(session_id="conv_tip", source="tui", parent_session_id="conv_root")- finally:- db.close()+ # The dashboard never opens a second writer: DELETE admits through the owner.+ authority = SessionAuthority(+ SimpleNamespace(_draining=False), profile_id=str(get_hermes_home()),+ instance_id="owner", db=db, epoch=begin_runtime_epoch(db, instance_id="owner"))+ authority.sessions["conv_tip"] = LiveSession(None, "route")+ monkeypatch.setattr(app.state, "session_authority", authority, raising=False)++ snap = self.auth_client.get("/api/sessions/conv_tip/mutation-snapshot").json()+ resp = self.auth_client.delete("/api/sessions/conv_tip", params={+ "request_id": "delete-chain", "expected_revision": snap["runtime_revision"],+ "expected_generation": snap["runtime_generation"]})+ assert resp.status_code == 200, resp.text+ assert resp.json().get("ok") is True- resp = self.auth_client.delete("/api/sessions/conv_tip")- assert resp.status_code == 200- assert resp.json().get("ok") is True-- db = SessionDB()- try:assert db.get_session("conv_tip") is Noneassert db.get_session("conv_root") is Nonefinally: