BigPizzaV3/CodexPlusPlus · error

微信回复缺少 context_token

Error message

微信回复缺少 context_token

What it means

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.

Solutions

  1. Log the raw incoming update and confirm whether context_token was present
  2. Only call send_text_chunks for messages that carry a non-empty context_token
  3. Check for WeChat API changes to the update payload and fix the struct/field mapping
  4. For messages without a token, send via an alternative path or drop the reply with a warning

Example fix

// before
client.send_text_chunks(&to_user_id, &reply, &update.context_token).await?;
// after
if update.context_token.trim().is_empty() {
    tracing::warn!("update {} has no context_token; skipping reply", update.msg_id);
} else {
    client.send_text_chunks(&to_user_id, &reply, &update.context_token).await?;
}
Defensive patterns

Strategy: validation

Validate before calling

if context_token.trim().is_empty() {
    tracing::warn!("no context_token; cannot reply to user {to_user_id}");
    return Ok(());
}

Type guard

fn has_context_token(t: &str) -> bool { !t.trim().is_empty() }

Try / catch

match send_text_chunks(&to, &reply, &ctx_token).await {
    Err(e) if e.to_string().contains("微信回复缺少 context_token") => {
        tracing::warn!("dropping reply: missing context_token");
        Ok(())
    }
    other => other,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/aa6f305a377acd26. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/connect/weixin.rs:256

        if updates.ret != 0 || updates.errcode != 0 {
            bail!(
                "微信长轮询被拒绝:ret={} errcode={} {}",
                updates.ret,
                updates.errcode,
                updates.errmsg
            );
        }
        Ok(updates)
    }

    pub async fn send_text_chunks(
        &self,
        to_user_id: &str,
        text: &str,
        context_token: &str,
    ) -> anyhow::Result<()> {
        if context_token.trim().is_empty() {
            bail!("微信回复缺少 context_token");
        }
        for chunk in chunk_text(text, MAX_REPLY_CHARS) {
            self.send_text(to_user_id, &chunk, context_token).await?;
            tokio::time::sleep(Duration::from_millis(100)).await;
        }
        Ok(())
    }

    async fn send_text(
        &self,
        to_user_id: &str,
        text: &str,
        context_token: &str,
    ) -> anyhow::Result<()> {
        let request_body = json!({
            "msg": {
                "from_user_id": "",
                "to_user_id": to_user_id,

View on GitHub (pinned to b1ed92e5e4)