{"record":{"id":"1742fdabea60f5ab","repo":"HKUDS/Vibe-Trading","slug":"wechat-client-not-initialized-or-not-authenticated","errorCode":null,"errorMessage":"WeChat client not initialized or not authenticated","messagePattern":"WeChat client not initialized or not authenticated","errorType":"error_code","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/src/channels/weixin.py","lineNumber":1090,"sourceCode":"            \"status\": status,\n            \"base_info\": BASE_INFO,\n        }\n        await self._api_post(\"ilink/bot/sendtyping\", body)\n\n    async def _typing_keepalive_loop(self, user_id: str, typing_ticket: str, stop_event: asyncio.Event) -> None:\n        try:\n            while not stop_event.is_set():\n                await asyncio.sleep(TYPING_KEEPALIVE_INTERVAL_S)\n                if stop_event.is_set():\n                    break\n                with suppress(Exception):\n                    await self._send_typing(user_id, typing_ticket, TYPING_STATUS_TYPING)\n        finally:\n            pass\n\n    async def send(self, msg: OutboundMessage) -> None:\n        if not self._client or not self._token:\n            raise RuntimeError(\"WeChat client not initialized or not authenticated\")\n        self._assert_session_active()\n\n        is_progress = bool((msg.metadata or {}).get(\"_progress\", False))\n\n        # Buffer tool hints to coalesce consecutive ones and avoid burning\n        # WeChat iLink rate-limit quota (~7 msgs / 5 min).\n        if is_progress and (msg.metadata or {}).get(\"_tool_hint\"):\n            if not self.send_tool_hints:\n                return\n            self._pending_tool_hints.setdefault(msg.chat_id, []).append(msg.content)\n            self.logger.debug(\n                \"Buffered tool hint for {} (count={})\",\n                msg.chat_id,\n                len(self._pending_tool_hints[msg.chat_id]),\n            )\n            return\n\n        # Reasoning deltas are invisible in WeChat (there is no reasoning","sourceCodeStart":1072,"sourceCodeEnd":1108,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/channels/weixin.py#L1072-L1108","documentation":"Public send() refuses to dispatch when the channel's internal _client or _token is missing, meaning the channel was never started or authentication never completed. This is a precondition check so callers fail fast instead of sending into an uninitialized WeChat iLink client.","triggerScenarios":"Calling send(msg) on a WeixinChannel before start() completed the QR login, or after the client/token were cleared (failed login, shutdown).","commonSituations":"Sending a welcome/broadcast message at application startup before the channel finished QR login; integrating the channel into a framework that fires outbound hooks during initialization; login failed silently earlier and the error surfaces only at first send.","solutions":["Ensure start() (and successful QR login) completes before any send(); await a readiness signal/event.","Check login status/logs first — if QR was never scanned or login failed, complete authentication.","If the channel was shut down, restart and re-authenticate before sending.","Add a guard in caller code to queue messages until the channel reports ready."],"exampleFix":"// before\nawait weixin_channel.send(msg)\n\n// after\nawait weixin_channel.wait_until_ready()  # or check a ready flag\nawait weixin_channel.send(msg)","handlingStrategy":"validation","validationCode":"def channel_ready(ch) -> bool:\n    return bool(getattr(ch, \"_client\", None) and getattr(ch, \"_token\", None))\n\nif channel_ready(channel):\n    await channel.send(msg)","typeGuard":"def is_ready(ch: \"WeixinChannel\") -> bool:\n    return ch._client is not None and bool(ch._token)","tryCatchPattern":"try:\n    await channel.send(msg)\nexcept RuntimeError as e:\n    if \"not initialized or not authenticated\" in str(e):\n        queue_for_later(msg)  # resend after login completes\n    else:\n        raise","preventionTips":["Await channel start/login before enabling outbound handlers.","Expose and await a readiness event.","Queue messages produced during startup."],"tags":["wechat","initialization","authentication","precondition"],"backgroundTag":"client-not-initialized","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}