{"record":{"id":"bc5e3dfe272ad3da","repo":"chenhg5/cc-connect","slug":"bridge-cannot-determine-adapter-from-session-key","errorCode":null,"errorMessage":"bridge: cannot determine adapter from session key %q","messagePattern":"bridge: cannot determine adapter from session key %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/bridge.go","lineNumber":351,"sourceCode":"\t\treturn fmt.Errorf(\"bridge: invalid reply context type %T\", replyCtx)\n\t}\n\treturn bp.server.sendToAdapter(rc.Platform, map[string]any{\n\t\t\"type\":        \"reply\",\n\t\t\"session_key\": rc.SessionKey,\n\t\t\"reply_ctx\":   rc.ReplyCtx,\n\t\t\"content\":     content,\n\t\t\"format\":      \"text\",\n\t})\n}\n\nfunc (bp *BridgePlatform) Send(ctx context.Context, replyCtx any, content string) error {\n\treturn bp.Reply(ctx, replyCtx, content)\n}\n\nfunc (bp *BridgePlatform) ReconstructReplyCtx(sessionKey string) (any, error) {\n\tplatform := bp.server.platformFromSessionKey(sessionKey)\n\tif platform == \"\" {\n\t\treturn nil, fmt.Errorf(\"bridge: cannot determine adapter from session key %q\", sessionKey)\n\t}\n\ta := bp.server.getAdapter(platform)\n\tif a == nil {\n\t\treturn nil, fmt.Errorf(\"bridge: adapter %q not connected\", platform)\n\t}\n\tif !a.capabilities[\"reconstruct_reply\"] {\n\t\treturn nil, fmt.Errorf(\"bridge: adapter %q does not support reconstruct_reply\", platform)\n\t}\n\treplyCtx, err := buildBridgeReconstructReplyCtx(bp.project, sessionKey)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn newBridgeReplyCtx(a, sessionKey, replyCtx), nil\n}\n\nfunc newBridgeReplyCtx(a *bridgeAdapter, sessionKey, replyCtx string) *bridgeReplyCtx {\n\trc := &bridgeReplyCtx{\n\t\tSessionKey: sessionKey,","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/bridge.go#L333-L369","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log the full session key and verify it contains the expected ':<adapter>:' segment; fix whatever truncated or mangled it.","Re-fetch the session key from the engine/session manager rather than reconstructing it manually.","Ensure the bridge adapter named in the key is registered/enabled in the current config (renames change the key's resolvable prefix)."],"exampleFix":"// before\nreplyCtx, err := bp.ReconstructReplyCtx(row.ChatID) // ChatID is not a session key\n\n// after\nreplyCtx, err := bp.ReconstructReplyCtx(row.SessionKey) // full key like \"bridge:feishu:oc_xxx\"","handlingStrategy":"validation","validationCode":"func validBridgeSessionKey(key string) bool {\n    parts := strings.SplitN(key, \":\", 3)\n    return len(parts) >= 2 && parts[0] != \"\" && parts[1] != \"\"\n}\n// call before ReconstructReplyCtx","typeGuard":null,"tryCatchPattern":"rc, err := bp.ReconstructReplyCtx(key)\nif err != nil && strings.Contains(err.Error(), \"cannot determine adapter\") {\n    slog.Error(\"unroutable session key\", \"key\", key)\n    return err\n}","preventionTips":["Store the full session key exactly as the engine emits it; never truncate DB columns.","Never synthesize session keys by hand.","Re-validate stored keys after config/adapter renames."],"tags":["go","session-key","routing"],"backgroundTag":"invalid-identifier-format","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}