fix(telegram): pass source.thread_id explicitly on auto-reset notice (carve-out of #7404)#23440
Merged
Conversation
…(carve-out of #7404) The auto-reset notice ("◐ Session automatically reset…") was being sent with metadata=getattr(event, 'metadata', None), which can drop or mis-route in Telegram forum topics: the event's metadata isn't guaranteed to carry the originating thread_id, so the notice could leak into General or another topic. Use the existing self._thread_metadata_for_source(source) helper, which already handles thread_id construction plus the Telegram DM topic reply-fallback shape used everywhere else in the gateway. Carve-out of #7404. The PR's other hunk (line 7578, queued first response) is already redundant on main — gateway/run.py:15782 has used _status_thread_metadata since the _thread_metadata_for_source plumbing landed. Closes #7355 (path B; paths A and C closed via prior salvage merges).
Contributor
🔎 Lint report:
|
3 tasks
This was referenced May 11, 2026
1 task
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
Telegram auto-reset notices ("◐ Session automatically reset…") could land in the wrong forum topic — General or a sibling topic — instead of the topic the user was last active in. Now the notice carries
source.thread_idexplicitly via the existing_thread_metadata_for_sourcehelper.What was wrong
gateway/run.py:7026-7028sent the notice withmetadata=getattr(event, 'metadata', None). Theevent.metadataisn't guaranteed to carry the originatingthread_id(varies by adapter and by which code path constructed the event), so the notice could route to a different topic.Fix
The helper builds
{thread_id, ...}and also handles Telegram DM topic reply-fallback metadata (telegram_dm_topic_reply_fallback,telegram_reply_to_message_id) — used everywhere else in the gateway for thread-aware sends.Carve-out from PR #7404
PR #7404 by @keyuyuan had two hunks:
_thread_metadata_for_sourceinstead of inlining the{"thread_id": ...}dict (matches the existing pattern at_status_thread_metadata).gateway/run.py:15782has used_status_thread_metadatasince the_thread_metadata_for_sourceplumbing landed.Validation
tests/gateway/test_telegram_thread_fallback.py,test_session_reset_notify.py,test_fresh_reset_skill_injection.py: 56/56 pass.The existing helper is covered by
test_base_gateway_metadata_marks_telegram_dm_topics_as_reply_fallbackand adjacent fallback tests; this one-line change opts the auto-reset path into that contract.Note on issue #7355
This is path B (auto-reset notice). Path A (final response chunk) was already on main via
_status_thread_metadata. Path C (stream consumer first message) was closed in PR #23437 (salvage of #13077). With this carve-out, all three paths in #7355 are addressed.Closes #7355 (final).
Carve-out of #7404; @keyuyuan's authorship preserved.