fix(telegram): preserve DM topic routing via reply fallback (salvage #22053)#22410
Merged
kshitijk4poor merged 2 commits intoMay 9, 2026
Merged
Conversation
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.
This was referenced May 9, 2026
This was referenced May 9, 2026
1 task
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
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 withBad 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:
message_thread_id(unchanged).direct_messages_topic_idmetadata opt-in.message_thread_idtogether with areply_to_message_idpointing 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 ingateway/platforms/base.py, then wired into ~15 outgoing send sites ingateway/run.pyand all media/keyboard sends ingateway/platforms/telegram.py.Follow-up fix (added during salvage review)
send_typingwas the one outgoing site #22053 didn't update because Telegram'ssend_chat_actiononly acceptsmessage_thread_id(nodirect_messages_topic_idequivalent). 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
Lint diff (
scripts/lint_diff.py): 🆕 New issues: none for both ruff and ty.Closes / supersedes
send_model_pickerbypasses_message_thread_id_for_send(incidentally fixed; model picker now goes through the new_thread_kwargs_for_sendhelper)direct_messages_topic_id, which works for true Bot API DM topics but does NOT work for Hermes-created topic lanes (those aren't classified as Direct Messages topics in incoming updates). fix(telegram): preserve DM topic routing via reply fallback #22053's three-case framing handles both. Credit to @max_chad for first identifying the post-Bot-API-10.0 regression and prototyping the routing change.Attribution
2065cd583142013a54@leehack's email (
jhin.lee@unity3d.com) is added toAUTHOR_MAPin #22409 (prerequisite, must merge first).Test plan for review