fix(gateway): don't hijack brand-new Telegram DM topics into previous session#29287
Closed
fabiosiqueira wants to merge 1 commit into
Closed
fix(gateway): don't hijack brand-new Telegram DM topics into previous session#29287fabiosiqueira wants to merge 1 commit into
fabiosiqueira wants to merge 1 commit into
Conversation
Collaborator
Contributor
Author
|
The 2
Neither test touches |
… session _recover_telegram_topic_thread_id treated any unknown thread_id as a stale cross-topic reply and rewrote it to the user's most-recent binding. That also matches a freshly-created topic, whose binding is only recorded after recovery decides not to rewrite — so every message in the new topic was silently merged into the previously-active topic's session, and the new topic was never bound. Limit recovery to the lobby/General case (the original PR NousResearch#3206 strip bug). Replies to deleted-topic messages become a rare orphan case, matching what Telegram itself shows the user. Updates the existing unknown-thread_id test to assert the new no-hijack behavior; adds a brand-new-topic regression test.
9bdb72d to
bff401b
Compare
This was referenced May 22, 2026
Contributor
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.
Regression introduced by #26609
Commit
ede47a54badded_recover_telegram_topic_thread_idto pin inbound DM topic routing to the user's most-recent binding when the inboundthread_idis either lobby/General or unknown to existing bindings.The "unknown → recover" branch is wrong: when a user creates a new Telegram DM topic, the inbound
thread_idis real and non-lobby, but it has no binding yet because_record_telegram_topic_bindingruns at line ~7876 — after recovery has already decided to redirect. The result: every message in the new topic is silently routed into the previously-active topic's session, and the new topic is never bound.Live evidence from gateway logs:
27453is the freshly-created topic id;27374is the previous session's topic. Every message keeps being hijacked because the binding for27453is never written.The fix
The two cases that warrant recovery are:
thread_idisNone/ empty —_build_message_eventstripped it ([Bug]: Telegram DM sends fail with 'Message thread not found' — spurious thread_id from reply chains #3206).thread_idis a Telegram General/lobby magic id.Both are lobby cases. A non-lobby
thread_idalways belongs to the topic the user intends — whether it is already bound or brand new. The fix collapses the recovery guard tois_lobbyonly and removes theknownset lookup entirely.Trade-off: a reply to a message in a deleted topic delivers a non-lobby but truly stale
thread_id. Previously that would have been recovered; now it becomes an orphan message with no binding — consistent with what Telegram itself shows the user when the topic is gone.Test changes
test_recover_rewrites_unknown_thread_id_to_most_recent→ renamed totest_recover_returns_none_for_unknown_thread_idand body updated to assertNone(no hijack).test_recover_returns_none_for_brand_new_topic: bindings exist for topic12345, inboundthread_id="99999"(non-lobby, unbound). AssertsNone.test_recover_returns_none_for_known_topic,test_recover_rewrites_lobby_thread_id_to_most_recent,test_recover_returns_none_when_topic_mode_disabled,test_recover_returns_none_when_no_bindings_yet) remain unchanged and pass.