Skip to content

fix(telegram): preserve DM topic routing via reply fallback (salvage #22053)#22410

Merged
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/telegram-dm-topic-22053
May 9, 2026
Merged

fix(telegram): preserve DM topic routing via reply fallback (salvage #22053)#22410
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/telegram-dm-topic-22053

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Salvage of #22053 by @leehack onto current main, fixing #22022 (Telegram Bot API 10.0 broke private-chat topic replies — Hermes responses landed in "All Messages" instead of the active DM topic lane).

Root cause (from #22022)

Bot API 10.0 changed how Telegram routes outbound sends in private-chat topic lanes. Previously, sendMessage(message_thread_id=N) worked. After 10.0, the same call fails with Bad Request: message thread not found. Hermes' existing fallback retried without the thread id, dropping the response into the root chat.

Fix (from #22053, by @leehack)

Three distinct routing modes:

  1. Forum / supergroup topics — keep using message_thread_id (unchanged).
  2. True Bot API Direct Messages topics — explicit direct_messages_topic_id metadata opt-in.
  3. Hermes-created private DM topic lanes — reply-anchor fallback (send message_thread_id together with a reply_to_message_id pointing at the triggering user message; if either is missing, drop both rather than land in the wrong lane).

Threaded through new _thread_metadata_for_source(source, reply_to_message_id) and _reply_anchor_for_event(event) helpers in gateway/platforms/base.py, then wired into ~15 outgoing send sites in gateway/run.py and all media/keyboard sends in gateway/platforms/telegram.py.

Follow-up fix (added during salvage review)

send_typing was the one outgoing site #22053 didn't update because Telegram's send_chat_action only accepts message_thread_id (no direct_messages_topic_id equivalent). Without a fix, every typing tick (~every 2s during agent runs) makes a doomed API call that gets logged at debug level. This salvage adds a short-circuit: when metadata indicates a DM topic reply-fallback lane, skip the call entirely. User-visible behavior is unchanged (no typing indicator either way for these lanes), but logs stay clean.

Verification

bash scripts/run_tests.sh \
  tests/gateway/test_telegram_thread_fallback.py \
  tests/gateway/test_run_progress_topics.py \
  tests/gateway/test_background_command.py \
  tests/gateway/test_voice_command.py \
  tests/gateway/test_discord_free_response.py \
  tests/gateway/test_feishu.py
=> 480 passed

Lint diff (scripts/lint_diff.py): 🆕 New issues: none for both ruff and ty.

Closes / supersedes

Attribution

Commit Author Description
2065cd583 @leehack fix(telegram): preserve DM topic routing via reply fallback
142013a54 @kshitijk4poor fix(telegram): skip send_chat_action for DM topic reply-fallback lanes

@leehack's email (jhin.lee@unity3d.com) is added to AUTHOR_MAP in #22409 (prerequisite, must merge first).

Test plan for review

  1. Merge chore(release): add leehack to AUTHOR_MAP for PR #22053 salvage #22409 first (AUTHOR_MAP).
  2. Read the diff: 7 files changed, 1370 insertions, 153 deletions.
  3. Run focused tests as above.
  4. (Optional) Live-test on a real Telegram bot in a private DM topic lane — message the bot in a topic, verify the response stays in the topic lane instead of leaking to "All Messages."

leehack and others added 2 commits May 9, 2026 13:59
The send path uses Hermes' reply-anchor fallback for DM topic lanes
(message_thread_id + reply_to_message_id), but send_chat_action only
accepts message_thread_id — Telegram's Bot API 10.0 rejects it for
these lanes. Without this short-circuit, every typing tick (~every 2s
during agent runs) makes a doomed API call that gets logged as a
'thread not found' debug warning. Skip the call entirely when the
metadata indicates a DM topic reply-fallback lane; the user-visible
behavior is unchanged (no typing indicator either way for these
lanes), but the logs stay clean.

Identified during salvage review of NousResearch#22053.
@kshitijk4poor kshitijk4poor merged commit aef297a into NousResearch:main May 9, 2026
8 of 11 checks passed
@kshitijk4poor kshitijk4poor deleted the salvage/telegram-dm-topic-22053 branch May 9, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants