chenhg5/cc-connect · error
yuanbao: invalid session key %q
Error message
yuanbao: invalid session key %q
What it means
ReconstructReplyCtx splits the session key on ":" and requires at least 2 parts with prefix "yuanbao"; otherwise it returns this error. Valid keys look like "yuanbao:{chat_id}" where chat_id is "group:..." or "dm:...".
Source
Thrown at platform/yuanbao/platform.go:432
ws := p.getWS()
if ws == nil {
return fmt.Errorf("yuanbao: not connected")
}
err := ws.WriteMessage(websocket.BinaryMessage, frame)
if err != nil {
slog.Error("yuanbao: reply send failed", "error", err)
}
return err
}
func (p *Platform) Send(ctx context.Context, rctx any, content string) error {
return p.Reply(ctx, rctx, content)
}
func (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {
parts := strings.SplitN(sessionKey, ":", 3)
if len(parts) < 2 || parts[0] != "yuanbao" {
return nil, fmt.Errorf("yuanbao: invalid session key %q", sessionKey)
}
chatID := parts[1]
isGroup := strings.HasPrefix(chatID, "group:")
targetID := strings.TrimPrefix(chatID, "dm:")
targetID = strings.TrimPrefix(targetID, "group:")
return replyContext{
chatType: map[bool]string{true: "group", false: "dm"}[isGroup],
chatID: chatID,
targetID: targetID,
}, nil
}
func (p *Platform) Stop() error {
p.mu.Lock()
p.shouldReconnect = false
ws := p.ws
p.mu.Unlock()
if ws != nil {View on GitHub (pinned to 4000b2338a)
Solutions
- Verify the key format is "yuanbao:{group:ID|dm:ID}" and starts with "yuanbao:"
- Regenerate the key from a live inbound message instead of replaying stale state
- Add a prefix/type check before calling ReconstructReplyCtx
- Fix whatever persistence layer truncated or mismatched the key
Example fix
// before
ctx, err := p.ReconstructReplyCtx("12345") // no "yuanbao:" prefix
// after
ctx, err := p.ReconstructReplyCtx("yuanbao:group:12345") Defensive patterns
Strategy: validation
Validate before calling
func isValidYuanbaoSessionKey(k string) bool { p := strings.SplitN(k, ":", 3); return len(p) >= 2 && p[0] == "yuanbao" && p[1] != "" } Try / catch
rc, err := p.ReconstructReplyCtx(key); if err != nil && strings.Contains(err.Error(), "invalid session key") { slog.Warn("bad yuanbao session key", "key", key); return } Prevention
- Generate session keys only through yuanbao's own reply-context path
- Version-stamp persisted session keys
- Validate keys on write to the store
When it happens
Trigger: Passing a session key from another platform, a key missing the "yuanbao" prefix, an empty string, or a malformed stored key into ReconstructReplyCtx.
Common situations: Restoring sessions persisted by a different adapter; upgrading from an old key format; manual editing of persisted state corrupting the key.
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/6ffcdf043d746265.
Report an issue: GitHub.