Skip to content

fix(gateway): strip MEDIA tags before chained /queue follow-up#19011

Open
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/18539-queue-fifo-media
Open

fix(gateway): strip MEDIA tags before chained /queue follow-up#19011
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/18539-queue-fifo-media

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented May 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Multiple /queue items chained in one session via the FIFO queue lost attachments on every item except the last. The queue-drain path in _run_agent called adapter.send(first_response) with the raw, MEDIA:/path-tagged response — so per-item file markers leaked through as plain text, the file existed on disk, but the upload never happened. The normal _process_message_background path runs adapter.extract_media before adapter.send; the queue path missed that gate.

Extract the queue-drain delivery into _send_queued_followup_first_response and run the same extract_mediasend(cleaned_text)send_document / send_voice per file pipeline as the normal path. is_voice-flagged files route through send_voice when the adapter exposes one, falling back to send_document so unsupported adapters still deliver instead of crashing. Per-file upload errors are logged but don't block remaining files — losing one attachment beats losing all.

Related Issue

Fixes #18539

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • gateway/run.py — replace the inline raw-send block in _run_agent's queue-drain branch with a call to a new helper.
  • gateway/run.py — new _send_queued_followup_first_response() method that mirrors the normal path's extract → send → upload-files pipeline.
  • tests/gateway/test_queue_followup_media.py — new file, 5 tests: extract-before-send ordering, multi-document dispatch, voice routing, per-file failure containment, no-MEDIA preserves pre-fix behaviour.

How to Test

  1. In one session, run /queue twice with messages that produce MEDIA attachments (e.g. ask the agent for a chart and a PDF).
  2. Before this PR: only the last item's attachment uploaded; the first appeared as raw MEDIA:/path text.
  3. After: both attachments upload, both texts arrive cleanly.
  4. pytest tests/gateway/test_queue_consumption.py tests/gateway/test_queue_followup_media.py -q → 16/16 pass.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15.x

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

pytest tests/gateway/test_queue_consumption.py tests/gateway/test_queue_followup_media.py -q
16 passed

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels May 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #18546 — both fix the same queue-drain MEDIA extraction bypass from #18539. This PR appears more complete (voice routing, per-file error containment).

@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #18546 — both fix the same queue-drain MEDIA extraction bypass from #18539.

@Tranquil-Flow

Tranquil-Flow commented May 2, 2026

Copy link
Copy Markdown
Contributor Author

Hey @alt-glitch, just flagging that it seems your agent is double commenting here. Might be worth checking how the agent processes new PRs :)

Multiple ``/queue`` items chained in one session via the FIFO queue lost
attachments on every item except the last. The queue-drain path in
``_run_agent`` called ``adapter.send(first_response)`` with the raw,
``MEDIA:/path``-tagged response — so the per-item file markers leaked
through as plain text, the file existed on disk, but the upload never
happened. The normal ``_process_message_background`` path runs
``adapter.extract_media`` before ``adapter.send``; the queue path missed
that gate.

Extract the queue-drain delivery into
``_send_queued_followup_first_response`` and run the same
``extract_media`` → ``send(cleaned_text)`` → ``send_document`` /
``send_voice`` per file pipeline as the normal path. ``is_voice``-flagged
files route through ``send_voice`` when the adapter exposes one, falling
back to ``send_document`` so unsupported adapters still deliver instead
of crashing. Per-file upload errors are logged but don't block the
remaining files — losing one attachment beats losing all.

Tests cover: extract_media-before-send ordering, multi-file dispatch
through ``send_document``, voice-flagged routing through ``send_voice``,
graceful continuation when one upload raises, and the no-MEDIA path
preserving pre-fix behaviour exactly (one ``send`` call, no document
uploads).

Fixes NousResearch#18539
@Tranquil-Flow Tranquil-Flow force-pushed the fix/18539-queue-fifo-media branch from 68e7c6a to a77b571 Compare May 25, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /queue FIFO chain drops MEDIA files — only last item gets media delivery

2 participants