chenhg5/cc-connect · error
wecom-ws: invalid session key %q
Error message
wecom-ws: invalid session key %q
What it means
Guard in ReconstructReplyCtx: the session key string does not match the expected 'wecom:{chatID}:{userID}' format (wrong prefix, or fewer/malformed colon-separated parts), so a wsReplyContext cannot be rebuilt. This is a format-validation failure on a persistent session identifier, exercised by the TestReconstructReplyCtx_* cases.
Source
Thrown at platform/wecom/websocket.go:544
if err := p.writeAndWaitAck(ctx, frame, reqID); err != nil {
slog.Error("wecom-ws: send failed", "user", rc.userID, "chunk", i, "error", err)
return err
}
}
slog.Debug("wecom-ws: message sent", "user", rc.userID, "chunks", len(chunks), "total_len", len(content))
return nil
}
// ReconstructReplyCtx rebuilds a reply context from a session key.
// Session key format: "wecom:{chatID}:{userID}".
// The reconstructed context has no req_id, so Reply() (which needs req_id for
// aibot_respond_msg) won't work — the engine should use Send() (aibot_send_msg)
// for cron/relay scenarios.
func (p *WSPlatform) ReconstructReplyCtx(sessionKey string) (any, error) {
// wecom:{chatID}:{userID}
parts := strings.SplitN(sessionKey, ":", 3)
if len(parts) < 3 || parts[0] != "wecom" {
return nil, fmt.Errorf("wecom-ws: invalid session key %q", sessionKey)
}
return wsReplyContext{chatID: parts[1], userID: parts[2]}, nil
}
func (p *WSPlatform) Stop() error {
if p.cancel != nil {
p.cancel()
}
p.mu.Lock()
conn := p.conn
p.mu.Unlock()
if conn != nil {
return conn.Close()
}
return nil
}
// writeJSON sends a JSON message over the WebSocket connection with mutex protection.View on GitHub (pinned to 4000b2338a)
Solutions
- Check how the session key was produced — only keys minted by this platform's session manager parse back
- Reject unknown prefixes early in the engine so wecom never receives keys from other platforms
- Log the offending key (it is already included via %q) to trace which flow produced it
- Return the error to the caller so cron/relay sends are skipped rather than misaddressed
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at platform/wecom/websocket.go:544 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/0a300871eb805eac.
Report an issue: GitHub.