Skip to content

fix: report Telegram media request timeout details - #11043

Open
123XieC wants to merge 1 commit into
AstrBotDevs:masterfrom
123XieC:fix/telegram-media-timeout-11028
Open

123XieC wants to merge 1 commit into
AstrBotDevs:masterfrom
123XieC:fix/telegram-media-timeout-11028

Conversation

@123XieC

@123XieC 123XieC commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11028 by adding the error detail requested in the maintainer's comment. The SDK reports both a stalled upload and a response read timeout as TimedOut, which leaves the transport phase missing from AstrBot's media send logs.

Modifications / 改动点

  • Log the timeout cause type, for example WriteTimeout or ReadTimeout, for normal and streamed Telegram media sends.
  • Log the exception type alone so the Bot API URL and token stay out of the new log entry. Re-raise the original SDK exception for the existing caller.
  • Compatible with existing callers.

Screenshots or Test Results / 运行截图或测试结果

The regression tests use a real ExtBot and HTTPXRequest with a local mock transport and a temporary video. All four cases reached a multipart sendVideo request and failed on the missing log on master. After the fix they verify the phase, the preserved exception cause and the absence of the dummy token from the AstrBot error log.

python -m pytest -q tests/test_telegram_adapter.py
63 passed

ruff check .
All checks passed!

ruff format --check .
546 files already formatted

Validation used Python 3.12.16 and python-telegram-bot 22.8 on macOS. The transport was simulated locally.

Checklist / 检查清单

  • Regression tests and verification steps are provided above.
  • This logging change needs no WebUI navigation or documentation update.
  • No dependency changes.
  • Reviewed the patch for safe error logging.

AI disclosure: Codex generated the patch and ran the checks.

Summary by Sourcery

Improve Telegram media timeout diagnostics by logging the transport phase without exposing sensitive request details.

Bug Fixes:

  • Report whether Telegram media request timeouts occur during writing or response reading for both regular and streaming sends.
  • Preserve the original timeout exception while preventing sensitive Bot API credentials from appearing in timeout logs.

Tests:

  • Add regression coverage for read and write timeouts across regular and streaming Telegram video sends, including exception preservation and credential-safe logging.

Log the transport exception type for outgoing media timeouts and keep the original SDK error for callers.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Linked issues

#11028 [Feature] Telegram 适配器未暴露媒体上传超时(media_write_timeout),大视频在弱上行网络下固定 20 秒写入超时 · 1 of 3 met

# Requirement Status Notes
1 Allow users to adjust the media upload write timeout through configuration. ❌ Not addressed The change adds timeout logging but does not add a timeout setting or pass a configured request to the Telegram application.
2 Keep the default media write timeout at 20.0 seconds. ✅ Met The application still uses the SDK's default request configuration, so the existing 20-second media write timeout is unchanged.
3 Explain in the dashboard hint that increasing the timeout may keep sending tasks occupied longer and queue later messages. ❌ Not addressed No dashboard configuration entry or hint is added.

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

[Feature] Telegram 适配器未暴露媒体上传超时(media_write_timeout),大视频在弱上行网络下固定 20 秒写入超时

1 participant