hermes - ✅(Solved) Fix Gateway should not treat MEDIA examples or missing files as attachments [2 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#16434Fetched 2026-04-28 06:53:21
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Participants
Timeline (top)
labeled ×3cross-referenced ×2commented ×1

Error Message

This creates noisy warning/error logs during code review, grep output, or tests that include MEDIA: examples, making real delivery failures harder to spot.

Fix Action

Fixed

PR fix notes

PR #16436: fix(gateway): ignore MEDIA examples without local files

Description (problem / solution / changelog)

Summary

  • Ignore MEDIA: tags inside fenced code blocks and inline code.
  • Only extract MEDIA: paths for native delivery when the expanded local file exists.
  • Preserve skipped MEDIA: examples in text instead of removing them or attempting delivery.

Root cause

BasePlatformAdapter.extract_media() treated any MEDIA:<path> token as a real attachment directive. Code snippets, grep output, and test examples containing MEDIA:/tmp/missing.png were therefore sent through native media delivery and produced noisy File not found warnings.

What changed

  • Builds code spans for fenced and inline code and skips matches inside them.
  • Validates candidate paths with os.path.isfile() before adding them to the media list.
  • Removes only accepted delivery tags from the outgoing text; skipped examples remain visible.
  • Updates gateway media extraction tests to use real temp files for positive cases and adds coverage for missing files / code examples.

Tests

  • python -m pytest tests/gateway/test_media_extraction.py tests/gateway/test_platform_base.py -q -o 'addopts='

Verification

  • Verified that existing local media files are still extracted and removed from text.
  • Verified that missing paths, fenced-code examples, and inline-code examples are not extracted and are preserved.

Fixes #16434

Changed files

  • gateway/platforms/base.py (modified, +40/-8)
  • tests/gateway/test_platform_base.py (modified, +70/-25)

PR #16585: fix(gateway): skip MEDIA tags inside code blocks in extract_media

Description (problem / solution / changelog)

Fixes NousResearch/hermes-agent#16434

Problem

When the agent's response contains MEDIA: tags inside fenced code blocks (``` ... ```) or inline code (`...`), the gateway incorrectly treats them as real attachment directives and tries to deliver the files. This also mangles code examples in streamed display.

Root Cause

extract_media() in base.py and _clean_for_display() in stream_consumer.py use finditer() / sub() over raw content with no code-block filtering. Ironically, extract_local_files() in the same file already has this exact code-block awareness pattern.

Fix

Applied the same code-block-aware pattern already used by extract_local_files():

  1. base.pyextract_media(): Build code_spans list from fenced/inline code blocks, skip matches inside those spans, and only remove non-code MEDIA tags from cleaned content.

  2. stream_consumer.py_clean_for_display(): Same pattern — build code spans, use _safe_sub() to preserve MEDIA tags inside code blocks.

Files Changed

  • gateway/platforms/base.py — 20 lines added (code-block filtering in extract_media())
  • gateway/stream_consumer.py — 15 lines added (code-block filtering in _clean_for_display())

Changed files

  • gateway/platforms/base.py (modified, +19/-1)
  • gateway/stream_consumer.py (modified, +16/-1)

Code Example

[Feishu] Failed to send media (.png): Image file not found: /tmp/img.png
RAW_BUFFERClick to expand / collapse

Bug Description

Gateway response post-processing treats every MEDIA:<path> token as a real attachment directive, even when the token appears inside fenced code blocks, inline code, grep output, or other examples. It also attempts to send non-existent paths, producing noisy Failed to send media: File not found warnings.

Steps to Reproduce

  1. Send a gateway response that contains a code snippet or test output with a literal MEDIA:/tmp/missing.png example.
  2. Let the platform adapter post-process the response.
  3. Inspect errors.log / gateway logs.

Expected Behavior

  • Literal MEDIA: examples inside code should remain text.
  • Non-existent MEDIA: paths should not be attempted as attachments.
  • Real existing local files referenced by MEDIA: should still be delivered and removed from text.

Actual Behavior

The adapter attempts delivery for example/missing paths and logs warnings such as:

[Feishu] Failed to send media (.png): Image file not found: /tmp/img.png

Impact

This creates noisy warning/error logs during code review, grep output, or tests that include MEDIA: examples, making real delivery failures harder to spot.

Proposed Fix

Update BasePlatformAdapter.extract_media() to:

  • ignore matches inside fenced code blocks and inline code,
  • validate that expanded local paths exist before returning them for delivery,
  • remove only accepted delivery tags from the outgoing text.

extent analysis

TL;DR

Update the BasePlatformAdapter.extract_media() method to ignore MEDIA: tokens within code blocks and validate file existence before attempting delivery.

Guidance

  • Review the BasePlatformAdapter.extract_media() method to ensure it correctly handles MEDIA: tokens within fenced code blocks, inline code, and other examples by ignoring them.
  • Modify the method to check if the expanded local path exists before returning it for delivery, preventing attempts to send non-existent files.
  • Adjust the method to remove only successfully delivered media tags from the outgoing text, reducing noise in the logs.
  • Test the updated method with various scenarios, including code snippets and test outputs containing MEDIA: examples, to verify the fix.

Example

def extract_media(text):
    # ...
    for match in media_matches:
        if is_inside_code_block(text, match) or not path_exists(match.path):
            continue
        # Attempt delivery and remove tag if successful
        # ...

Notes

The proposed fix assumes that the is_inside_code_block() and path_exists() functions are implemented correctly. Additional testing may be necessary to ensure the updated method works as expected in all scenarios.

Recommendation

Apply the workaround by updating the BasePlatformAdapter.extract_media() method as described, to reduce log noise and improve the overall reliability of the gateway response post-processing.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix Gateway should not treat MEDIA examples or missing files as attachments [2 pull requests, 1 comments, 2 participants]