fix(telegram): preserve DM topic routing for synthetic background process events#26945
fix(telegram): preserve DM topic routing for synthetic background process events#26945Ardem2025 wants to merge 1 commit into
Conversation
…cess events
When a background process completes, the gateway injects a synthetic
MessageEvent without a message_id. For Telegram DM topics, the
_thread_kwargs_for_send() method previously returned {} when no reply
anchor was available, causing the response to be sent to the root chat
instead of the topic thread.
Now falls back to sending with message_thread_id even without a reply
anchor. This prevents cross-thread bleed for background process
completion notifications and watch pattern events in DM topics.
Fixes NousResearch#9532
This comment was marked as spam.
This comment was marked as spam.
|
Thanks for the pointer! I looked at #24222 — the two PRs are complementary rather than competing:
Both fixes are needed for the full path to work: #24222 ensures the source has the right thread_id, and this PR ensures that thread_id actually gets passed to the Telegram Bot API even without a reply anchor. |
|
I hit the same no-anchor symptom in the resumed final-response path and opened #27937 as a narrow alternative/follow-up. One important difference: #27937 does not fall back to |
|
Hey @Qwinty, thanks for chiming in and for #27937! Good point about the bare This PR was intentionally minimal: fix the immediate symptom (notifications going to the general stream instead of the topic at all) while #24222 and now #27937 address the deeper routing context. Happy to coordinate — if #27937 lands first, this fallback becomes redundant for that path and can be dropped or scoped down. Let me know if there's anything useful I can do on my end! |
|
Thanks! That makes sense — I’ll keep #27937 focused on the no-reply-anchor DM-topic path and mention that if it lands first, the bare |
|
Closing in favor of #27212 (same issue #9532, better approach). The
Your fix falls back to Also see #27937 (@Qwinty) which solves the resumed-send variant via Thanks for the diagnosis on #9532; #27212 takes it to a working fix. |
Summary
Fixes #9532 — background process completion notifications leak into the root DM chat instead of the correct DM topic thread.
Problem
When a background process completes (
notify_on_complete=true), the gateway injects a syntheticMessageEventwithout amessage_id. For Telegram DM topics,_thread_kwargs_for_send()requires a reply anchor (reply_to_message_id) to route messages into the correct topic lane. Without it, the method returned{}— dropping all thread routing and sending the response to the root chat.Fix
In
_thread_kwargs_for_send(): whentelegram_dm_topic_reply_fallbackis set but no reply anchor is available, fall back to sending withmessage_thread_idinstead of returning empty kwargs. This ensures the message is routed to the correct DM topic thread.Testing
test_send_dm_topic_fallback_without_anchor_uses_message_thread_idto verify the new behaviortest_telegram_thread_fallback.pypassReproduction
notify_on_complete=truein a Telegram DM topic session