The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(gateway): pin the launch routing row across a secondary delete
liuhao10240f5159890e86
diff --git a/tests/gateway/test_authority_connection.py b/tests/gateway/test_authority_connection.pyindex 3ccdf81a42d..49617fb0b8d 100644--- a/tests/gateway/test_authority_connection.py+++ b/tests/gateway/test_authority_connection.py@@ -53,6 +53,7 @@ async def test_close_after_a_subscribed_session_was_deleted_releases_every_membestore = SimpleNamespace(_routing_db=db, retire_runtime_sessions=lambda ids: None)runner = SimpleNamespace(_draining=False, session_store=store, _evict_cached_agent=lambda route: None)authority = SessionAuthority(runner, profile_id='test', instance_id='test', db=db, epoch=epoch)+ runner.session_authority = authority # the runtime owns this authority, so its delete passes the guardfor sid in ('doomed', 'kept'):authority.sessions[sid] = LiveSession(None, sid + '-route')viewer = AuthorityConnection(authority, object(), {'user_id': 'human'})diff --git a/tests/gateway/test_delete_secondary_profile_multiplex.py b/tests/gateway/test_delete_secondary_profile_multiplex.pyindex b121a52cf6e..711f053c0ea 100644--- a/tests/gateway/test_delete_secondary_profile_multiplex.py+++ b/tests/gateway/test_delete_secondary_profile_multiplex.py@@ -1,4 +1,5 @@"""A multiplexed secondary profile's delete retires routing under one owner (#138826)."""+from datetime import UTC, datetimefrom types import SimpleNamespaceimport pytest@@ -32,12 +33,36 @@ async def test_delete_of_secondary_profile_session_does_not_409(tmp_path, monkeywith _profile_runtime_scope(home, {}):ref = create_local_session(authority, actor, {'request_id': 'r', 'source': 'gui','cwd': str(tmp_path), 'model': 'frozen', 'toolsets': []})+ # A messaging key routed at this session, published to the launch store's durable+ # index — the shape that survives deletes a user actually observes (#138862).+ from gateway.session import SessionEntry+ store = runner.session_store+ now = datetime.now(UTC)+ store._entries['agent:main:telegram:111'] = SessionEntry(+ session_key='agent:main:telegram:111', session_id=ref.session_id,+ created_at=now, updated_at=now)+ with store._lock:+ store._save()result = await mutate_session(authority, actor, ref, dict(session_id=ref.session_id, request_id='delete', expected_revision=0,expected_generation=0, operation='delete', payload={}))assert 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.+ 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'finally:for a in list(getattr(runner, 'session_authorities', None) or []):a.db.close()