Skip to content

fix(telegram): stop dropping voice messages on getFile network errors (#16136) - #16154

Merged
obviyus merged 2 commits into
openclaw:mainfrom
yinghaosang:fix/telegram-voice-getfile-retry
Feb 15, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
yinghaosang:fix/telegram-voice-getfile-retry

Conversation

@yinghaosang

@yinghaosang yinghaosang commented Feb 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Voice messages (and all non-sticker media) get lost when the Telegram getFile API call hits a network error. The sticker path already has a try/catch that returns null gracefully, but the non-sticker media path in resolveMedia just lets the exception bubble up — it reaches the outer catch in bot-handlers.ts which logs and drops the message.

Closes #16136

lobster-biscuit

Root Cause

resolveMedia() in delivery.ts calls ctx.getFile() with no retry and no error handling for non-sticker media (voice, photo, video, audio, document). On network failure, the error propagates to bot-handlers.ts:884 where only the "exceeds MB limit" case is caught — everything else gets re-thrown and the outer catch at line 933 swallows it. Message gone, no feedback.

Changes

  • Before: single getFile() call, network error → message dropped
  • After: 3 retries with exponential backoff (1s/2s/4s) using the existing retryAsync from src/infra/retry.ts. If all retries fail, returns null instead of throwing — the message still reaches the agent with a type-based placeholder (e.g. <media:audio>) from bot-message-context.ts

Only delivery.ts is changed. The retry catch is scoped to getFile only — downstream errors from fetchRemoteMedia/saveMediaBuffer still throw normally.

Tests

New file: delivery.resolve-media-retry.test.ts (5 tests, fake timers):

  • getFile fails once then succeeds → media resolved normally (retry works)
  • getFile fails all 3 attempts → returns null, message isn't dropped
  • getFile succeeds but fetchRemoteMedia throws → error propagates (not swallowed by retry catch)
  • photo getFile exhausts retries → returns null
  • video getFile exhausts retries → returns null

All 50 telegram test files (419 tests) pass. pnpm build && pnpm check clean (pre-existing format issue in .agents/skills/find-issue/SKILL.md only).

Greptile Overview

Greptile Summary

This PR contains two separate fixes that improve reliability in different parts of the system. The telegram fix adds retry logic with exponential backoff (3 attempts, 1s/2s/4s delays) for the getFile API call when processing non-sticker media (voice, photo, video, audio, document). Previously, network errors would cause messages to be dropped at the outer catch handler in bot-handlers.ts:933. Now, if all retries fail, resolveMedia returns null instead of throwing, allowing the message to reach the agent with a type-based placeholder (e.g., <media:audio>). The agents fix addresses a race condition where async onBlockReplyFlush callbacks were not awaited before subsequent events were processed, causing tool messages to potentially overtake narration delivery. The fix serializes events through a promise chain when a flush callback is present, ensuring delivery completes before tool execution proceeds.

  • Added retryAsync wrapper around ctx.getFile() in delivery.ts:406-414 with exponential backoff for non-sticker media
  • Returns null on retry exhaustion instead of throwing, preventing message loss
  • Comprehensive test coverage in delivery.resolve-media-retry.test.ts (5 tests with fake timers)
  • Modified pi-embedded-subscribe.handlers.ts to serialize events through a promise chain when flush is in-flight
  • Changed handleToolExecutionStart to await onBlockReplyFlush() with try-catch for best-effort delivery

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Both fixes are well-implemented with comprehensive test coverage and follow existing patterns in the codebase. The telegram retry logic uses the existing retryAsync utility correctly and degrades gracefully on failure. The agents fix properly serializes async operations without breaking the event handler chain. No logic errors, security issues, or breaking changes detected.
  • No files require special attention

Last reviewed commit: 9956dad

@openclaw-barnacle openclaw-barnacle Bot added channel: telegram Channel integration: telegram agents Agent runtime and tooling size: L labels Feb 14, 2026
@yinghaosang
yinghaosang force-pushed the fix/telegram-voice-getfile-retry branch from 9956dad to f2f0879 Compare February 14, 2026 10:45
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed agents Agent runtime and tooling size: L labels Feb 14, 2026
@yinghaosang yinghaosang changed the title fix(telegram): retry getFile for non-sticker media and gracefully degrade on failure (#16136) fix(telegram): retry getFile to prevent voice message drops (#16136) Feb 14, 2026
@yinghaosang yinghaosang changed the title fix(telegram): retry getFile to prevent voice message drops (#16136) fix(telegram): stop dropping voice messages on getFile network errors (#16136) Feb 14, 2026
@obviyus obviyus self-assigned this Feb 15, 2026
@obviyus
obviyus force-pushed the fix/telegram-voice-getfile-retry branch from f2f0879 to fbcd784 Compare February 15, 2026 09:19
@obviyus
obviyus merged commit 80abb5a into openclaw:main Feb 15, 2026
11 of 12 checks passed
@obviyus

obviyus commented Feb 15, 2026

Copy link
Copy Markdown
Collaborator

Merged via squash.

Thanks @yinghaosang!

GwonHyeok pushed a commit to learners-superpumped/openclaw that referenced this pull request Feb 15, 2026
…openclaw#16136) (openclaw#16154)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: fbcd784
Co-authored-by: yinghaosang <[email protected]>
Co-authored-by: obviyus <[email protected]>
Reviewed-by: @obviyus
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…openclaw#16136) (openclaw#16154)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: fbcd784
Co-authored-by: yinghaosang <[email protected]>
Co-authored-by: obviyus <[email protected]>
Reviewed-by: @obviyus
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…openclaw#16136) (openclaw#16154)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: fbcd784
Co-authored-by: yinghaosang <[email protected]>
Co-authored-by: obviyus <[email protected]>
Reviewed-by: @obviyus
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…openclaw#16136) (openclaw#16154)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: fbcd784
Co-authored-by: yinghaosang <[email protected]>
Co-authored-by: obviyus <[email protected]>
Reviewed-by: @obviyus
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…openclaw#16136) (openclaw#16154)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: fbcd784
Co-authored-by: yinghaosang <[email protected]>
Co-authored-by: obviyus <[email protected]>
Reviewed-by: @obviyus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: telegram Channel integration: telegram size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram: voice messages silently dropped when getFile API fails (no retry)

2 participants