fix(telegram): normalize thread id in group gating via shared helper - #56109
Merged
Merged
Conversation
Group gating (_should_process_message) read the raw message_thread_id, while event routing (_build_message_event) normalized it. A plain non-forum group reply's message_thread_id is a reply-UI anchor, not a topic, so an anchor id matching an ignored_threads entry wrongly dropped the message, and the anchor was treated as a routable topic under allowed_topics. Extract _effective_message_thread_id and route both gating and event-building through it, so gating and session routing agree on one normalized value: real topic/forum messages keep their thread id, reply anchors are dropped, and forum General-topic messages normalize to the General-topic id.
19 tasks
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 group gating and session routing now derive the message thread id from one shared normalizer, so they can no longer disagree.
Root cause:
_should_process_messageread the rawmessage_thread_id, while_build_message_eventnormalized it. A plain non-forum group reply'smessage_thread_idis a reply-UI anchor, not a topic — so an anchor id that matched anignored_threadsentry wrongly dropped the message, and the anchor id was treated as a routable topic underallowed_topics.Changes
plugins/platforms/telegram/adapter.py: add_effective_message_thread_id()and route both_should_process_message(gating) and_build_message_event(routing/skill-binding) through it. Real topic/forum messages keep their thread id; reply anchors are dropped; forum General-topic messages (thread_id=None) normalize to the General-topic id.tests/gateway/test_telegram_group_gating.py: regression tests for the non-forum reply-anchor gating and forum General-topic normalization.Salvaged from #18913 by @nocturnum91 — that branch predated the Telegram move to
plugins/platforms/telegram/, and its bot-command mention half (#15415) and forum-topic normalization (#3206/#22423 in_build_message_event) already landed onmainindependently. This carries the one remaining un-merged delta: unifying the gate on the same normalized thread id, plus folding_build_message_event's inline block into the shared helper so the two paths cannot drift again.Validation
ignored_threads=[55]allowed_topics=["1"]thread_id=None),allowed_topics=["1"]112 Telegram gateway tests pass (
group_gating,dm_topics,forum_commands,thread_fallback,topic_mode,prune_stale_topic_binding). New gating tests fail against the old raw-thread_id code and pass on the fix.Infographic