hermes - 💡(How to fix) Fix from session history are re-delivered as media files [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…

Error Message

def filter_media_delivery_paths(media_files) -> List[Tuple[str, bool]]: """Drop unsafe MEDIA paths and normalize accepted paths.""" import time as _time _MAX_AGE = 300 # 5 minutes — reject stale from history safe_media: List[Tuple[str, bool]] = [] for media_path, is_voice in media_files or []: safe_path = validate_media_delivery_path(str(media_path)) if safe_path: try: age = _time.time() - os.path.getmtime(safe_path) if age > _MAX_AGE: logger.info("Skipping stale MEDIA file (age=%.0fs): %s", age, safe_path) continue except OSError: pass safe_media.append((safe_path, bool(is_voice))) else: logger.warning("Skipping unsafe MEDIA directive path outside allowed roots") return safe_media

Root Cause

extract_media() in gateway/platforms/base.py (line ~2460) uses a regex to find all ` patterns in the response text, without distinguishing between:

  • Freshly generated files (from tool output in this turn) — should be delivered
  • Historical references (from session history / memory context) — should NOT be delivered

The gateway has no per-turn state tracking of which files were explicitly generated.

Fix Action

Fixed

Code Example

def filter_media_delivery_paths(media_files) -> List[Tuple[str, bool]]:
    """Drop unsafe MEDIA paths and normalize accepted paths."""
    import time as _time
    _MAX_AGE = 300  # 5 minutes — reject stale  from history
    safe_media: List[Tuple[str, bool]] = []
    for media_path, is_voice in media_files or []:
        safe_path = validate_media_delivery_path(str(media_path))
        if safe_path:
            try:
                age = _time.time() - os.path.getmtime(safe_path)
                if age > _MAX_AGE:
                    logger.info("Skipping stale MEDIA file (age=%.0fs): %s", age, safe_path)
                    continue
            except OSError:
                pass
            safe_media.append((safe_path, bool(is_voice)))
        else:
            logger.warning("Skipping unsafe MEDIA directive path outside allowed roots")
    return safe_media
RAW_BUFFERClick to expand / collapse

Describe the bug

When the agent references past conversation history that contains tags (e.g., quoting a previous TTS or image response), the gateway'sextract_media()` blindly extracts and re-delivers those files to the user. This causes stale media (old TTS audio, screenshots, generated images) to be sent repeatedly, often in unrelated conversations.

In my case, a single TTS audio file (tts_20260604_223856.mp3) was delivered 5 times over 2 days — once correctly when generated, and 4 more times whenever the agent's response referenced the original conversation.

To reproduce

  1. Have a conversation where the agent generates a TTS audio or image (response contains )
  2. In a later session, ask the agent about past conversations or memory contents
  3. The agent uses session_search or recalls memory that includes the old ` tag
  4. The agent's response references the old conversation text, including the ` tag
  5. Gateway extracts the tag and re-delivers the file to the user

Expected behavior

tags (from session history, memory context, or session_search results) should be stripped or ignored.

Root cause

extract_media() in gateway/platforms/base.py (line ~2460) uses a regex to find all ` patterns in the response text, without distinguishing between:

  • Freshly generated files (from tool output in this turn) — should be delivered
  • Historical references (from session history / memory context) — should NOT be delivered

The gateway has no per-turn state tracking of which files were explicitly generated.

Evidence from logs

Correct delivery (TTS tool call) 2026-06-04 22:39:04 — extracted 1 media file: tts_20260604_223856.mp3

Bug: re-delivery when agent quoted history in unrelated conversation 2026-06-05 11:53:29 — extracted 2 media files: [tts_20260604_223856.mp3, tts_20260604_223747.mp3]

Bug: re-delivery when agent was discussing the bug itself 2026-06-05 12:05:02 — extracted 1 media file: tts_20260604_223856.mp3 2026-06-05 12:22:21 — extracted 2 media files: [tts_20260604_223856.mp3, tts_20260604_223856.mp3]

Suggested fix

Add a file age check in filter_media_delivery_paths() (~line 2398 in base.py): reject files older than a configurable TTL (e.g., 5 minutes). This is the minimal change that prevents stale re-delivery while preserving current behavior for freshly generated files.

def filter_media_delivery_paths(media_files) -> List[Tuple[str, bool]]:
    """Drop unsafe MEDIA paths and normalize accepted paths."""
    import time as _time
    _MAX_AGE = 300  # 5 minutes — reject stale  from history
    safe_media: List[Tuple[str, bool]] = []
    for media_path, is_voice in media_files or []:
        safe_path = validate_media_delivery_path(str(media_path))
        if safe_path:
            try:
                age = _time.time() - os.path.getmtime(safe_path)
                if age > _MAX_AGE:
                    logger.info("Skipping stale MEDIA file (age=%.0fs): %s", age, safe_path)
                    continue
            except OSError:
                pass
            safe_media.append((safe_path, bool(is_voice)))
        else:
            logger.warning("Skipping unsafe MEDIA directive path outside allowed roots")
    return safe_media

An alternative (more thorough) fix would be to strip paths in the first place.

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

tags (from session history, memory context, or session_search results) should be stripped or ignored.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING