hermes - 💡(How to fix) Fix [BUG] Telegram media path escaping broken — regex patterns passed as file paths [1 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…

When the Hermes gateway tries to send audio/image media via Telegram, in some conditions the file path is not properly extracted from the MEDIA: tag. Instead, the raw regex pattern or a debug placeholder string is passed to os.path.exists().

Error Message

  1. The error shows a regex pattern or placeholder string as the "path"

Root Cause

In gateway/platforms/base.py line ~1897, extract_media() parses the response content looking for MEDIA:<path> tags. The regex captures the path group correctly when the path is a clean absolute path. However, when the path extraction fails for any reason (e.g. malformed MEDIA tag, whitespace issues), the code falls through to an else branch where it uses the raw matched text (which may be the entire regex pattern or a debug string) as the path.

The Telegram platform's send_voice calls os.path.exists(audio_path) which returns False for these invalid strings.

Fix Action

Fixed

Code Example

gateway.platforms.base: [Telegram] Failed to send media (): File file not found: <path>
gateway.platforms.base: [Telegram] Failed to send media (.ogg\n1888): File file not found: /path/to/audio.ogg\n1888
gateway.platforms.base: [Telegram] Failed to send media (.(?:png|jpe?g|...)): File file not found: \s*(?P<path>...`
RAW_BUFFERClick to expand / collapse

Description

When the Hermes gateway tries to send audio/image media via Telegram, in some conditions the file path is not properly extracted from the MEDIA: tag. Instead, the raw regex pattern or a debug placeholder string is passed to os.path.exists().

Symptom

Errors in gateway.log:

gateway.platforms.base: [Telegram] Failed to send media (): File file not found: <path>
gateway.platforms.base: [Telegram] Failed to send media (.ogg\n1888): File file not found: /path/to/audio.ogg\n1888
gateway.platforms.base: [Telegram] Failed to send media (.(?:png|jpe?g|...)): File file not found: \s*(?P<path>...`

Notice the path is:

  • A debug placeholder like <path>
  • A literal path string like /path/to/audio.ogg
  • The raw regex pattern itself (the media_pattern from extract_media)

Root Cause

In gateway/platforms/base.py line ~1897, extract_media() parses the response content looking for MEDIA:<path> tags. The regex captures the path group correctly when the path is a clean absolute path. However, when the path extraction fails for any reason (e.g. malformed MEDIA tag, whitespace issues), the code falls through to an else branch where it uses the raw matched text (which may be the entire regex pattern or a debug string) as the path.

The Telegram platform's send_voice calls os.path.exists(audio_path) which returns False for these invalid strings.

Steps to Reproduce

  1. Send a message via Telegram that triggers a text_to_speech response
  2. Observe the gateway log — the [[audio_as_voice]] / MEDIA:/path/to/audio.ogg tag is sometimes not correctly parsed
  3. The error shows a regex pattern or placeholder string as the "path"

Environment

  • Hermes Agent: latest
  • Platform: Telegram
  • OS: Debian GNU/Linux 13 (trixie) VM

Suggested Fix

In extract_media() (base.py), add validation before appending to the media list: verify the captured path is a valid filesystem path (starts with /, ~, or a drive letter) before treating it as a file. If the match does not look like a valid path, skip it silently or log a warning with the actual matched text for debugging.

Also audit the send_voice / send_image paths to ensure they receive validated absolute paths only.

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