fix(gateway): deliver MEDIA files for queued follow-up responses#18546
fix(gateway): deliver MEDIA files for queued follow-up responses#18546vnhwd wants to merge 4 commits into
Conversation
When multiple /queue items are chained, only the last item's MEDIA files (PDFs, images, etc.) were delivered. Preceding items showed raw MEDIA:/path tags because the queue drain path called adapter.send() without first extracting and delivering media attachments. Fix: call adapter.extract_media() before adapter.send() in the queue follow-up path, mirroring the normal delivery path in gateway/platforms/base.py L2724, and deliver each extracted file via adapter.send_document(). Closes NousResearch#18539
Add the three missing processing steps that the normal delivery path (platforms/base.py L2724-2736) applies but the queue follow-up path was missing: - extract_images() — native delivery of markdown images - re.sub(r'MEDIA:\s*\S+', ...) — secondary strip safety net - extract_local_files() — bare-path detection for small models Also clean [[audio_as_voice]] directive from text content. Refs: NousResearch#18539
Cover the three newly-aligned processing steps in the queue follow-up response path (b6fbcb6): - extract_images() — markdown image extraction and delivery - Secondary re.sub(r'MEDIA:\s*\S+', ...) safety strip - extract_local_files() — bare-path detection - [[audio_as_voice]] directive cleanup 9 new tests covering: single/multiple MEDIA tags, HTML fallback, voice directive, markdown images, stray MEDIA cleanup, plain text no-crash, and mixed media+image combos. Refs: NousResearch#18539
liuhao1024
left a comment
There was a problem hiding this comment.
The media extraction pipeline for queued follow-ups is correct and well-tested. One production-reliability issue though:
Inconsistent error handling in delivery loops. The image and local-file delivery loops use bare except Exception: pass, silently swallowing all failures:
# Deliver extracted images
for image_url, alt_text in (images or []):
try:
await adapter.send_image(...)
except Exception:
pass # ← silent
# Deliver extracted local files
for local_path in (local_files or []):
try:
await adapter.send_document(...)
except Exception:
pass # ← silentBut the media-file loop correctly logs:
except Exception as media_e:
logger.warning("Failed to deliver queue media %s: %s", media_path, media_e)This means image and file delivery failures are completely invisible in production logs. If an adapter's send_image raises (bad URL, expired token, platform rate-limit), the user silently loses the image with no trace.
Suggestion: Match the media-file pattern for the other two loops:
except Exception as img_e:
logger.warning("Failed to deliver queue image %s: %s", image_url, img_e)except Exception as doc_e:
logger.warning("Failed to deliver queue file %s: %s", local_path, doc_e)…ia delivery Match the media-file loop pattern for image and local-file delivery loops so failures are visible in production logs instead of silently swallowed. The media-file loop already logged with logger.warning; the image and local-file loops used bare 'except Exception: pass'. Reviewer feedback: make all three loops consistent for production observability. Refs: NousResearch#18546
|
Thanks for catching the inconsistency — pushed a fix in e1bb21d. All three delivery loops (images, local files, media files) now use |
Summary
When multiple /queue items are chained in a single session, only the last item's MEDIA files (PDFs, images, etc.) were delivered. Preceding items showed raw MEDIA:/path tags because the queue drain path called adapter.send() without first extracting and delivering media attachments.
Fix
Call adapter.extract_media() before adapter.send() in the queue follow-up path (gateway/run.py), mirroring the normal delivery path in gateway/platforms/base.py L2724. Each extracted file is then delivered via adapter.send_document().
Testing
Closes #18539