fix(gateway): restore Telegram DM topic thread_id after session split (closes #27166)#28524
Merged
Conversation
…#27166) When context compression triggers a mid-turn session split, source.thread_id can be None on synthetic/recovered events. _thread_metadata_for_source then returns None, causing the Telegram adapter to send with no message_thread_id and the response lands in the General thread instead of the active DM topic. Fix: - hermes_state.py: Add get_telegram_topic_binding_by_session() for reverse lookup by session_id (enabled by the existing UNIQUE INDEX on session_id). - gateway/run.py: After session-split detection, if source is a Telegram DM and source.thread_id is None, recover it from the binding via the new method so _thread_metadata_for_source produces the correct thread routing. - tests/: Coverage for the new lookup method and the recovery flow.
1 task
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-argument-type |
1 |
First entries
gateway/run.py:16562: [invalid-argument-type] invalid-argument-type: Argument to bound method `SessionDB.get_telegram_topic_binding_by_session` is incorrect: Expected `str`, found `object`
✅ Fixed issues: none
Unchanged: 4679 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
This was referenced May 19, 2026
Closed
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.
Salvage of #27239 (@jackjin1997). After mid-turn context compression splits a session, the final response was routing to the General thread instead of the original Telegram DM topic. Now
source.thread_idis recovered from the topic binding (reverse lookup by session_id, using the existing UNIQUE INDEX) so_thread_metadata_for_sourceproduces the rightmessage_thread_id.Conflict resolution: kept both
list_telegram_topic_bindings_for_chat(from #28488 salvage) AND newget_telegram_topic_binding_by_session— they serve different purposes.Authorship preserved via cherry-pick. 42/42 topic-mode tests passing.