{"record":{"id":"c850071b48cf5ee5","repo":"BigPizzaV3/CodexPlusPlus","slug":"error-codex-wechat","errorCode":null,"errorMessage":"error","messagePattern":"error","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"tools/codex-wechat/codex_wechat.py","lineNumber":538,"sourceCode":"            elif method == \"item/agentMessage/delta\":\n                if final_item_id and params.get(\"turnId\") == turn_id and params.get(\"itemId\") == final_item_id:\n                    final_chunks.append(str(params.get(\"delta\") or \"\"))\n            elif method == \"item/completed\":\n                item = params.get(\"item\") or {}\n                if item.get(\"type\") == \"agentMessage\" and item.get(\"phase\") == \"final_answer\":\n                    text = str(item.get(\"text\") or \"\")\n                    if text:\n                        final_chunks = [text]\n            elif method == \"turn/completed\" and params.get(\"turn\", {}).get(\"id\") == turn_id:\n                turn = params.get(\"turn\") or {}\n                if turn.get(\"status\") == \"failed\":\n                    error = str((turn.get(\"error\") or {}).get(\"message\") or \"turn failed\")\n                completed = True\n\n        if not completed:\n            raise TimeoutError(\"app-server turn 超时\")\n        if error:\n            raise RuntimeError(error)\n\n        reply = \"\".join(final_chunks).strip()\n        return reply or \"Codex 没有返回最终答复。\"\n\n\nclass CodexRunner:\n    def __init__(self, cfg: BridgeConfig):\n        self.cfg = cfg\n        self.app_server: AppServerCodexClient | None = None\n        if cfg.codex.backend == \"app-server\":\n            self.app_server = AppServerCodexClient(cfg)\n            atexit.register(self.app_server.close)\n\n    def run(self, user_id: str, prompt: str) -> str:\n        if self.app_server:\n            try:\n                log(\"调用 codex app-server\")\n                return self.app_server.run(user_id, prompt)","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/tools/codex-wechat/codex_wechat.py#L520-L556","documentation":"In _collect_turn, a notification with method 'error' arrives from the app-server (turn aborted, invalid turn id, internal model error). The handler raises it so the user's prompt fails fast instead of waiting for a turn/completed that will never come.","triggerScenarios":"Thrown at tools/codex-wechat/codex_wechat.py:538 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the error payload in the notification for the underlying cause (quota, model unavailable, malformed turn).","Retry the turn if the cause is transient; otherwise surface the message back to the WeChat user.","Verify the turn was started with a valid session/turn id from the previous turn/start response."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}