Skip to content

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

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-822a0590
Apr 7, 2026
Merged

fix(cron): deliver MEDIA files as native platform attachments#5921
teknium1 merged 2 commits into
mainfrom
hermes/hermes-822a0590

Conversation

@teknium1

@teknium1 teknium1 commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the live adapter path in _deliver_result() so cron deliveries via a running gateway send cleaned text (MEDIA tags stripped) and route extracted media files to native platform methods (send_voice, send_image_file, send_video, send_document).

Before: Discord/Telegram users saw literal MEDIA:/path/to/file text instead of audio/image/video attachments.
After: Media files are delivered as native platform attachments, matching how the standalone delivery path and live chat already work.

Root cause

_deliver_result() line 250 sent raw delivery_content through runtime_adapter.send(). The extract_media() call at line 241 already extracts files, but its output (cleaned_delivery_content, media_files) was only consumed by the standalone fallback path — the live adapter path ignored both.

Changes

cron/scheduler.py:

  • New _send_media_via_adapter() helper routes each file by extension to the adapter's typed send method — mirrors BasePlatformAdapter._process_message_background routing
  • Live adapter path now sends cleaned_delivery_content (stripped) instead of raw delivery_content
  • Handles media-only content (no text) — skips adapter.send() entirely, still delivers media
  • Per-file run_coroutine_threadsafe isolation — one failure doesn't block remaining files
  • Uses frozenset for module-level extension constants

tests/cron/test_scheduler.py:

  • 8 new tests (52 total, all passing):
    • Integration: audio routing via Discord, image routing, media-only, text cleaning
    • Unit: video routing, document fallback, multi-file delivery, failure isolation

Attribution

Core fix cherry-picked from PR #5909 by @kshitijk4poor.
Additional unit tests adapted from PR #5679 by @0xbyt4.
PR #4517 by @boobutler addressed the standalone path (merged in #5598).

Test plan

python -m pytest tests/cron/test_scheduler.py -o 'addopts=' -q
# 52 passed

E2E verified: text+media, media-only, and plain-text delivery paths all correct.

Closes #5909, closes #5679, closes #4517.

kshitijk4poor and others added 2 commits April 7, 2026 12:31
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
…failure isolation

Adapted from PR #5679 (0xbyt4) to cover edge cases not in the integration tests:
video routing, unknown extension fallback to send_document, multi-file delivery,
and single-failure isolation.
@teknium1 teknium1 merged commit c040b0e into main Apr 7, 2026
3 of 4 checks passed
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