The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: keep relay reader live during canonical busy delivery
Teknium4485fb73d5a3
diff --git a/gateway/relay/adapter.py b/gateway/relay/adapter.pyindex 111959bb32c..8635a875d27 100644--- a/gateway/relay/adapter.py+++ b/gateway/relay/adapter.py@@ -840,7 +840,20 @@ class RelayAdapter(BasePlatformAdapter):if await self._consume_prompt_response(event):returnawait self._localize_inbound_media(event)- await self.handle_message(event)+ runner = getattr(self._message_handler, '__self__', None)+ if getattr(runner, 'session_authority', None) is not None:+ # Busy authority dispatch waits for the final. Never await it on the+ # WS reader: that same reader must receive the outbound_result ACK.+ task = asyncio.create_task(self.handle_message(event))+ self._background_tasks.add(task)+ task.add_done_callback(self._relay_ingress_done)+ else:+ await self.handle_message(event)++ def _relay_ingress_done(self, task):+ self._background_tasks.discard(task)+ if not task.cancelled() and (error := task.exception()) is not None:+ logger.error('Relay ingress failed', exc_info=error)_SEEN_INBOUND_MAX = 512diff --git a/tests/gateway/test_relay_authority.py b/tests/gateway/test_relay_authority.pyindex 44c8ff042f7..be965d10f74 100644--- a/tests/gateway/test_relay_authority.py+++ b/tests/gateway/test_relay_authority.py@@ -150,7 +150,7 @@ async def probe(peer):finally:peer.release.set()async with asyncio.timeout(10):- while adapter._active_sessions or any(r['status'] != 'terminal' for r in+ while any(not task.done() for task in adapter._background_tasks) or any(r['status'] != 'terminal' for r inlist_session_admissions(authority.db, session_id=sid, pending_only=False)):await asyncio.sleep(.01)rows = list_session_admissions(authority.db, session_id=sid, pending_only=False)