fix: new Telegram DM topics from All Messages reroute to previous session#29546
Closed
viraniaman94 wants to merge 1 commit into
Closed
fix: new Telegram DM topics from All Messages reroute to previous session#29546viraniaman94 wants to merge 1 commit into
viraniaman94 wants to merge 1 commit into
Conversation
…ession When topic mode is enabled and a user creates a new topic from Telegram's 'All Messages' view, the first message in that topic often arrives without is_topic_message=True. _build_message_event stripped the message_thread_id, and _recover_telegram_topic_thread_id redirected the resulting lobby thread_id (None) to the user's most recent binding — causing the brand-new topic to inherit the previous topic's session. Two-part fix: 1. gateway/telegram.py (_build_message_event): When is_topic_message is False for a DM with message_thread_id, check if topic mode is enabled and the thread_id is not yet bound to any session. If genuinely new, preserve the thread_id so the topic gets its own session lane. 2. gateway/run.py (_recover_telegram_topic_thread_id): Only recover from the lobby/General topic (thread_id=None/'') where routing intent is ambiguous. Non-lobby unknown thread_ids are treated as genuinely new lanes and left alone.
Collaborator
This was referenced May 22, 2026
Contributor
|
Superseded by #31444 (#31444), which fixes the same #31086 hijack with a smaller, single-site change in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When topic mode is enabled and a user creates a new topic from Telegram's "All Messages" view, the first message in that topic often arrives without
is_topic_message=True. This caused_build_message_eventto strip themessage_thread_id, and_recover_telegram_topic_thread_idredirected the resulting lobby thread_id to the user's most recent binding — making the brand-new topic inherit the previous topic's session.Changes
1.
gateway/platforms/telegram.py—_build_message_eventWhen
is_topic_messageisFalsefor a DM that has amessage_thread_id:2.
gateway/run.py—_recover_telegram_topic_thread_idOnly recover from the lobby/General topic (
thread_id=None/""/"1") where routing intent is truly ambiguous. Non-lobby unknown thread_ids are treated as genuinely new topic lanes and left alone.3.
tests/gateway/test_telegram_topic_mode.py— updated teststest_recover_rewrites_unknown_thread_id_to_most_recentwithtest_recover_leaves_unknown_topic_alone(the old test codified the buggy behavior)test_recover_redirects_cross_topic_reply_to_known_topic(known topic stays put)test_recover_rewrites_cross_topic_reply_to_unknown_topic(unknown non-lobby returns None)Testing
test_telegram_topic_mode.pypass