Skip to content

fix(telegram): preserve voice notes and recover from missing thread/reply targets - #13662

Closed
tumbleweedlabs wants to merge 3 commits into
NousResearch:mainfrom
tumbleweedlabs:fix/telegram-voice-note-cleanup
Closed

fix(telegram): preserve voice notes and recover from missing thread/reply targets#13662
tumbleweedlabs wants to merge 3 commits into
NousResearch:mainfrom
tumbleweedlabs:fix/telegram-voice-note-cleanup

Conversation

@tumbleweedlabs

Copy link
Copy Markdown

Summary

This cleans up Telegram voice-note delivery so auto-TTS replies stay native voice notes and the send path degrades gracefully when Telegram rejects stale thread or reply targets.

What changed

  • preserve Telegram auto-TTS replies as .ogg / voice-note friendly output instead of defaulting everything through an .mp3 temp path
  • teach the Telegram adapter to:
    • send .ogg / .opus files via send_voice
    • retry without message_thread_id when Telegram returns Message thread not found
    • retry without reply_to_message_id when the replied-to message is gone
    • keep using send_audio for non-OGG files
  • prefer native .ogg temp output for Telegram auto voice replies when the active TTS provider can produce it directly
  • add regression coverage for:
    • Telegram auto-TTS output path selection
    • missing thread fallback
    • missing reply-target fallback
    • MP3-vs-voice send behavior
    • helper/config behavior touched by the TTS path

Why

We had two ugly failure modes in Telegram:

  1. voice replies could fall back to regular audio/file behavior because the auto-TTS path started from an .mp3 temp filename
  2. sends could fail outright when Telegram topics or replied-to messages disappeared between generation and delivery

This patch keeps the voice-note path native and makes delivery more tolerant of stale Telegram metadata.

Testing

pytest -q tests/gateway/test_telegram_auto_tts_path.py \
          tests/gateway/test_voice_command.py \
          tests/tools/test_tool_backend_helpers.py \
          tests/tools/test_tts_speed.py \
          tests/gateway/test_telegram_thread_fallback.py

Result: 251 passed

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter tool/tts Text-to-speech and transcription labels Apr 21, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the thorough PR! After reviewing current main, all three behaviors this patch introduces are already shipped:

  • Thread-not-found fallback — merged in PR fix(telegram): fall back to no thread_id on 'Message thread not found' #3390 (commit 41d9d0807). _is_thread_not_found_error() + retry-without-message_thread_id are live at gateway/platforms/telegram.py:1058, with full test coverage in tests/gateway/test_telegram_thread_fallback.py.
  • Reply-target-deleted fallback — merged in PR fix(telegram): gracefully handle deleted reply targets #3858 (commit b60cfd6ce, inspired by an earlier PR from @heathley). The "message to be replied not found" handler that clears reply_to_id and retries is at telegram.py:1069.
  • OGG → send_voice / MP3 → send_audio routing — already in send_voice() at telegram.py:1741–1758 (added with the /voice command feature, commit d80da5ddd). The auto-TTS path in gateway/run.py:_send_voice_reply already uses result.get("file_path", audio_path) to follow any OGG conversion.

The branch is also marked as having merge conflicts against main.

Closing as implemented. The underlying issues were real and well-diagnosed — they just got fixed on a parallel track before this PR landed. Appreciate the regression tests; if any specific coverage from test_telegram_auto_tts_path.py isn't captured on main yet, a small focused follow-up is welcome.

This is an automated hermes-sweeper review.

@teknium1 teknium1 closed this Apr 27, 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 platform/telegram Telegram bot adapter tool/tts Text-to-speech and transcription type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants