{"record":{"id":"aa6f305a377acd26","repo":"BigPizzaV3/CodexPlusPlus","slug":"context-token","errorCode":null,"errorMessage":"微信回复缺少 context_token","messagePattern":"微信回复缺少 context_token","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/connect/weixin.rs","lineNumber":256,"sourceCode":"        if updates.ret != 0 || updates.errcode != 0 {\n            bail!(\n                \"微信长轮询被拒绝：ret={} errcode={} {}\",\n                updates.ret,\n                updates.errcode,\n                updates.errmsg\n            );\n        }\n        Ok(updates)\n    }\n\n    pub async fn send_text_chunks(\n        &self,\n        to_user_id: &str,\n        text: &str,\n        context_token: &str,\n    ) -> anyhow::Result<()> {\n        if context_token.trim().is_empty() {\n            bail!(\"微信回复缺少 context_token\");\n        }\n        for chunk in chunk_text(text, MAX_REPLY_CHARS) {\n            self.send_text(to_user_id, &chunk, context_token).await?;\n            tokio::time::sleep(Duration::from_millis(100)).await;\n        }\n        Ok(())\n    }\n\n    async fn send_text(\n        &self,\n        to_user_id: &str,\n        text: &str,\n        context_token: &str,\n    ) -> anyhow::Result<()> {\n        let request_body = json!({\n            \"msg\": {\n                \"from_user_id\": \"\",\n                \"to_user_id\": to_user_id,","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/connect/weixin.rs#L238-L274","documentation":"send_text_chunks chunks a reply and sends each piece via send_text using the conversation's context_token; it validates upfront that the token is non-empty and bails with this message otherwise. context_token is required by WeChat to associate the reply with the original message, so sending without it would silently fail server-side.","triggerScenarios":"Calling send_text_chunks (directly or via process_weixin_message) with a context_token argument that is empty or whitespace-only — usually because the incoming WeixinUpdate/message did not carry one.","commonSituations":"Upstream message lacked a context_token (e.g. certain message types or API change); token field lost during deserialization into the update struct; replying to a synthesized message that never had a context.","solutions":["Log the raw incoming update and confirm whether context_token was present","Only call send_text_chunks for messages that carry a non-empty context_token","Check for WeChat API changes to the update payload and fix the struct/field mapping","For messages without a token, send via an alternative path or drop the reply with a warning"],"exampleFix":"// before\nclient.send_text_chunks(&to_user_id, &reply, &update.context_token).await?;\n// after\nif update.context_token.trim().is_empty() {\n    tracing::warn!(\"update {} has no context_token; skipping reply\", update.msg_id);\n} else {\n    client.send_text_chunks(&to_user_id, &reply, &update.context_token).await?;\n}","handlingStrategy":"validation","validationCode":"if context_token.trim().is_empty() {\n    tracing::warn!(\"no context_token; cannot reply to user {to_user_id}\");\n    return Ok(());\n}","typeGuard":"fn has_context_token(t: &str) -> bool { !t.trim().is_empty() }","tryCatchPattern":"match send_text_chunks(&to, &reply, &ctx_token).await {\n    Err(e) if e.to_string().contains(\"微信回复缺少 context_token\") => {\n        tracing::warn!(\"dropping reply: missing context_token\");\n        Ok(())\n    }\n    other => other,\n}","preventionTips":["Validate incoming updates carry context_token before enqueueing replies","Log raw payloads when the field is absent to catch API changes","Skip or route-around replies for messages without a token","Add struct-level serde defaults + explicit checks at reply time"],"tags":["wechat","validation","missing-field","reply"],"backgroundTag":"empty-required-field","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"}