Skip to content

fix: avoid empty turns when Telegram documents fail to download - #46680

Closed
BeliefanX wants to merge 1 commit into
NousResearch:mainfrom
BeliefanX:fix/telegram-document-download-failures
Closed

BeliefanX wants to merge 1 commit into
NousResearch:mainfrom
BeliefanX:fix/telegram-document-download-failures

Conversation

@BeliefanX

Copy link
Copy Markdown
Contributor

Summary

  • Fail closed when Telegram document/CSV downloads cannot be fetched or cached, instead of dispatching an empty agent turn.
  • Add bounded retry/backoff and explicit per-call timeout kwargs for Telegram document downloads.
  • Cover CSV/document timeout and retry behavior in tests/gateway/test_telegram_documents.py.

Implementation

Telegram/PTB or the network can legitimately time out while resolving get_file() or downloading file bytes. That timeout is the trigger, but the user-visible bug is in Hermes: after the document cache path raised, the adapter logged the failure and continued to handle_message(event) with no cached path or injected text. For CSV and other document-only inputs, that can produce an empty user turn.

This change centralizes Telegram media-byte download for document uploads, retries transient failures with bounded backoff, forwards explicit read/connect/pool timeout kwargs to PTB calls, and sends a direct Telegram failure notice when all attempts fail. The failed download is not routed through the agent because there is no file path/content for the agent to inspect.

Testing

/Users/fanxuxin/.hermes/hermes-agent/.venv/bin/python -m pytest -o addopts='' tests/gateway/test_telegram_documents.py -q
# 42 passed in 3.32s

/Users/fanxuxin/.hermes/hermes-agent/.venv/bin/python -m py_compile gateway/platforms/telegram.py tests/gateway/test_telegram_documents.py

git diff --check

Note: /usr/bin/python3 on this macOS host is Python 3.9 and cannot import current main because the repo uses Python 3.10+ type syntax; the project venv Python 3.11 was used for verification.

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 15, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

Duplicate of #23063 — both fix #23045 (Telegram document/CSV download failures dispatching an empty agent turn) with the same fail-closed approach: bounded retry/backoff on the media download plus a direct failure notice to the user instead of forwarding an empty turn. Both touch the same files (gateway/platforms/telegram.py, tests/gateway/test_telegram_documents.py); #23063 is the earlier still-open PR and is canonical. Related: #23061 (earlier closed attempt) and #41087 (sibling voice-variant fix).

@BeliefanX

Copy link
Copy Markdown
Contributor Author

Confirmed this duplicates #23063, which already covers the Telegram document/CSV download-failure empty-turn path and is the earlier canonical PR for #23045. Closing this duplicate to avoid reviewer noise. Apologies for missing the existing PR during triage.

@BeliefanX BeliefanX closed this Jun 15, 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 duplicate This issue or pull request already exists 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.

2 participants