{"record":{"id":"6ffcdf043d746265","repo":"chenhg5/cc-connect","slug":"yuanbao-invalid-session-key-q","errorCode":null,"errorMessage":"yuanbao: invalid session key %q","messagePattern":"yuanbao: invalid session key %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/yuanbao/platform.go","lineNumber":432,"sourceCode":"\tws := p.getWS()\n\tif ws == nil {\n\t\treturn fmt.Errorf(\"yuanbao: not connected\")\n\t}\n\terr := ws.WriteMessage(websocket.BinaryMessage, frame)\n\tif err != nil {\n\t\tslog.Error(\"yuanbao: reply send failed\", \"error\", err)\n\t}\n\treturn err\n}\n\nfunc (p *Platform) Send(ctx context.Context, rctx any, content string) error {\n\treturn p.Reply(ctx, rctx, content)\n}\n\nfunc (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {\n\tparts := strings.SplitN(sessionKey, \":\", 3)\n\tif len(parts) < 2 || parts[0] != \"yuanbao\" {\n\t\treturn nil, fmt.Errorf(\"yuanbao: invalid session key %q\", sessionKey)\n\t}\n\tchatID := parts[1]\n\tisGroup := strings.HasPrefix(chatID, \"group:\")\n\ttargetID := strings.TrimPrefix(chatID, \"dm:\")\n\ttargetID = strings.TrimPrefix(targetID, \"group:\")\n\treturn replyContext{\n\t\tchatType: map[bool]string{true: \"group\", false: \"dm\"}[isGroup],\n\t\tchatID:   chatID,\n\t\ttargetID: targetID,\n\t}, nil\n}\n\nfunc (p *Platform) Stop() error {\n\tp.mu.Lock()\n\tp.shouldReconnect = false\n\tws := p.ws\n\tp.mu.Unlock()\n\tif ws != nil {","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/yuanbao/platform.go#L414-L450","documentation":"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:...\".","triggerScenarios":"Passing a session key from another platform, a key missing the \"yuanbao\" prefix, an empty string, or a malformed stored key into ReconstructReplyCtx.","commonSituations":"Restoring sessions persisted by a different adapter; upgrading from an old key format; manual editing of persisted state corrupting the key.","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"],"exampleFix":"// before\nctx, err := p.ReconstructReplyCtx(\"12345\") // no \"yuanbao:\" prefix\n// after\nctx, err := p.ReconstructReplyCtx(\"yuanbao:group:12345\")","handlingStrategy":"validation","validationCode":"func isValidYuanbaoSessionKey(k string) bool { p := strings.SplitN(k, \":\", 3); return len(p) >= 2 && p[0] == \"yuanbao\" && p[1] != \"\" }","typeGuard":null,"tryCatchPattern":"rc, err := p.ReconstructReplyCtx(key); if err != nil && strings.Contains(err.Error(), \"invalid session key\") { slog.Warn(\"bad yuanbao session key\", \"key\", key); return }","preventionTips":["Generate session keys only through yuanbao's own reply-context path","Version-stamp persisted session keys","Validate keys on write to the store"],"tags":["session-key","parsing","yuanbao"],"backgroundTag":"invalid-argument-format","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}