The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): lock a deleted chat's password managers
emozilla8b721403ad50
diff --git a/gateway/session_mutations.py b/gateway/session_mutations.pyindex e9b3f3e3ccd..bfab54b943f 100644--- a/gateway/session_mutations.py+++ b/gateway/session_mutations.py@@ -406,9 +406,12 @@ def retire_live_sessions(authority, session_ids, *, require_fence=False):release_launch_secrets(authority, session_ids)release_session_workspaces(authority, session_ids)from tools.async_delegation import allow_for_session+ from gateway.session_vault_prompt import release_unlocksfor sid in session_ids:# A closed session's refusal of new delegations (session_viewer_close) goes with its live state.allow_for_session((authority.profile_id, sid))+ # So do the password managers it unlocked: this path never reaches the viewer-close settle.+ release_unlocks(sid)candidate = authority.sessions.pop(sid, None)if candidate is not None and not candidate.superseded: # its route is the newer session'sevict = getattr(authority.runner, '_evict_cached_agent', None)diff --git a/tests/gateway/test_local_viewer_vault_prompt.py b/tests/gateway/test_local_viewer_vault_prompt.pyindex 64d75291928..77e9749d94b 100644--- a/tests/gateway/test_local_viewer_vault_prompt.py+++ b/tests/gateway/test_local_viewer_vault_prompt.py@@ -250,3 +250,30 @@ def test_a_manager_unlocked_on_a_tool_worker_is_released_with_its_session():assert not unlock.is_unlocked('test-backend-w')finally:unlock.lock('test-backend-w')+++def test_deleting_a_chat_locks_the_managers_it_unlocked(monkeypatch):+ """Delete, the owner-run prune and onboarding cleanup retire the live session without the+ viewer-close settle, so retiring it locks what the chat unlocked. Other chats keep theirs."""+ from agent.vault_backends import unlock+ from gateway import session_local_mcp, session_policy, session_worker_construct+ from gateway.session_mutations import retire_live_sessions+ from gateway.session_vault_prompt import vault_prompt_scope+ from tools import async_delegation+ for module, name in ((session_policy, 'release_launch_secrets'), (session_policy, 'release_session_workspaces'),+ (session_local_mcp, 'release_editor_mcp'),+ (session_worker_construct, 'release_session_prefill'), (async_delegation, 'allow_for_session')):+ monkeypatch.setattr(module, name, lambda *args, **kwargs: None)+ authority = SimpleNamespace(runner=SimpleNamespace(), profile_id='default', sessions={})+ events, _ = _events()+ try:+ with vault_prompt_scope(_turn(events, session_id='s-del'), SimpleNamespace()):+ assert unlock.store_session_token('test-backend-d', 'token-d')+ with vault_prompt_scope(_turn(events, session_id='s-keep'), SimpleNamespace()):+ assert unlock.store_session_token('test-backend-k', 'token-k')+ retire_live_sessions(authority, ['s-del'])+ assert not unlock.is_unlocked('test-backend-d')+ assert unlock.is_unlocked('test-backend-k')+ finally:+ unlock.lock('test-backend-d')+ unlock.lock('test-backend-k')