Skip to content

fix(gateway): preserve MEDIA delivery on queued follow-up responses (salvage #71031) - #82162

Merged
teknium1 merged 8 commits into
mainfrom
salvage/71031-queued-media-delivery
Aug 9, 2026
Merged

teknium1 merged 8 commits into
mainfrom
salvage/71031-queued-media-delivery

Conversation

@teknium1

@teknium1 teknium1 commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Telegram (and every gateway platform) no longer leaks literal MEDIA:/path text — or silently drops attachments — when a response is delivered through the queued follow-up path.

Salvage of #71031 by @StellarisW (all 7 commits cherry-picked with authorship preserved; consolidates @vKongv's #25119 work, whose commits were already merged into the PR branch with attribution), plus a follow-up commit adding the failed-result guard from the salvage review.

Both bug branches verified at line level on main: when a message queues during an active run (interrupt-mode next-turn handoff, subagent/compression demotions, photo bursts, or queue mode), the first turn's response is delivered by a side path in _run_agent that bypassed MEDIA handling entirely — (1) non-streamed responses went out via raw adapter.send() with the literal MEDIA: tag as text and no file; (2) already-streamed responses logged "delivery confirmed" and silently dropped the attachments. Hermes told the user a file was produced; the file never arrived.

Changes

  • gateway/run.py (contributor): new _deliver_queued_first_response() — splits text from attachments via the existing extract_media + _deliver_media_from_response machinery (path-security filtering and the explicit-only bug(gateway): post-stream media delivery can upload bare local paths not intentionally present in the visible reply #20834 policy preserved), covers both branches via text_already_delivered, keeps thread/reply routing metadata, keeps protected `MEDIA:` examples and bare paths as visible text, applies the intentional-silence predicate.
  • gateway/run.py (follow-up): deliver_media=not _delivery_result.get("failed") — a failed first turn still delivers its normalized failure text but never uploads its attachments, mirroring the completed-turn path's guard. Regression test added.
  • Tests: exactly-once assertions (single image batch, single text send), routing-metadata reuse, protected-example preservation, bare-path/remote-URL contract, commentary-vs-final, normalized-failure text.

Conflicts were confined to the two test files flagged in review (test_run_progress_topics.py, test_tts_media_routing.py — neighboring tests added on main); production run.py changes applied clean.

Validation

Before After
Queued follow-up, non-streamed first turn literal MEDIA:/path text, no file text cleaned, file uploaded natively
Queued follow-up, streamed first turn attachments silently dropped attachments delivered exactly once
Failed first turn n/a (leaked) failure text only, no uploads
tests/gateway/ full directory — 5101/5101 pass

After merge: close #18546, #25119, #46223, #51805 as superseded (each covered only the fallback branch or violated the explicit-only policy); #56092 (duplicate re-send race) is orthogonal and stays open.

Infographic

File delivered

StellarisW and others added 8 commits August 8, 2026 18:48
Ensure queued follow-up resends keep MEDIA-backed attachments by replaying the
first response through the gateway's text-plus-media delivery flow instead of a
plain adapter text send.
MEDIA:/tmp paths are filtered by delivery safe roots; mirror other tests
by placing the fixture under an allowed cache directory.
Drop the broad MEDIA: regex after extract_media so code/inline examples
survive, and cover the real queued first-response resend path in tests.
… delivery

Adds the failed-result guard the salvage review called for:
_deliver_queued_first_response now takes deliver_media and the queued
follow-up call site passes deliver_media=not _delivery_result.get('failed').
A failed turn still delivers its normalized failure text (pinned by
test_run_agent_sends_normalized_failure_before_queued_followup), but its
attachments are no longer uploaded as if the turn succeeded — mirroring
the completed-turn path's 'not agent_result.get(failed)' guard.
Regression test added.
@github-actions

github-actions Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

૮ >ﻌ< ა ci review

ran on 00c6c07

⚠️ Warnings

OSV vulnerability scan · View job

21 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.


debug info

CI timings

CI timings · View report · View job

Wall time 3m50s vs 6m54s (-44.4%). 5 job(s) slower, 14 faster, 4 unchanged.

  • Python tests / Run tests slice 7/12: +52.0s
  • Python tests / Run tests slice 8/12: -30.0s
  • Python tests / Run tests slice 4/12: -20.0s
  • Python tests / Run tests slice 10/12: +12.0s
  • Python tests / Run tests slice 11/12: -9.0s

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery needs-decision Awaiting maintainer decision before any implementation sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Aug 9, 2026
@alt-glitch

Copy link
Copy Markdown

This was generated by AI during triage.

Related: this maintainer salvage supersedes the queued-media continuity approach in #71031 and consolidates work from #25119. It remains part of the open queued-follow-up media-routing cluster with #46223 and #51805.

@teknium1
teknium1 merged commit 0b17b69 into main Aug 9, 2026
45 checks passed
@teknium1
teknium1 deleted the salvage/71031-queued-media-delivery branch August 9, 2026 02:17
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 6, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 6, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 6, 2026
cursor Bot pushed a commit to pebble-tech/hermes-agent that referenced this pull request Sep 7, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 9, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 9, 2026
cursor Bot pushed a commit to pebble-tech/hermes-agent that referenced this pull request Sep 21, 2026
cursor Bot pushed a commit to pebble-tech/hermes-agent that referenced this pull request Sep 22, 2026
cursor Bot pushed a commit to pebble-tech/hermes-agent that referenced this pull request Sep 23, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 24, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 24, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 24, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 24, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 24, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 24, 2026
cursor Bot pushed a commit to pebble-tech/hermes-agent that referenced this pull request Sep 27, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 28, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 28, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 28, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 28, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 28, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 28, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 29, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 29, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 29, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 29, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 29, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 29, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 30, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 30, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 30, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 30, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 30, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Sep 30, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Oct 1, 2026
vKongv added a commit to pebble-tech/hermes-agent that referenced this pull request Oct 1, 2026
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 needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants