{"record":{"id":"79ca35c075c06fbe","repo":"chenhg5/cc-connect","slug":"telegram-invalid-session-key-q","errorCode":null,"errorMessage":"telegram: invalid session key %q","messagePattern":"telegram: invalid session key %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/telegram/telegram.go","lineNumber":1379,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"download file %s: %w\", fileID, err)\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"download file %s: status %d\", fileID, resp.StatusCode)\n\t}\n\treturn io.ReadAll(resp.Body)\n}\n\nfunc (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {\n\t// Formats:\n\t//   telegram:{chatID}                      - shared session, no topic\n\t//   telegram:{chatID}:{threadID}           - shared session, with topic\n\t//   telegram:{chatID}:{userID}             - per-user session, no topic\n\t//   telegram:{chatID}:{threadID}:{userID}  - per-user session, with topic\n\tparts := strings.SplitN(sessionKey, \":\", 5)\n\tif len(parts) < 2 || parts[0] != \"telegram\" {\n\t\treturn nil, fmt.Errorf(\"telegram: invalid session key %q\", sessionKey)\n\t}\n\tchatID, err := strconv.ParseInt(parts[1], 10, 64)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"telegram: invalid chat ID in %q\", sessionKey)\n\t}\n\n\tthreadID := 0\n\tswitch len(parts) {\n\tcase 2:\n\t\t// telegram:{chatID}\n\tcase 3:\n\t\tif p.shareSessionInChannel {\n\t\t\t// telegram:{chatID}:{threadID}\n\t\t\tthreadID, err = strconv.Atoi(parts[2])\n\t\t\tif err != nil {\n\t\t\t\tslog.Warn(\"telegram: invalid thread ID\", \"raw\", parts[2], \"error\", err)\n\t\t\t}\n\t\t}","sourceCodeStart":1361,"sourceCodeEnd":1397,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L1361-L1397","documentation":"This error comes from the Telegram platform's session-key parser (platform/telegram/telegram.go:1379). Session keys encode chat/topic/user routing as colon-separated segments like 'telegram:{chatID}' or 'telegram:{chatID}:{threadID}:{userID}'. The parser rejects any key that has fewer than 2 segments or whose first segment is not the literal 'telegram', because such a key cannot be routed to a Telegram chat.","triggerScenarios":"Calling the session-restore/parse function with a session key that was produced by a different platform (e.g. 'feishu:123'), a key missing the 'telegram:' prefix (e.g. '12345:-100'), or an empty/empty-segment key stored by an older version of the app.","commonSituations":"Mixing persisted sessions across platform adapters after switching messaging backends; hand-editing session keys in a database or config file; loading sessions serialized by a version that used a different key format; passing a raw chat ID instead of a full key.","solutions":["Verify the session key starts with the literal prefix 'telegram:' followed by a base-10 integer chat ID","Regenerate the session through the normal telegram platform flow instead of restoring a stored key","If migrating from another platform, discard keys from other adapters and create a fresh Telegram session","Check for stale/legacy session records and delete or migrate them to the current format"],"exampleFix":"// before\nsess, err := p.parseSessionKey(\"12345:67890\")\n// after\nsess, err := p.parseSessionKey(\"telegram:12345:67890\")","handlingStrategy":"validation","validationCode":"func validTelegramSessionKey(key string) bool {\n    parts := strings.SplitN(key, \":\", 5)\n    return len(parts) >= 2 && parts[0] == \"telegram\"\n}\nif !validTelegramSessionKey(key) {\n    return fmt.Errorf(\"skipping malformed session key %q\", key)\n}","typeGuard":"func isTelegramSessionKey(v any) (*telegramSession, bool) {\n    s, ok := v.(string)\n    if !ok || !strings.HasPrefix(s, \"telegram:\") {\n        return nil, false\n    }\n    return parseTelegramSessionKey(s)\n}","tryCatchPattern":"sess, err := parseSessionKey(key)\nif err != nil {\n    slog.Warn(\"unparseable session key, creating new session\", \"key\", key, \"err\", err)\n    sess, err = newSession(chatID)\n}","preventionTips":["Only create session keys via the platform's own formatter, never by string concatenation elsewhere","Never mix session keys between platform adapters","When loading persisted sessions, skip-and-log keys that fail validation instead of hard-failing","Add a version tag to stored session records so legacy formats can be migrated"],"tags":["telegram","session-key","parsing","golang"],"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"}