chenhg5/cc-connect · error
bridge: invalid session key %q
Error message
bridge: invalid session key %q
What it means
bridgeTransportChatID splits a session key on ':' and requires at least two parts with a non-empty second segment (the transport chat ID). Keys that are too short or have an empty chat-ID component are rejected with this error while building a reconstruct reply context.
Source
Thrown at core/bridge.go:464
}
payload := bridgeReconstructReplyCtxPayload{
Kind: bridgeReconstructReplyCtxKind,
Version: 1,
SenderProject: project,
TransportChatID: chatID,
TransportSessionKey: sessionKey,
}
data, err := json.Marshal(payload)
if err != nil {
return "", fmt.Errorf("bridge: marshal reconstruct reply ctx: %w", err)
}
return string(data), nil
}
func bridgeTransportChatID(sessionKey string) (string, error) {
parts := strings.SplitN(sessionKey, ":", 3)
if len(parts) < 2 || parts[1] == "" {
return "", fmt.Errorf("bridge: invalid session key %q", sessionKey)
}
return parts[1], nil
}
func (bp *BridgePlatform) SendCard(ctx context.Context, replyCtx any, card *Card) error {
rc, ok := replyCtx.(*bridgeReplyCtx)
if !ok {
return fmt.Errorf("bridge: invalid reply context")
}
a := bp.server.getAdapter(rc.Platform)
if a == nil || !a.capabilities["card"] {
return bp.Reply(ctx, replyCtx, card.RenderText())
}
return bp.server.sendToAdapter(rc.Platform, map[string]any{
"type": "card",
"session_key": rc.SessionKey,
"reply_ctx": rc.ReplyCtx,
"card": serializeCard(card),View on GitHub (pinned to 4000b2338a)
Solutions
- Print the session key and confirm it matches the expected "prefix:chatID[:extra]" shape before calling.
- Fix the producer of the key (session manager / persistence layer) so it always stores the full key.
- Add a migration/validator for stored keys and skip or repair rows with empty chat-ID segments.
Example fix
// before
replyCtx, err := bp.ReconstructReplyCtx(strings.ToUpper(key)) // mangling/format drift
// after
if strings.Count(key, ":") < 1 { return fmt.Errorf("stored key %q malformed", key) }
replyCtx, err := bp.ReconstructReplyCtx(key) Defensive patterns
Strategy: validation
Validate before calling
func keyHasChatID(key string) bool {
parts := strings.SplitN(key, ":", 3)
return len(parts) >= 2 && parts[1] != ""
} Try / catch
if !keyHasChatID(key) { return fmt.Errorf("stored key %q missing chat ID", key) }
rc, err := bp.ReconstructReplyCtx(key)
if err != nil { return err } Prevention
- Validate session key shape at write time in your persistence layer.
- Migrate legacy keys from old formats explicitly.
- Treat empty key columns as data bugs, not empty optional values.
When it happens
Trigger: Calling ReconstructReplyCtx (which internally calls buildBridgeReconstructReplyCtx → bridgeTransportChatID) with a malformed session key such as "bridge:" or "feishu:" — empty, missing segments, or only the adapter prefix.
Common situations: Database rows where the session key column was never populated; keys built by string concatenation that dropped the chat ID; legacy keys from an older key format before a version migration.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- bridge: cannot determine adapter from session key %q
- invalid source session key: %w
- slack: invalid session key %q
- listen for Agy permission hooks: %w
- generate permission bridge token: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/7a476dc736c8bb32.
Report an issue: GitHub.