fix(cron): deliver MEDIA files as native platform attachments#5909
Closed
kshitijk4poor wants to merge 1 commit into
Closed
fix(cron): deliver MEDIA files as native platform attachments#5909kshitijk4poor wants to merge 1 commit into
kshitijk4poor wants to merge 1 commit into
Conversation
The cron delivery path sent raw 'MEDIA:/path/to/file' text instead of uploading the file as a native attachment. The standalone path (via _send_to_platform) already extracted MEDIA tags and forwarded them as media_files, but the live adapter path passed the unprocessed delivery_content directly to adapter.send(). Two bugs fixed: 1. Live adapter path now sends cleaned text (MEDIA tags stripped) instead of raw content — prevents 'MEDIA:/path' from appearing as literal text in Discord/Telegram/etc. 2. Live adapter path now sends each extracted media file via the adapter's native method (send_voice for audio, send_image_file for images, send_video for video, send_document as fallback) — files are uploaded as proper platform attachments. The file-type routing mirrors BasePlatformAdapter._process_message_background to ensure consistent behavior between normal gateway responses and cron-delivered responses. Adds 2 tests: - test_live_adapter_sends_media_as_attachments: verifies Discord adapter receives send_voice call for .mp3 file - test_live_adapter_sends_cleaned_text_not_raw: verifies MEDIA tag stripped from text sent via live adapter
7e3fb89 to
69fdbf9
Compare
Contributor
|
Merged via PR #5921. Your commit was cherry-picked onto current main with your authorship preserved in git log. Thanks @kshitijk4poor! |
4 tasks
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.
Problem
Cron job delivery sends raw
MEDIA:/path/to/filetext to Discord/Telegram/etc instead of uploading the file as a native platform attachment. This happens because the live adapter path in_deliver_result()passes unprocessed content toadapter.send()— MEDIA tags are never extracted or handled.Repro (from the issue report):
Result: Discord shows literal text
MEDIA:/opt/data/audio_cache/tts_20260407_182354.mp3instead of playing the audio file.Root cause
_deliver_result()incron/scheduler.pyhas two delivery paths:_send_to_platform) — already extracts MEDIA tags and passes them asmedia_files✓runtime_adapter.send()) — passes rawdelivery_contentwith embeddedMEDIA:tags ✗The live adapter path is used when the gateway is running (which is the case for Discord cron delivery). The text goes through
adapter.send()which is a plain text sender — it doesn't parse MEDIA tags.Fix
Two changes to the live adapter path in
_deliver_result():cleaned_delivery_content(MEDIA tags already stripped by the existingextract_media()call) instead of rawdelivery_content_send_media_via_adapter()helper routes each extracted file to the adapter's appropriate method:send_voicefor audio,send_image_filefor images,send_videofor video,send_documentas fallback. This mirrors the same file-type routing logic inBasePlatformAdapter._process_message_background.Testing
python -m pytest tests/cron/test_scheduler.py -q # 46 passed (44 existing + 2 new)New tests:
test_live_adapter_sends_media_as_attachments: Discord adapter receivessend_voice()for .mp3, text has MEDIA tag strippedtest_live_adapter_sends_cleaned_text_not_raw: Telegram adapter receives cleaned text without MEDIA tags