Skip to content

fix(telegram): apply _effective_update_message to _handle_media_message - #28813

Open
EloquentBrush0x wants to merge 1 commit into
NousResearch:mainfrom
EloquentBrush0x:fix/telegram-media-channel-post
Open

fix(telegram): apply _effective_update_message to _handle_media_message#28813
EloquentBrush0x wants to merge 1 commit into
NousResearch:mainfrom
EloquentBrush0x:fix/telegram-media-channel-post

Conversation

@EloquentBrush0x

Copy link
Copy Markdown
Contributor

Summary

PR #28531 introduced _effective_update_message and applied it to
_handle_text_message, _handle_command, and _handle_location_message
so that Telegram channel posts (update.channel_post; update.message == None)
are routed correctly. _handle_media_message was missed.

Bug: the if not update.message: return guard at the top of
_handle_media_message exits immediately for every channel post, silently
dropping all channel media (photos, videos, audio, documents, stickers).

Fix: resolve msg via _effective_update_message at the top of the
handler and remove the now-redundant msg = update.message assignment.
Identical to the pattern already applied to the three sibling handlers.

Changes

  • gateway/platforms/telegram.py: apply _effective_update_message to
    _handle_media_message (mirrors _handle_location_message)
  • tests/gateway/test_telegram_channel_posts.py: add
    test_media_handler_uses_effective_message_for_channel_post; extend
    _make_channel_message with media attribute stubs

Test plan

  • scripts/run_tests.sh tests/gateway/test_telegram_channel_posts.py -q → 4/4
  • scripts/run_tests.sh tests/gateway/test_telegram_group_gating.py tests/gateway/test_telegram_channel_posts.py -q → 30/30

PR NousResearch#28531 fixed _handle_text_message, _handle_command, and
_handle_location_message to use _effective_update_message so channel
posts (update.channel_post; update.message == None) are routed correctly.
_handle_media_message was missed: the `if not update.message: return`
guard silently dropped all media channel posts (photos, videos, audio,
documents, stickers).

Apply the same pattern: resolve msg via _effective_update_message at the
top of the handler and remove the now-redundant `msg = update.message`
assignment. Add a regression test to test_telegram_channel_posts.py.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter labels May 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #28614 — same fix applying _effective_update_message() to _handle_media_message() for channel_post media routing. Both extend merged #28531 which fixed text/commands but missed media.

@teknium1

teknium1 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Thanks for the focused fix. I verified the premise against current remote main (733472952a0fb): gateway/platforms/telegram.py:5995 still returns early on not update.message, while the sibling text/command/location handlers already use _effective_update_message(update) at gateway/platforms/telegram.py:5780, 5797, and 5812.

Problems

  • Current main has moved since this PR. _handle_media_message now also has an observe-unmentioned branch that still reads update.message at gateway/platforms/telegram.py:5997-6010. A salvage should normalize that branch to the same msg object too, not just the original early guard.

Suggested changes

  • Apply the PR’s pattern on current main: compute msg = self._effective_update_message(update) once, then use msg throughout _handle_media_message.
  • Keep the channel-post media regression test; the PR’s test targets the right behavior.

This is an automated hermes-sweeper review.

@teknium1 teknium1 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.

Thanks for the focused regression fix. The premise remains valid on current main.

Problems

  • The active adapter moved from gateway/platforms/telegram.py to plugins/platforms/telegram/adapter.py in 560010547, so this branch cannot be applied unchanged.
  • Current _handle_media_message still rejects a channel post at plugins/platforms/telegram/adapter.py:7764, and its auth/observe paths continue to read update.message at :7766-7786. Resolving only the original guard would leave those branches inconsistent with the effective message.

Suggested changes

  • Salvage the fix in plugins/platforms/telegram/adapter.py: bind msg = self._effective_update_message(update) once and use it throughout _handle_media_message.
  • Port the media channel-post regression test into tests/gateway/test_telegram_channel_posts.py; current coverage there stops at text and command handlers (:150-181).

This is an automated hermes-sweeper review.

async def _handle_media_message(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Handle incoming media messages, downloading images to local cache."""
if not update.message:
msg = self._effective_update_message(update)

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.

The active adapter has since moved to plugins/platforms/telegram/adapter.py (5600105). When salvaging this line, use the resolved msg for the current handler's authorization and unmentioned-group observation branches too; they still read update.message directly at current main :7766-7786.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 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 P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants