The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway/platforms): signal/bluebubbles — _close_client helper, health-monitor early continue
Teknium83420be9c239
diff --git a/gateway/platforms/bluebubbles.py b/gateway/platforms/bluebubbles.pyindex e33151e4421..1a28bbda685 100644--- a/gateway/platforms/bluebubbles.py+++ b/gateway/platforms/bluebubbles.py@@ -225,9 +225,7 @@ class BlueBubblesAdapter(BasePlatformAdapter):self.server_url, self._private_api_enabled, self._helper_connected)except Exception as exc:logger.error("[bluebubbles] cannot reach server at %s: %s", self.server_url, exc)- if self.client:- await self.client.aclose()- self.client = None+ await self._close_client()return False# client_max_size makes aiohttp enforce the cap on every read path,# including chunked requests with no Content-Length.@@ -249,11 +247,14 @@ class BlueBubblesAdapter(BasePlatformAdapter):self._wire_plugin_handlers(None)return True- async def disconnect(self) -> None:- await self._unregister_webhook()+ async def _close_client(self) -> None:if self.client:await self.client.aclose()self.client = None++ async def disconnect(self) -> None:+ await self._unregister_webhook()+ await self._close_client()if self._runner:await self._runner.cleanup()self._runner = Nonediff --git a/gateway/platforms/signal.py b/gateway/platforms/signal.pyindex 05f58e6b404..3fbcded8a27 100644--- a/gateway/platforms/signal.py+++ b/gateway/platforms/signal.py@@ -262,12 +262,15 @@ class SignalAdapter(BasePlatformAdapter):return Truefinally:if not self._running:- if self.client:- await self.client.aclose()- self.client = None+ await self._close_client()if lock_acquired:self._release_platform_lock()+ async def _close_client(self) -> None:+ if self.client:+ await self.client.aclose()+ self.client = None+@staticmethodasync def _cancel_task(task: Optional[asyncio.Task]) -> None:if task:@@ -283,9 +286,7 @@ class SignalAdapter(BasePlatformAdapter):for task in self._typing_tasks.values():task.cancel()self._typing_tasks.clear()- if self.client:- await self.client.aclose()- self.client = None+ await self._close_client()self._release_platform_lock()logger.info("Signal: disconnected")@@ -353,16 +354,17 @@ class SignalAdapter(BasePlatformAdapter):logger.warning("Signal: SSE idle for %.0fs, checking daemon health", elapsed)try:resp = await self.client.get(f"{self.http_url}/api/v1/check", timeout=10.0)- if resp.status_code == 200:- # Daemon alive but SSE quiet — reset activity to avoid repeated warnings- self._last_sse_activity = time.time()- logger.debug("Signal: daemon healthy, SSE idle")- else:- logger.warning("Signal: health check failed (%d), forcing reconnect", resp.status_code)- self._force_reconnect()except Exception as e:logger.warning("Signal: health check error: %s, forcing reconnect", e)self._force_reconnect()+ continue+ if resp.status_code == 200:+ # Daemon alive but SSE quiet — reset activity to avoid repeated warnings+ self._last_sse_activity = time.time()+ logger.debug("Signal: daemon healthy, SSE idle")+ else:+ logger.warning("Signal: health check failed (%d), forcing reconnect", resp.status_code)+ self._force_reconnect()def _force_reconnect(self) -> None:"""Force SSE reconnection by closing the current response."""