fix(gateway): notify on media delivery failure in more silent-swallow spots - #91335
Open
moon2sun wants to merge 1 commit into
Open
fix(gateway): notify on media delivery failure in more silent-swallow spots#91335moon2sun wants to merge 1 commit into
moon2sun wants to merge 1 commit into
Conversation
… spots Several media-send exception handlers across the gateway only logged the error and otherwise dropped it silently - neither the user nor the model got any signal that a MEDIA: attachment never arrived, so a model that fabricated or mistyped a path would keep repeating the same broken tag indefinitely with no feedback loop to correct it. _notify_media_delivery_failure() already exists and is already called from several other spots in gateway/platforms/base.py - this extends the same pattern to the remaining silent handlers: - gateway/platforms/base.py: single image send (both the !success and exception branches), both image-batch fallback paths, non-image media send, and local-file send. - gateway/platforms/weixin.py: extracted-media delivery and bare local-file delivery. - gateway/run.py: post-stream image-batch delivery, post-stream media delivery, and both background-task delivery paths (image + media). Deliberately excludes gateway/run.py's `_send_voice_reply` (the `except Exception` after the TTS send) - NousResearch#65745 is already open against that exact block for a related but distinct case (`send_result.success is False` without an exception), and gateway/kanban_watchers.py - NousResearch#83952 is already open and replaces those two handlers entirely with a larger SendResult-based rework, so a small notify-only patch there would just add merge-conflict noise against an in-flight PR. ## Verification - python -m py_compile on all 3 changed files - No existing test coverage found for _notify_media_delivery_failure() itself (grepped tests/ - zero references), so there's no existing pattern to extend with new unit tests for these call sites; happy to add tests if a maintainer points at the preferred mocking setup for BasePlatformAdapter. - These exact code paths (same diff) have been running in a live, actively-used production Hermes gateway deployment for real-world verification, not just a local dry run.
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Several media-send exception handlers in the gateway only logged the error and otherwise dropped it silently — neither the user nor the model got any signal that a
MEDIA:attachment never arrived. In practice this means a model that fabricates or mistypes a path keeps repeating the same broken tag indefinitely, with no feedback loop to correct it._notify_media_delivery_failure()already exists and is already called from several other spots ingateway/platforms/base.py. This extends the same, already-established pattern to the remaining silent handlers, rather than inventing a new mechanism.Found through real, sustained production use of a Hermes gateway (heavy Telegram media traffic), not a code audit — happy to file a tracking issue first if that's preferred process here, just didn't want to hold up a small, self-contained fix on it.
Related Issue
No existing issue — small enough that I went straight to a PR per the "self-contained" guidance in CONTRIBUTING.md. Can open one if preferred.
Type of Change
Changes Made
gateway/platforms/base.py: notify on single-image send failure (both the!successand exception branches), both image-batch fallback paths, non-image media send, and local-file send.gateway/platforms/weixin.py: notify on extracted-media delivery failure and bare local-file delivery failure.gateway/run.py: notify on post-stream image-batch delivery failure, post-stream media delivery failure, and both background-task delivery paths (image + media).Deliberately excludes two adjacent spots that overlap with in-flight work, to avoid adding merge-conflict noise against open PRs:
gateway/run.py's_send_voice_reply— fix(gateway): handle silent audio and media producers #65745 is already open against that exactexcept Exceptionblock for a related but distinct case (send_result.success is Falsewithout a raised exception).gateway/kanban_watchers.py— fix(kanban): make notification delivery durable #83952 is already open and replaces both handlers I'd otherwise touch with a larger SendResult-based rework.How to Test
send_image/send_multiple_images/send_voice/send_documentat a path that will raise (e.g. a nonexistent file, or mock the adapter method to raise) in each of the newly-covered call sites._notify_media_delivery_failure(...)is called with the chat id / path / metadata for that failure, matching the behavior already present at the other call sites inbase.pythat weren't touched by this PR.Checklist
Code
fix(scope):)pytest tests/ -qand all tests pass — ranpython -m py_compileon all 3 changed files (clean); didn't run the full suite in this environment._notify_media_delivery_failure()itself has zero existing test coverage anywhere intests/(confirmed via grep), so there's no existing pattern to extend for these call sites. Happy to add tests if a maintainer can point at the preferred mocking setup forBasePlatformAdapterin this repo's test suite.Documentation & Housekeeping