chenhg5/cc-connect · error
wps-xiezuo: invalid session key %q
Error message
wps-xiezuo: invalid session key %q
What it means
ReconstructReplyCtx parses a session key expected in the format "wps-xiezuo:{company_id}:{chat_id}" (optionally ":{sender_id}"); if the key has fewer than 3 colon-separated parts or doesn't start with "wps-xiezuo", it returns this error.
Source
Thrown at platform/wps-xiezuo/wpsxiezuo.go:1009
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
respBody, _ := io.ReadAll(resp.Body)
return fmt.Errorf("delete reaction failed: status=%d body=%s", resp.StatusCode, string(respBody))
}
return nil
}
// --- Optional interface: ReplyContextReconstructor ---
func (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {
// Formats:
// wps-xiezuo:{company_id}:{chat_id} - group or legacy P2P
// wps-xiezuo:{company_id}:{chat_id}:{sender_id} - P2P, user-scoped
parts := strings.SplitN(sessionKey, ":", 4)
if len(parts) < 3 || parts[0] != "wps-xiezuo" {
return nil, fmt.Errorf("wps-xiezuo: invalid session key %q", sessionKey)
}
rc := replyContext{
ChatID: parts[2],
CompanyID: parts[1],
}
if len(parts) == 4 {
rc.ChatType = "p2p"
rc.SenderID = parts[3]
}
return rc, nil
}
// --- Optional interface: TypingIndicator ---
func (p *Platform) StartTyping(ctx context.Context, rctx any) (stop func()) {
rc, ok := rctx.(replyContext)
if !ok {
return func() {}View on GitHub (pinned to 4000b2338a)
Solutions
- Print the full sessionKey and compare with the documented format "wps-xiezuo:{company_id}:{chat_id}[:{sender_id}]"
- Ensure the key originates from this platform's reply-context generation, not another adapter
- Fix the persistence layer storing truncated keys
- Guard with a prefix check (strings.HasPrefix(key, "wps-xiezuo:")) before calling
Example fix
// before
rc, err := p.ReconstructReplyCtx(storedKey) // storedKey = "xiezuo:123:456"
// after
if !strings.HasPrefix(storedKey, "wps-xiezuo:") { /* regenerate or skip */ }
rc, err := p.ReconstructReplyCtx(storedKey) Defensive patterns
Strategy: validation
Validate before calling
func isValidXiezuoSessionKey(k string) bool { return strings.HasPrefix(k, "wps-xiezuo:") && len(strings.SplitN(k, ":", 4)) >= 3 } Try / catch
rc, err := p.ReconstructReplyCtx(key); if err != nil && strings.Contains(err.Error(), "invalid session key") { slog.Warn("skipping malformed session key", "key", key); return } Prevention
- Only build session keys via the platform's own context generation
- Include a version prefix in persisted session keys
- Validate keys at persistence time, not just at read time
When it happens
Trigger: Passing a session key from a different platform, a manually constructed key, a key with missing fields, or a truncated/corrupted stored key into ReconstructReplyCtx.
Common situations: Persisted session keys from an older format being replayed after an upgrade; copying a key from another platform adapter; trimming the key string incorrectly before calling.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- invalid source session key: %w
- invalid session key format: %q
- dingtalk: invalid session key format: %q
- discord: invalid session key %q
- line: invalid session key %q
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/06a39f583f04227e.
Report an issue: GitHub.