{"record":{"id":"b44a6c2c35da4ce4","repo":"chenhg5/cc-connect","slug":"matrix-invalid-session-key-q","errorCode":null,"errorMessage":"matrix: invalid session key %q","messagePattern":"matrix: invalid session key %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/matrix/matrix.go","lineNumber":615,"sourceCode":"\tnewContent.Mentions = nil\n\n\tparsed.NewContent = &newContent\n\tparsed.RelatesTo = &event.RelatesTo{\n\t\tType:    event.RelReplace,\n\t\tEventID: rc.messageID,\n\t}\n\tparsed.Body = \"* \" + content\n\n\treturn p.sendRoomEvent(ctx, rc.roomID, event.EventMessage, &parsed)\n}\n\nfunc (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {\n\t// Formats:\n\t//   matrix:{roomID}:{userID}   - per-user session\n\t//   matrix:{roomID}            - shared session\n\t// Room IDs contain a colon (!localpart:server), so we can't simply split on colons.\n\tif !strings.HasPrefix(sessionKey, \"matrix:\") {\n\t\treturn nil, fmt.Errorf(\"matrix: invalid session key %q\", sessionKey)\n\t}\n\trest := sessionKey[len(\"matrix:\"):]\n\tif rest == \"\" {\n\t\treturn nil, fmt.Errorf(\"matrix: invalid session key %q\", sessionKey)\n\t}\n\n\t// Find boundary between room ID and optional user ID.\n\t// User IDs start with @, so \":@\" only appears at the roomID:userID boundary.\n\tvar roomIDStr string\n\tif idx := strings.Index(rest, \":@\"); idx >= 0 {\n\t\troomIDStr = rest[:idx]\n\t} else {\n\t\troomIDStr = rest\n\t}\n\n\tif !strings.HasPrefix(roomIDStr, \"!\") {\n\t\treturn nil, fmt.Errorf(\"matrix: invalid room ID in %q\", sessionKey)\n\t}","sourceCodeStart":597,"sourceCodeEnd":633,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/matrix/matrix.go#L597-L633","documentation":"matrix ReconstructReplyCtx guard: sessionKey lacks the 'matrix:' prefix or has no roomID segment. Because Matrix room IDs themselves contain colons, parsing uses the ':@' boundary and rejects malformed keys instead of mis-splitting.","triggerScenarios":"Thrown at platform/matrix/matrix.go:615 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the persisted key format 'matrix:<roomID>[:<userID>]'","Regenerate the session by receiving a message in the room"],"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"}