Skip to content

fix(telegram): normalize thread id in group gating via shared helper - #56109

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-d3507100
Jul 1, 2026
Merged

teknium1 merged 1 commit into
mainfrom
hermes/hermes-d3507100

Conversation

@teknium1

@teknium1 teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

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_message read the raw message_thread_id, while _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 that matched an ignored_threads entry wrongly dropped the message, and the anchor id was treated as a routable topic under allowed_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 on main independently. 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

Case Before After
Non-forum group reply, anchor 55, ignored_threads=[55] dropped processed
Non-forum group reply, anchor 55, allowed_topics=["1"] dropped (anchor read as topic 55) processed
Forum General topic (thread_id=None), allowed_topics=["1"] processed processed

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

Telegram thread-id normalization

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.
@alt-glitch alt-glitch added type/bug Something isn't working platform/telegram Telegram bot adapter comp/gateway Gateway runner, session dispatch, delivery sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages P3 Low — cosmetic, nice to have labels Jul 1, 2026
@teknium1
teknium1 merged commit cc1e4c3 into main Jul 1, 2026
31 checks passed
@teknium1
teknium1 deleted the hermes/hermes-d3507100 branch July 1, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants