hermes - 💡(How to fix) Fix fix(gateway): MEDIA: directive silently drops .html and other extensions due to regex/whitelist drift [3 pull requests]

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…

gateway/platforms/base.py has two independent file-extension whitelists used for media routing that have drifted out of sync:

  • extract_media() parses explicit MEDIA:<path> directives produced by the model.
  • extract_local_files() finds bare local paths in response text.

extract_local_files's _LOCAL_MEDIA_EXTS accepts .html, .htm, .md, .svg, .bmp, .tiff, .json, .xml, .yaml, .yml, .tsv, .ods, .odp, .odt, .rtf, .key, .tar, .gz, .tgz, .bz2, .xz — but the regex inside extract_media does not.

When the model emits MEDIA:/abs/path/file.html (or any other missing extension), the extract_media regex doesn't match, the file is never attached, and the parent send_message tool still reports success: true because the text portion ships fine. Silent data loss, no log line at any level.

The (?<![/:\w.]) anti-URL guard inside extract_local_files also disqualifies the same path (the : after MEDIA defeats it), so the path falls between both detectors.

Root Cause

gateway/platforms/base.py, around line 2270:

media_pattern = re.compile(
    r'''[`"']?MEDIA:\s*(?P<path>`[^`\n]+`|"[^"\n]+"|'[^'\n]+'|(?:~/|/)\S+(?:[^\S\n]+\S+)*?\.(?:png|jpe?g|gif|webp|mp4|mov|avi|mkv|webm|ogg|opus|mp3|wav|m4a|flac|epub|pdf|zip|rar|7z|docx?|xlsx?|pptx?|txt|csv|apk|ipa)(?=[\s`"',;:)\]}]|$))[`"']?'''
)

vs.

_LOCAL_MEDIA_EXTS = (
    '.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.tiff', '.svg',
    '.mp4', '.mov', '.avi', '.mkv', '.webm',
    '.mp3', '.wav', '.ogg', '.m4a', '.flac',
    '.pdf', '.docx', '.doc', '.odt', '.rtf', '.txt', '.md',
    '.xlsx', '.xls', '.ods', '.csv', '.tsv', '.json', '.xml', '.yaml', '.yml',
    '.pptx', '.ppt', '.odp', '.key',
    '.zip', '.tar', '.gz', '.tgz', '.bz2', '.xz', '.7z', '.rar',
    '.html', '.htm',
)

The two lists need to stay in sync, but the structure (one is a regex alternation, one is a tuple) makes it easy to forget.

Fix Action

Fixed

Code Example

media_pattern = re.compile(
    r'''[`"']?MEDIA:\s*(?P<path>`[^`\n]+`|"[^"\n]+"|'[^'\n]+'|(?:~/|/)\S+(?:[^\S\n]+\S+)*?\.(?:png|jpe?g|gif|webp|mp4|mov|avi|mkv|webm|ogg|opus|mp3|wav|m4a|flac|epub|pdf|zip|rar|7z|docx?|xlsx?|pptx?|txt|csv|apk|ipa)(?=[\s`"',;:)\]}]|$))[`"']?'''
)

---

_LOCAL_MEDIA_EXTS = (
    '.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.tiff', '.svg',
    '.mp4', '.mov', '.avi', '.mkv', '.webm',
    '.mp3', '.wav', '.ogg', '.m4a', '.flac',
    '.pdf', '.docx', '.doc', '.odt', '.rtf', '.txt', '.md',
    '.xlsx', '.xls', '.ods', '.csv', '.tsv', '.json', '.xml', '.yaml', '.yml',
    '.pptx', '.ppt', '.odp', '.key',
    '.zip', '.tar', '.gz', '.tgz', '.bz2', '.xz', '.7z', '.rar',
    '.html', '.htm',
)
RAW_BUFFERClick to expand / collapse

Summary

gateway/platforms/base.py has two independent file-extension whitelists used for media routing that have drifted out of sync:

  • extract_media() parses explicit MEDIA:<path> directives produced by the model.
  • extract_local_files() finds bare local paths in response text.

extract_local_files's _LOCAL_MEDIA_EXTS accepts .html, .htm, .md, .svg, .bmp, .tiff, .json, .xml, .yaml, .yml, .tsv, .ods, .odp, .odt, .rtf, .key, .tar, .gz, .tgz, .bz2, .xz — but the regex inside extract_media does not.

When the model emits MEDIA:/abs/path/file.html (or any other missing extension), the extract_media regex doesn't match, the file is never attached, and the parent send_message tool still reports success: true because the text portion ships fine. Silent data loss, no log line at any level.

The (?<![/:\w.]) anti-URL guard inside extract_local_files also disqualifies the same path (the : after MEDIA defeats it), so the path falls between both detectors.

Reproduction

Telegram, gateway running:

  1. Put any file with one of the missing extensions on a media-allowed root, e.g. /root/.hermes/media_cache/foo.html.
  2. Have the agent return a reply containing literally MEDIA:/root/.hermes/media_cache/foo.html.
  3. Observe: text arrives, file does not. send_message tool result is success: true.

Direct POST https://api.telegram.org/bot$TOKEN/sendDocument against the same file works first try — confirming the bug is in extraction, not transport.

Affected platforms

All platforms that use BasePlatformAdapter.extract_media — i.e. every messaging platform in gateway/platforms/. The bug only surfaces for extensions in the gap between the two lists, but those gaps cover common artifact types (HTML reports, Markdown notes, JSON exports, SVG charts, archives, etc.).

Root cause

gateway/platforms/base.py, around line 2270:

media_pattern = re.compile(
    r'''[`"']?MEDIA:\s*(?P<path>`[^`\n]+`|"[^"\n]+"|'[^'\n]+'|(?:~/|/)\S+(?:[^\S\n]+\S+)*?\.(?:png|jpe?g|gif|webp|mp4|mov|avi|mkv|webm|ogg|opus|mp3|wav|m4a|flac|epub|pdf|zip|rar|7z|docx?|xlsx?|pptx?|txt|csv|apk|ipa)(?=[\s`"',;:)\]}]|$))[`"']?'''
)

vs.

_LOCAL_MEDIA_EXTS = (
    '.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.tiff', '.svg',
    '.mp4', '.mov', '.avi', '.mkv', '.webm',
    '.mp3', '.wav', '.ogg', '.m4a', '.flac',
    '.pdf', '.docx', '.doc', '.odt', '.rtf', '.txt', '.md',
    '.xlsx', '.xls', '.ods', '.csv', '.tsv', '.json', '.xml', '.yaml', '.yml',
    '.pptx', '.ppt', '.odp', '.key',
    '.zip', '.tar', '.gz', '.tgz', '.bz2', '.xz', '.7z', '.rar',
    '.html', '.htm',
)

The two lists need to stay in sync, but the structure (one is a regex alternation, one is a tuple) makes it easy to forget.

Expected behavior

Any extension accepted by extract_local_files should also be accepted by extract_media. A model emitting MEDIA:/path/to/report.html should result in the file being attached as a document (the same routing the bare-path detection would do).

Suggested fix

Extend the extract_media regex extension list to be a superset of _LOCAL_MEDIA_EXTS, and add a binding comment so future drift gets caught in review.

I have a PR ready: #<PR_NUMBER_PLACEHOLDER> (43-case parametrized regression test + the original user-reported repro path).

Environment

  • Hermes Agent: git rev origin/mainf3fb7899d (May 2026)
  • OS: Linux (Ubuntu, kernel 6.8.0-111-generic)
  • Python 3.11, gateway running under user systemd unit
  • Transport: Telegram bot

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…

FAQ

Expected behavior

Any extension accepted by extract_local_files should also be accepted by extract_media. A model emitting MEDIA:/path/to/report.html should result in the file being attached as a document (the same routing the bare-path detection would do).

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 - 💡(How to fix) Fix fix(gateway): MEDIA: directive silently drops .html and other extensions due to regex/whitelist drift [3 pull requests]