chenhg5/cc-connect · error

weixin: no stored context_token for %q (user must message th

Error message

weixin: no stored context_token for %q (user must message the bot first)

What it means

ReconstructReplyCtx resolved a valid weixin session key, but the platform has no stored context_token for that peer — Weixin requires the user to have messaged the bot first so a reply context exists, so a proactive/cron send to this peer is impossible.

Source

Thrown at platform/weixin/weixin.go:914

		n := maxRunes
		if len(runes) < n {
			n = len(runes)
		}
		out = append(out, string(runes[:n]))
		runes = runes[n:]
	}
	return out
}

// ReconstructReplyCtx implements core.ReplyContextReconstructor for cron / proactive sends.
func (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {
	if !strings.HasPrefix(sessionKey, sessionKeyPrefix) {
		return nil, fmt.Errorf("weixin: not a weixin session key")
	}
	peer := strings.TrimPrefix(sessionKey, sessionKeyPrefix)
	tok := p.getContextToken(peer)
	if tok == "" {
		return nil, fmt.Errorf("weixin: no stored context_token for %q (user must message the bot first)", peer)
	}
	return &replyContext{peerUserID: peer, contextToken: tok}, nil
}

// FormattingInstructions implements core.FormattingInstructionProvider.
func (p *Platform) FormattingInstructions() string {
	return "Replies are delivered as plain text to Weixin. Avoid markdown tables; use short paragraphs."
}

var (
	_ core.Platform                      = (*Platform)(nil)
	_ core.ReplyContextReconstructor     = (*Platform)(nil)
	_ core.FormattingInstructionProvider = (*Platform)(nil)
	_ core.ImageSender                   = (*Platform)(nil)
	_ core.FileSender                    = (*Platform)(nil)
	_ core.TypingIndicator               = (*Platform)(nil)
	_ core.AsyncRecoverablePlatform      = (*Platform)(nil)
)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Wait until the user sends the bot at least one message to establish a context_token, then re-enable the cron/proactive job
  2. Skip and log rather than retry-looping: the token will not appear until user interaction
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at platform/weixin/weixin.go:914 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/ed8953c0b3df0d82. Report an issue: GitHub.