The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): a secondary-profile delete drops its shared routing rows
Tekniumedb78c6a5220
diff --git a/gateway/session_mutations.py b/gateway/session_mutations.pyindex 211515a8bff..c1bcd600ca0 100644--- a/gateway/session_mutations.py+++ b/gateway/session_mutations.py@@ -5,12 +5,15 @@ transactions. Local reset prepares its replacement in the receipt transaction;branch/compress/model still require their own prepared runtime publication."""import asyncio+import loggingfrom contextlib import nullcontextfrom functools import partialfrom hermes_state_mutation_guards import MUTATION_GUARD_REFUSALSfrom hermes_state_runtime import RuntimeStoreError, mutate_runtime_session+logger = logging.getLogger(__name__)+_METADATA = frozenset({'rename', 'archive', 'sidebar'})# Prepared off the commit like model, then published as a new frozen policy._POLICY = frozenset({'model', 'reasoning', 'workspace', 'editor_mcp'})@@ -317,6 +320,16 @@ def retire_live_sessions(authority, session_ids):store = getattr(authority.runner, 'session_store', None)if store is not None:store.retire_runtime_sessions(session_ids)+ # The delete transaction dropped routing rows in the owning store; a multiplexed+ # secondary's routes live in the launch home's shared index, so drop them there too+ # rather than wait for the next whole-index save (a crash in between left a route to+ # a deleted session, #138826).+ routing = getattr(store, '_routing_db', None)+ if session_ids and routing is not None and routing.db_path != authority.db.db_path:+ try:+ routing._delete_routing_entries_for_sessions(set(session_ids))+ except Exception:+ logger.warning('could not drop shared routing rows for deleted sessions', exc_info=True)from gateway.session_policy import release_launch_secretsrelease_launch_secrets(authority, session_ids)from tools.async_delegation import allow_for_sessiondiff --git a/tests/gateway/test_delete_secondary_profile_multiplex.py b/tests/gateway/test_delete_secondary_profile_multiplex.pyindex 711f053c0ea..bb6221ccccb 100644--- a/tests/gateway/test_delete_secondary_profile_multiplex.py+++ b/tests/gateway/test_delete_secondary_profile_multiplex.py@@ -49,20 +49,13 @@ async def test_delete_of_secondary_profile_session_does_not_409(tmp_path, monkeyassert result.get('deleted_ids') == [ref.session_id]assert authority.db.get_session(ref.session_id) is Noneassert runner.session_store.lookup_by_session_id(ref.session_id) is None- # The retire clears the in-memory entry but not the launch store's durable row: the- # fence marker lives in the owner store, and the launch table is rewritten only by the- # next whole-index save. Pin both halves — a live path always republishes on its next- # save, while an offline CLI delete, with no live store, leaves its row behind for good.+ # The secondary's routes live in the launch home's shared index: the delete drops its+ # durable row there too, not only at the next whole-index save (a crash in between kept+ # a messaging route to a deleted session).routing_db = runner.session_store._routing_db- seated = {r['session_key'] for r in routing_db._read_all(- 'SELECT session_key FROM gateway_routing WHERE json_extract(entry_json, ?) = ?',- ('$.session_id', ref.session_id))}- assert 'agent:main:telegram:111' in seated- with runner.session_store._lock:- runner.session_store._save()assert not routing_db._read_all('SELECT session_key FROM gateway_routing WHERE json_extract(entry_json, ?) = ?',- ('$.session_id', ref.session_id)), 'the next whole-index save republishes the retire'+ ('$.session_id', ref.session_id))finally:for a in list(getattr(runner, 'session_authorities', None) or []):a.db.close()