chenhg5/cc-connect · error
matrix: invalid session key %q
Error message
matrix: invalid session key %q
What it means
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.
Source
Thrown at platform/matrix/matrix.go:615
newContent.Mentions = nil
parsed.NewContent = &newContent
parsed.RelatesTo = &event.RelatesTo{
Type: event.RelReplace,
EventID: rc.messageID,
}
parsed.Body = "* " + content
return p.sendRoomEvent(ctx, rc.roomID, event.EventMessage, &parsed)
}
func (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {
// Formats:
// matrix:{roomID}:{userID} - per-user session
// matrix:{roomID} - shared session
// Room IDs contain a colon (!localpart:server), so we can't simply split on colons.
if !strings.HasPrefix(sessionKey, "matrix:") {
return nil, fmt.Errorf("matrix: invalid session key %q", sessionKey)
}
rest := sessionKey[len("matrix:"):]
if rest == "" {
return nil, fmt.Errorf("matrix: invalid session key %q", sessionKey)
}
// Find boundary between room ID and optional user ID.
// User IDs start with @, so ":@" only appears at the roomID:userID boundary.
var roomIDStr string
if idx := strings.Index(rest, ":@"); idx >= 0 {
roomIDStr = rest[:idx]
} else {
roomIDStr = rest
}
if !strings.HasPrefix(roomIDStr, "!") {
return nil, fmt.Errorf("matrix: invalid room ID in %q", sessionKey)
}View on GitHub (pinned to 4000b2338a)
Solutions
- Check the persisted key format 'matrix:<roomID>[:<userID>]'
- Regenerate the session by receiving a message in the room
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at platform/matrix/matrix.go:615 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/b44a6c2c35da4ce4.
Report an issue: GitHub.