The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): move a superseded Bot Chat aside only once its replacement is committed
Teknium745433c67163
diff --git a/gateway/session_controls.py b/gateway/session_controls.pyindex f5c839b8b2c..2494a38ad98 100644--- a/gateway/session_controls.py+++ b/gateway/session_controls.py@@ -445,9 +445,6 @@ class AuthorityConnection:if type(hidden) is not bool:raise RuntimeStoreError('invalid_params', field='hidden', detail='must be a boolean')ref = title and resolve_titled_session(self.authority, self.actor, title, missing_ok=True)- if not ref and title == 'Bot Chat':- from gateway.session_bot import move_aside_superseded_bot_chat- await move_aside_superseded_bot_chat(self.authority)if (not ref and title == 'Bot Chat'and not any(params.get(name) is True for name in BYPASS_FIELDS)and staged_creation_follows(self.authority, self.actor, params.get('request_id'))):@@ -483,6 +480,10 @@ class AuthorityConnection:from hermes_state_local import local_receiptpolicy = restore_policy(local_receipt(self.authority.db, ref.session_id)['policy'])await asyncio.to_thread(accept_launch_hooks, policy)+ if title == 'Bot Chat':+ # Only once the replacement is committed: a refused create leaves the old chat as it was.+ from gateway.session_bot import move_aside_superseded_bot_chat+ await move_aside_superseded_bot_chat(self.authority)if title:await tracked_write(self.authority, partial(title_new_session, self.authority, ref, title))if hidden:diff --git a/tests/gateway/test_handoff_local_receipt.py b/tests/gateway/test_handoff_local_receipt.pyindex 85f2a8bc03f..056b76c678a 100644--- a/tests/gateway/test_handoff_local_receipt.py+++ b/tests/gateway/test_handoff_local_receipt.py@@ -163,6 +163,10 @@ async def test_a_handed_off_bot_chat_whose_lane_moved_on_is_moved_aside(tmp_pathassert resolve_titled_session(cold, owner, 'Bot Chat', missing_ok=True) is Noneif door == 'Desktop create':connection = AuthorityConnection(cold, object(), {'user_id': owner.subject})+ with pytest.raises(RuntimeStoreError): # a refused create leaves the old chat as it was+ await connection.create(None, {'title': 'Bot Chat', 'request_id': 'bot-chat-bad', 'source': 'gui',+ 'cwd': str(tmp_path / 'missing'), 'model': 'frozen', 'toolsets': []})+ assert cold.db.get_session_by_title('Bot Chat')['id'] == ref.session_idopened = await connection.create(None, {'title': 'Bot Chat', 'request_id': 'bot-chat-2', 'source': 'gui','cwd': str(tmp_path), 'model': 'frozen', 'toolsets': [], 'hidden': True})fresh = opened['session_id']