chenhg5/cc-connect · error

weixin: not a weixin session key

Error message

weixin: not a weixin session key

What it means

ReconstructReplyCtx (used by cron/proactive sends) received a session key that does not start with the weixin sessionKeyPrefix, so it cannot belong to this platform — the key was produced by another platform or is malformed.

Solutions

  1. Route the reconstruction request to the platform that owns the session key (check the prefix) before calling ReconstructReplyCtx
  2. Verify cron/timer jobs store the full platform-prefixed session key when created
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at platform/weixin/weixin.go:909 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/025d2d0205c55420. Report an issue: GitHub.

Appendix: source

Thrown at platform/weixin/weixin.go:909

		return []string{s}
	}
	var out []string
	runes := []rune(s)
	for len(runes) > 0 {
		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)

View on GitHub (pinned to 4000b2338a)