The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(feishu): publish retrying when the SDK's own reconnect ladder runs
teknium188a9ca7be49d
diff --git a/plugins/platforms/feishu/adapter.py b/plugins/platforms/feishu/adapter.pyindex 42a2579f1e5..4e3621af252 100644--- a/plugins/platforms/feishu/adapter.py+++ b/plugins/platforms/feishu/adapter.py@@ -1091,6 +1091,10 @@ def _run_official_feishu_ws_client(ws_client: Any, adapter: Any) -> None:setattr(ws_client, "_reconnect_interval", adapter._ws_reconnect_interval)if adapter._ws_ping_interval is not None:setattr(ws_client, "_ping_interval", adapter._ws_ping_interval)+ # SDK observer (lark-oapi ``Client.on_reconnecting``, fired first thing in ``_reconnect()``):+ # on the live link ``_auto_reconnect`` is on, so the ladder runs *inside* the receive loop+ # and the thread never dies — without this the supervisor's ``retrying`` is never published.+ setattr(ws_client, "on_reconnecting", _on_reconnecting)except Exception:logger.debug("[Feishu] Failed to apply websocket runtime overrides", exc_info=True)@@ -1101,6 +1105,10 @@ def _run_official_feishu_ws_client(ws_client: Any, adapter: Any) -> None:}adapter_loop = adapter._loop+ def _on_reconnecting() -> None:+ if adapter_loop is not None and not adapter_loop.is_closed():+ adapter_loop.call_soon_threadsafe(adapter._ws_link_retrying, ws_client)+def _on_link_up() -> None:# Fired on the WS thread when the SDK scheduled a receive loop (handshake done); hop to the# adapter loop so the ``connected`` re-stamp after a supervisor rebuild runs where the adapter's@@ -3773,6 +3781,14 @@ class FeishuAdapter(BasePlatformAdapter):if self._running and self._ws_client is ws_client:self._mark_connected()+ def _ws_link_retrying(self, ws_client: Any) -> None:+ """WS thread reports the SDK's own reconnect ladder started; ``_ws_link_up`` re-stamps ``connected``."""+ if self._running and self._ws_client is ws_client:+ self._write_runtime_status_safe(+ "ws_link_lost", platform_state="retrying", error_code=None,+ error_message="Feishu websocket link lost; reconnecting",+ )+async def _connect_websocket(self) -> None:if not FEISHU_WEBSOCKET_AVAILABLE:raise RuntimeError("websockets not installed; websocket mode unavailable")diff --git a/tests/gateway/test_feishu_ws_multiplex_isolation.py b/tests/gateway/test_feishu_ws_multiplex_isolation.pyindex 302b98b1bcd..6ec3eba2754 100644--- a/tests/gateway/test_feishu_ws_multiplex_isolation.py+++ b/tests/gateway/test_feishu_ws_multiplex_isolation.py@@ -197,6 +197,42 @@ def test_receive_loop_normal_return_keeps_start_parked(monkeypatch):assert not thread.is_alive()+def test_sdk_reconnect_ladder_publishes_retrying(monkeypatch):+ """#113662, live path: with ``_auto_reconnect`` on, a receive-loop error runs+ the SDK's own ``_reconnect()`` ladder inside the WS thread — the thread does+ not die, so the supervisor never publishes ``retrying``. The SDK's+ ``on_reconnecting`` observer must hop to the adapter loop and publish it."""+ _inject_fake_lark_module(monkeypatch)+ adapter_loop = asyncio.new_event_loop()++ class FakeSDKClient:+ def __init__(self):+ self.on_reconnecting = lambda: None # SDK default: no-op observer++ def start(self):+ self.on_reconnecting() # what lark_oapi ``_reconnect()`` fires first++ client = FakeSDKClient()+ stub = _adapter_stub(_loop=adapter_loop, _running=True, _ws_client=client, status_writes=[])+ stub._write_runtime_status_safe = lambda context, **kw: stub.status_writes.append(kw["platform_state"])+ stub._ws_link_retrying = types.MethodType(feishu_adapter.FeishuAdapter._ws_link_retrying, stub)++ thread = threading.Thread(target=feishu_adapter._run_official_feishu_ws_client, args=(client, stub), daemon=True)+ thread.start()+ thread.join(timeout=10)+ assert not thread.is_alive()++ async def drain():+ for _ in range(100):+ if stub.status_writes:+ break+ await asyncio.sleep(0.01)++ adapter_loop.run_until_complete(drain())+ adapter_loop.close()+ assert stub.status_writes == ["retrying"]++def _supervisor_stub():stub = SimpleNamespace(_running=True,diff --git a/website/docs/user-guide/messaging/feishu.md b/website/docs/user-guide/messaging/feishu.mdindex a483395f636..1b5aadea999 100644--- a/website/docs/user-guide/messaging/feishu.md+++ b/website/docs/user-guide/messaging/feishu.md@@ -102,7 +102,7 @@ FEISHU_CONNECTION_MODE=websocket**Requirements:** The `websockets` Python package must be installed. The SDK handles connection lifecycle, heartbeats, and auto-reconnection internally.-**How it works:** The adapter runs the Lark SDK's WebSocket client in a background executor thread. Inbound events (messages, reactions, card actions) are dispatched to the main asyncio loop. On disconnect, the SDK will attempt to reconnect automatically.+**How it works:** The adapter runs the Lark SDK's WebSocket client in a background executor thread. Inbound events (messages, reactions, card actions) are dispatched to the main asyncio loop. On disconnect, the SDK will attempt to reconnect automatically. If the link dies outright (the SDK's retry ladder gives up or the client thread exits), Hermes' supervisor rebuilds the client with capped backoff. While a link is down, `hermes gateway status` shows the platform as `retrying` until the connection is re-established.### Optional: Webhook mode