fix(telegram): preserve private topic session keys#804
fix(telegram): preserve private topic session keys#804pjpjq wants to merge 1 commit intochenhg5:mainfrom
Conversation
22b5bf4 to
cbffb6d
Compare
cbffb6d to
b01e195
Compare
chenhg5
left a comment
There was a problem hiding this comment.
Review Summary
Clean fix for private chat topic session isolation. Previously message_thread_id was only used when chat.is_forum was true, ignoring private chat topics.
✅ Good:
-
Minimal change: Removes the
if msg.Chat.IsForumcondition, directly usingmsg.MessageThreadID(defaults to 0 when not present). -
Applied to both paths:
handleMessageandhandleCallbackQueryboth updated consistently. -
Test updated:
TestHandleMessageNonForumIgnoresThreadIDrenamed toTestHandleMessagePrivateTopicUsesThreadID, now expectstelegram:100:55:7session key with thread ID preserved. -
Docs updated: New section 6.3 explains topic session behavior for forum and private chat topics.
-
Zero default is safe: When
MessageThreadIDis 0 (no topic), session key remains unchanged (telegram:100:7).
LGTM. CI green.
Summary
message_thread_idwhenever Telegram provides it, instead of only whenchat.is_forumis true.Related discussion
Telegram topic message_thread_id session; I did not find an open duplicate for private chat topics.Reproduction
Environment tested locally:
cc-connect v1.3.2Steps:
Before this change, private chat topic messages were handled with the same session key because the code only used
MessageThreadIDwhenChat.IsForumwas true.Expected behavior
Messages from different Telegram topics should use different session keys when Telegram includes
message_thread_id, so each topic has an independent conversation context.Actual behavior before this PR
Private chat topics could be collapsed into the base private chat session key, for example:
After applying this change locally, a private topic message used a topic-aware session key, for example:
Breaking changes
None expected. Messages without
message_thread_idstill use the existing non-topic session key formats.Validation
Passed:
Also verified against a real local Telegram bot: a private chat topic message created/used
telegram:680002712:34923instead of the basetelegram:680002712session.Attempted full validation as requested by CONTRIBUTING:
go test ./...On my local macOS machine this still fails in packages unrelated to this patch:
agent/codex:TestGetModelAndReasoningEffort_FromRuntimeConfigWhenUnsetfailed once in the full suite, but passes when run directly.core: existing macOS path expectation failures involving/var/...vs/private/var/..., plus reply footer path truncation expectations.The Telegram package touched by this PR passes.