Skip to content

fix(cron): deliver MEDIA files as native platform attachments#5909

Closed
kshitijk4poor wants to merge 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/cron-media-delivery
Closed

fix(cron): deliver MEDIA files as native platform attachments#5909
kshitijk4poor wants to merge 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/cron-media-delivery

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Problem

Cron job delivery sends raw MEDIA:/path/to/file text 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 to adapter.send() — MEDIA tags are never extracted or handled.

Repro (from the issue report):

Create a cron that will use the tts tool to say "Hello world" in this channel, then run it immediately

Result: Discord shows literal text MEDIA:/opt/data/audio_cache/tts_20260407_182354.mp3 instead of playing the audio file.

Root cause

_deliver_result() in cron/scheduler.py has two delivery paths:

  1. Standalone path (via _send_to_platform) — already extracts MEDIA tags and passes them as media_files
  2. Live adapter path (via runtime_adapter.send()) — passes raw delivery_content with embedded MEDIA: 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():

  1. Send cleaned text — use cleaned_delivery_content (MEDIA tags already stripped by the existing extract_media() call) instead of raw delivery_content
  2. Send media files natively — new _send_media_via_adapter() helper routes each extracted file to the adapter's appropriate method: send_voice for audio, send_image_file for images, send_video for video, send_document as fallback. This mirrors the same file-type routing logic in BasePlatformAdapter._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 receives send_voice() for .mp3, text has MEDIA tag stripped
  • test_live_adapter_sends_cleaned_text_not_raw: Telegram adapter receives cleaned text without MEDIA tags

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

teknium1 commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #5921. Your commit was cherry-picked onto current main with your authorship preserved in git log. Thanks @kshitijk4poor!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants