Skip to content

fix(telegram): respect reply_to_mode for DM topic reply fallback#24004

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/telegram-dm-topic-reply-to-mode
Closed

fix(telegram): respect reply_to_mode for DM topic reply fallback#24004
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/telegram-dm-topic-reply-to-mode

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

Summary

reply_to_mode: 'off' is ignored when sending messages via Hermes-created DM topic lanes (Telegram private-chat topics). The bot continues to show quote bubbles pointing to the user's message despite the explicit config.

Root Cause

Commit b3239572f introduced a DM topic reply fallback path in send() that hardcodes should_thread = reply_to_source is not None, completely bypassing _should_thread_reply() — the single method that checks _reply_to_mode.

Additionally, _reply_to_message_id_for_send() and _thread_kwargs_for_send() unconditionally return the reply anchor for DM topic fallback sends, propagating the ignore through all ~29 call sites.

Fix

  1. Added reply_to_mode parameter to _reply_to_message_id_for_send() and _thread_kwargs_for_send() classmethods
  2. In send(), changed DM topic fallback to check self._reply_to_mode != "off" before setting should_thread
  3. When reply_to_mode == "off":
    • _reply_to_message_id_for_send() returns None (no quote bubble)
    • _thread_kwargs_for_send() returns only message_thread_id (preserves topic routing without reply anchor)
  4. Threaded reply_to_mode=self._reply_to_mode through all 29 call sites

Regression Coverage

10 new tests in test_telegram_reply_mode.py (TestDMTopicFallbackReplyToMode):

Test What it covers
test_reply_to_id_suppressed_when_off classmethod returns None for off mode
test_reply_to_id_returned_when_first/all classmethod still returns anchor for other modes
test_reply_to_id_returned_when_no_mode backward compat (no mode = old behavior)
test_explicit_reply_to_overrides_mode explicit reply_to always wins
test_thread_kwargs_suppressed_reply_anchor_when_off thread kwargs without reply anchor
test_thread_kwargs_returns_full_when_first thread kwargs with reply anchor
test_thread_kwargs_no_mode_backward_compat backward compat
test_send_dm_topic_off_no_quote send() integration: no quote for off
test_send_dm_topic_first_still_quotes send() integration: quote for first

All 40 tests in test_telegram_reply_mode.py pass (30 existing + 10 new).
All 107 tests across test_telegram_reply_mode.py, test_telegram_reply_quote.py, test_telegram_thread_fallback.py, and test_telegram_topic_mode.py pass.

Testing

python -m pytest tests/gateway/test_telegram_reply_mode.py -v

Fixes reply_to_mode: 'off'ignored by Telegram DM topic reply fallback code #23994

The DM topic reply fallback code in send() hardcoded should_thread=True
when telegram_dm_topic_reply_fallback metadata was present, bypassing
_should_thread_reply() and ignoring reply_to_mode config. This caused
quote bubbles on every response even with reply_to_mode: 'off'.

Fix:
- Add reply_to_mode param to _reply_to_message_id_for_send() and
  _thread_kwargs_for_send() classmethods
- In send(), check self._reply_to_mode != 'off' for DM topic fallback
- Suppress reply anchor and reply_to_message_id when mode is 'off'
  while preserving message_thread_id for correct topic routing
- Thread reply_to_mode through all 29 call sites

Regression coverage: 10 new tests in test_telegram_reply_mode.py
covering classmethod behavior, send() integration, and backward
compatibility.

Fixes reply_to_mode: 'off' ignored by Telegram DM topic reply fallback code NousResearch#23994
@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 11, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #28477 — cherry-picked your commit onto current main with authorship preserved (rebase-merge). 40/40 reply-mode tests + 34/34 thread-fallback tests passing (no regression). Thanks. #28477

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.

3 participants