{"record":{"id":"628bd2b213fd4b95","repo":"BigPizzaV3/CodexPlusPlus","slug":"error-628bd2","errorCode":null,"errorMessage":"微信连接已停止","messagePattern":"微信连接已停止","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/codex-plus-core/src/connect/mod.rs","lineNumber":335,"sourceCode":"            server\n                .prepare_thread(None)\n                .await\n                .with_context(|| format!(\"恢复原会话失败（{error}），新建会话也失败\"))?\n        }\n        Err(error) => return Err(error),\n    };\n    state\n        .thread_ids\n        .insert(message.from_user_id.clone(), thread_id.clone());\n\n    let turn = server.run_turn(&thread_id, text);\n    tokio::pin!(turn);\n    let turn_result = loop {\n        tokio::select! {\n            reply = &mut turn => break reply?,\n            _ = tokio::time::sleep(std::time::Duration::from_millis(200)) => {\n                if stop.load(Ordering::SeqCst) {\n                    bail!(\"微信连接已停止\");\n                }\n            }\n        }\n    };\n    let reply = if turn_result.reply.trim().is_empty() {\n        \"Codex 已完成处理，但没有返回文字内容。\"\n    } else {\n        turn_result.reply.trim()\n    };\n    let reply_with_footer = append_reply_footer(reply, &turn_result, &app_config.work_dir);\n    client\n        .send_text_chunks(\n            &message.from_user_id,\n            &reply_with_footer,\n            &message.context_token,\n        )\n        .await\n}","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/connect/mod.rs#L317-L353","documentation":"During a WeChat-triggered Codex turn, the bridge races the turn against a stop flag: every 200ms it checks the shared AtomicBool, and if a stop was requested it aborts waiting and bails with this message. The turn task itself is dropped; this is the normal signal-initiated shutdown path, not a bug in Codex processing.","triggerScenarios":"Calling stop (setting the SharedStopFlag AtomicBool) while run_weixin_connect_with_codex_path is inside process_weixin_message awaiting a Codex turn reply.","commonSituations":"User clicks 'stop' in the manager UI mid-turn; app shutdown or profile switch cancels the bridge; a supervisor aborts a long-running turn.","solutions":["Treat this as an expected cancellation: catch it and exit the connect loop cleanly","If it fires unexpectedly, audit who sets the stop flag (UI stop button, shutdown hook)","Re-run the message/turn if its result is still needed — the turn was dropped, not completed"],"exampleFix":"// before\nlet reply = process_weixin_message(...).await?; // propagates 微信连接已停止\n// after\nmatch process_weixin_message(...).await {\n    Err(e) if e.to_string().contains(\"微信连接已停止\") => {\n        tracing::info!(\"weixin bridge stopped by request\");\n        return Ok(()); // expected shutdown\n    }\n    other => other?,\n}","handlingStrategy":"try-catch","validationCode":"// check the stop flag before starting an expensive turn\nif stop.load(Ordering::SeqCst) { return Ok(()); }","typeGuard":null,"tryCatchPattern":"match process_weixin_message(...).await {\n    Err(e) if e.to_string().contains(\"微信连接已停止\") => { /* expected shutdown */ Ok(()) }\n    other => other,\n}","preventionTips":["Treat this message as normal cancellation, not a failure","Check the stop flag before queuing new turns","Distinguish stop-caused errors from real failures in logs/UI","Persist turn state if resumability after stop matters"],"tags":["cancellation","shutdown","wechat","tokio","rust"],"backgroundTag":"operation-cancelled","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"}