Skip to content

fix(gateway): synthetic/queued messages routed to wrong Telegram DM topic#27114

Closed
Timur00Kh wants to merge 1 commit into
NousResearch:mainfrom
Timur00Kh:fix/telegram-dm-topic-goal-continuation
Closed

fix(gateway): synthetic/queued messages routed to wrong Telegram DM topic#27114
Timur00Kh wants to merge 1 commit into
NousResearch:mainfrom
Timur00Kh:fix/telegram-dm-topic-goal-continuation

Conversation

@Timur00Kh

@Timur00Kh Timur00Kh commented May 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #27139

Bug

When /goal is active in a Telegram DM thread and the judge decides to continue, the continuation message is generated as a synthetic MessageEvent (via _defer_goal_status_notice_after_delivery). These synthetic events have message_id=None and are queued via _enqueue_fifo for deferred delivery.

Because the reply anchor is missing, _thread_metadata_for_source only set telegram_dm_topic_reply_fallback=True but never included direct_messages_topic_id. The Telegram adapter then falls back to message_thread_id=None, causing the message to land in the root "All Messages" thread instead of the active topic lane.

Session context and transcripts were still correct (session key includes thread_id), but replies were visually lost to the user.

Fix

Include direct_messages_topic_id in thread metadata for all non-General Telegram DM topics. This ensures queued/synthetic messages (goal continuations, status notices) are routed to the correct thread even when no reply anchor exists.

Files changed

  • gateway/run.py: added direct_messages_topic_id assignment in _thread_metadata_for_source for Telegram DM topics.

Test

  • Tested with /goal continuation in a Telegram DM topic thread.
  • Confirmed messages now appear in the correct topic lane, not "All Messages".

…events

When /goal loop generates synthetic MessageEvents (goal continuations,
status notices), the reply anchor is unavailable (message_id=None). For
Telegram DM topic lanes, the Telegram adapter requires
direct_messages_topic_id to route messages correctly; without it, the
adapter falls back to message_thread_id=None, sending messages to the
root 'All Messages' thread instead of the active topic lane.

The fix includes direct_messages_topic_id in thread metadata for all
non-General Telegram DM topics, ensuring queued/synthetic messages are
delivered to the correct thread even when no reply anchor exists.
@cardtest15-coder

This comment was marked as spam.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter labels May 16, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competes with #26945 (preserving DM topic routing for synthetic background process events) and #24222 (different approach to same routing problem). All three fix synthetic events losing Telegram DM topic routing when no reply anchor exists.

@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #27302 — your commit was cherry-picked onto current main as part of a batch salvage of low-risk new-contributor PRs. Authorship preserved (fix(gateway): add direct_messages_topic_id for synthetic Telegram DM events). Thanks for the contribution.

@teknium1 teknium1 closed this May 17, 2026
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
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 P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram DM topic messages leak to All Messages on synthetic events

4 participants