{"record":{"id":"0a300871eb805eac","repo":"chenhg5/cc-connect","slug":"wecom-ws-invalid-session-key-q","errorCode":null,"errorMessage":"wecom-ws: invalid session key %q","messagePattern":"wecom-ws: invalid session key %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wecom/websocket.go","lineNumber":544,"sourceCode":"\t\tif err := p.writeAndWaitAck(ctx, frame, reqID); err != nil {\n\t\t\tslog.Error(\"wecom-ws: send failed\", \"user\", rc.userID, \"chunk\", i, \"error\", err)\n\t\t\treturn err\n\t\t}\n\t}\n\tslog.Debug(\"wecom-ws: message sent\", \"user\", rc.userID, \"chunks\", len(chunks), \"total_len\", len(content))\n\treturn nil\n}\n\n// ReconstructReplyCtx rebuilds a reply context from a session key.\n// Session key format: \"wecom:{chatID}:{userID}\".\n// The reconstructed context has no req_id, so Reply() (which needs req_id for\n// aibot_respond_msg) won't work — the engine should use Send() (aibot_send_msg)\n// for cron/relay scenarios.\nfunc (p *WSPlatform) ReconstructReplyCtx(sessionKey string) (any, error) {\n\t// wecom:{chatID}:{userID}\n\tparts := strings.SplitN(sessionKey, \":\", 3)\n\tif len(parts) < 3 || parts[0] != \"wecom\" {\n\t\treturn nil, fmt.Errorf(\"wecom-ws: invalid session key %q\", sessionKey)\n\t}\n\treturn wsReplyContext{chatID: parts[1], userID: parts[2]}, nil\n}\n\nfunc (p *WSPlatform) Stop() error {\n\tif p.cancel != nil {\n\t\tp.cancel()\n\t}\n\tp.mu.Lock()\n\tconn := p.conn\n\tp.mu.Unlock()\n\tif conn != nil {\n\t\treturn conn.Close()\n\t}\n\treturn nil\n}\n\n// writeJSON sends a JSON message over the WebSocket connection with mutex protection.","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wecom/websocket.go#L526-L562","documentation":"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.","triggerScenarios":"Thrown at platform/wecom/websocket.go:544 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}