chenhg5/cc-connect · error

bridge: cannot determine adapter from session key %q

Error message

bridge: cannot determine adapter from session key %q

What it means

BridgePlatform.ReconstructReplyCtx parses the session key to determine which downstream adapter (platform) the reply belongs to, via server.platformFromSessionKey. When the session key's format doesn't carry a recognizable platform segment, the bridge cannot route the reconstructed reply context and returns this error.

Source

Thrown at core/bridge.go:351

		return fmt.Errorf("bridge: invalid reply context type %T", replyCtx)
	}
	return bp.server.sendToAdapter(rc.Platform, map[string]any{
		"type":        "reply",
		"session_key": rc.SessionKey,
		"reply_ctx":   rc.ReplyCtx,
		"content":     content,
		"format":      "text",
	})
}

func (bp *BridgePlatform) Send(ctx context.Context, replyCtx any, content string) error {
	return bp.Reply(ctx, replyCtx, content)
}

func (bp *BridgePlatform) ReconstructReplyCtx(sessionKey string) (any, error) {
	platform := bp.server.platformFromSessionKey(sessionKey)
	if platform == "" {
		return nil, fmt.Errorf("bridge: cannot determine adapter from session key %q", sessionKey)
	}
	a := bp.server.getAdapter(platform)
	if a == nil {
		return nil, fmt.Errorf("bridge: adapter %q not connected", platform)
	}
	if !a.capabilities["reconstruct_reply"] {
		return nil, fmt.Errorf("bridge: adapter %q does not support reconstruct_reply", platform)
	}
	replyCtx, err := buildBridgeReconstructReplyCtx(bp.project, sessionKey)
	if err != nil {
		return nil, err
	}
	return newBridgeReplyCtx(a, sessionKey, replyCtx), nil
}

func newBridgeReplyCtx(a *bridgeAdapter, sessionKey, replyCtx string) *bridgeReplyCtx {
	rc := &bridgeReplyCtx{
		SessionKey: sessionKey,

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Log the full session key and verify it contains the expected ':<adapter>:' segment; fix whatever truncated or mangled it.
  2. Re-fetch the session key from the engine/session manager rather than reconstructing it manually.
  3. Ensure the bridge adapter named in the key is registered/enabled in the current config (renames change the key's resolvable prefix).

Example fix

// before
replyCtx, err := bp.ReconstructReplyCtx(row.ChatID) // ChatID is not a session key

// after
replyCtx, err := bp.ReconstructReplyCtx(row.SessionKey) // full key like "bridge:feishu:oc_xxx"
Defensive patterns

Strategy: validation

Validate before calling

func validBridgeSessionKey(key string) bool {
    parts := strings.SplitN(key, ":", 3)
    return len(parts) >= 2 && parts[0] != "" && parts[1] != ""
}
// call before ReconstructReplyCtx

Try / catch

rc, err := bp.ReconstructReplyCtx(key)
if err != nil && strings.Contains(err.Error(), "cannot determine adapter") {
    slog.Error("unroutable session key", "key", key)
    return err
}

Prevention

When it happens

Trigger: Calling ReconstructReplyCtx with a session key that is empty, was produced by a non-bridge platform, was truncated when stored, or whose adapter segment no longer matches a registered bridge adapter name.

Common situations: Storing truncated session keys in a database column with a size limit; hand-building session keys instead of using the value the engine provides; adapter/plugin renamed in config so the key's prefix no longer resolves.

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


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/bc5e3dfe272ad3da. Report an issue: GitHub.