chenhg5/cc-connect · error

wecom: invalid session key %q

Error message

wecom: invalid session key %q

What it means

Guard in the HTTP-platform ReconstructReplyCtx: the session key does not match the 'wecom:{userID}' format (missing prefix or fewer than two SplitN parts), so a usable reply context cannot be rebuilt for proactive sends. It indicates the engine handed this platform a session key minted elsewhere or a corrupted key.

Source

Thrown at platform/wecom/wecom.go:713

	if expires <= 0 {
		slog.Warn("wecom: missing/invalid expires_in in token response, defaulting to 7200s", "got", result.ExpiresIn)
		expires = 7200
	}
	if expires > 60 {
		expires -= 60
	}
	p.tokenCache.token = result.AccessToken
	p.tokenCache.expiresAt = time.Now().Add(time.Duration(expires) * time.Second)

	slog.Debug("wecom: access_token refreshed", "expires_in", result.ExpiresIn)
	return result.AccessToken, nil
}

func (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {
	// wecom:{userID}
	parts := strings.SplitN(sessionKey, ":", 2)
	if len(parts) < 2 || parts[0] != "wecom" {
		return nil, fmt.Errorf("wecom: invalid session key %q", sessionKey)
	}
	return replyContext{userID: parts[1]}, nil
}

func (p *Platform) Stop() error {
	if p.server != nil {
		return p.server.Shutdown(context.Background())
	}
	return nil
}

// --- Crypto helpers ---

// verifySignature checks SHA1(sort(token, timestamp, nonce, encrypt)).
func (p *Platform) verifySignature(expected, timestamp, nonce, encrypt string) bool {
	parts := []string{p.token, timestamp, nonce, encrypt}
	sort.Strings(parts)
	h := sha1.New()

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Ensure only session keys created by this platform's handler reach ReconstructReplyCtx
  2. Have the engine dispatch reconstruction by platform prefix so mismatched keys never arrive
  3. Log the offending key (included via %q) to trace the producing flow
  4. Return the error so the caller skips the proactive send instead of misaddressing it
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at platform/wecom/wecom.go:713 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/c49bd5c35a0922e7. Report an issue: GitHub.