Skip to content

feat(telegram): fall back to send_document on Photo_invalid_dimensions#18444

Closed
leon7609 wants to merge 1 commit into
NousResearch:mainfrom
leon7609:feat/telegram-photo-fallback-document
Closed

feat(telegram): fall back to send_document on Photo_invalid_dimensions#18444
leon7609 wants to merge 1 commit into
NousResearch:mainfrom
leon7609:feat/telegram-photo-fallback-document

Conversation

@leon7609

@leon7609 leon7609 commented May 1, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds a send_document fallback to the Telegram adapter's send_image_file when Telegram rejects the photo.

Telegram rejects photos with extreme aspect ratios (most commonly very tall full-page screenshots) with Photo_invalid_dimensions. Previously the adapter logged the error and called super().send_image_file(...), which on the Telegram path silently dropped the file — the user got nothing.

This PR retries the same bytes via send_document when send_photo raises, so the original image still reaches the user (just as a file rather than an inline preview). Only fall through to the base adapter if both attempts fail.

This complements #17833 (which added a similar send_voicesend_document fallback for unplayable audio formats), but for the image path.

Related Issue

No existing issue — observed in the wild while sending agent-rendered web-page screenshots over Telegram.

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)

Changes Made

  • gateway/platforms/telegram.pysend_image_file():
    • On send_photo exception: log a warning (was error) noting we're retrying as a document.
    • Retry via self.send_document(...) with the same bytes / caption / metadata.
    • If send_document also raises, log a final error and fall through to the base adapter (existing behaviour).
  • tests/gateway/test_send_image_file.py — add a case asserting the document fallback is invoked when send_photo raises BadRequest.

How to Test

  1. Generate an extremely tall PNG (e.g. a full-page web screenshot via the browser skill).
  2. Tell the agent to send it via Telegram with a chat session that produces an image attachment.
  3. Before this fix: Telegram fails with Photo_invalid_dimensions; nothing arrives in the chat.
  4. After this fix: the image arrives as a Telegram document, with the same caption preserved.

Or run the unit tests:

pytest tests/gateway/test_send_image_file.py -v

Checklist

Code

Documentation & Housekeeping

  • No public API surface changed
  • No config schema changed

Telegram rejects photos with extreme aspect ratios (most commonly
very tall full-page screenshots) with `Photo_invalid_dimensions`.
Previously the adapter logged the error and called the base
adapter's send_image_file, which on the Telegram path silently
dropped the file — the user got nothing.

When send_photo raises, retry the same bytes via send_document so
the original image still reaches the user (just as a file rather
than an inline preview).  Only fall through to the base adapter if
both the photo and document attempts fail.

Tested with full-page web screenshots that previously vanished;
they now arrive as documents.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists labels May 1, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #15728 / #15837 — same root cause: send_photo rejects extreme aspect ratios, needs send_document fallback.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #15728 / #15837.

@leon7609

leon7609 commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #19714 (which broadens the same idea to any send_photo failure with smarter logging — INFO for the expected dimension case, WARNING otherwise). Thanks @ee-blog and @QifengKuang for the earlier work on #15728 / #15837 that landed via #19630 / #19714.

Already running the upstream behaviour locally — it works well.

@leon7609 leon7609 closed this May 8, 2026
@leon7609 leon7609 deleted the feat/telegram-photo-fallback-document branch May 8, 2026 06:24
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