hermes - ✅(Solved) Fix [Bug] Weixin: send_document called with empty path after every text response (EISDIR) [1 pull requests, 1 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#19510Fetched 2026-05-05 06:06:22
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×3cross-referenced ×1

Error Message

The error is: ERROR [Weixin] send_document failed to=o9cq803o: [Errno 21] Is a directory: '/' Note the empty () in "Failed to send media ()" — the media path being passed is empty or resolves to "/", causing an EISDIR (Is a directory) OS error. 3. Observe gateway logs — the error appears immediately after Sending response 10:34:56,531 ERROR [Weixin] send_document failed to=o9cq803o: [Errno 21] Is a directory: '/' 10:34:56,532 WARN [Weixin] Failed to send media (): [Errno 21] Is a directory: '/' The user sees the text message fine (the text delivery succeeds before this error). The error is logged but doesn't block the conversation.

Fix Action

Fixed

PR fix notes

PR #19528: fix(weixin): skip invalid/empty media paths to prevent EISDIR error

Description (problem / solution / changelog)

Summary

Fixes #19510

The Weixin gateway was calling send_document with an empty or directory path (/) after every text response, causing:

ERROR [Weixin] send_document failed to=o9cq803o: [Errno 21] Is a directory: '/'
WARNING [Weixin] Failed to send media (): [Errno 21] Is a directory: '/'

Root Cause

extract_media() in gateway/platforms/base.py could return paths that expand to directories (e.g. / from a malformed or empty MEDIA: tag). The media delivery loops in both base.py and weixin.py had no validation guards, so these invalid paths were passed directly to send_document().

Changes

  • gateway/platforms/base.py:
    • extract_media(): Skip paths that resolve to directories after os.path.expanduser()
    • handle_message() media delivery loop: Validate media_path is an existing file before attempting delivery
    • handle_message() local files loop: Same validation for auto-detected local file paths
  • gateway/platforms/weixin.py:
    • send() / _deliver_media(): Validate path is an existing file before dispatching to send_document/send_voice/etc.

All invalid paths are logged at WARNING level for debugging.

Testing

  • All existing extract_media and weixin tests pass (57 passed)
  • Changes are defensive guards only — no behavioral change for valid paths

Changed files

  • gateway/platforms/base.py (modified, +10/-1)
  • gateway/platforms/weixin.py (modified, +3/-0)

Code Example

ERROR [Weixin] send_document failed to=o9cq803o: [Errno 21] Is a directory: '/'
WARNING [Weixin] Failed to send media (): [Errno 21] Is a directory: '/'

---

10:34:56,278 INFO  [Weixin] Sending response (182 chars) to o9cq803o
10:34:56,531 ERROR [Weixin] send_document failed to=o9cq803o: [Errno 21] Is a directory: '/'
10:34:56,532 WARN  [Weixin] Failed to send media (): [Errno 21] Is a directory: '/'
RAW_BUFFERClick to expand / collapse

Bug Description

Weixin (微信) gateway calls send_document with an empty/root-directory path after every text response, even pure text responses with no media attachments.

The error is:

ERROR [Weixin] send_document failed to=o9cq803o: [Errno 21] Is a directory: '/'
WARNING [Weixin] Failed to send media (): [Errno 21] Is a directory: '/'

Note the empty () in "Failed to send media ()" — the media path being passed is empty or resolves to "/", causing an EISDIR (Is a directory) OS error.

Steps to Reproduce

  1. Configure Weixin gateway
  2. Send any text message (e.g., "hello") — the user receives the text normally
  3. Observe gateway logs — the error appears immediately after Sending response

Expected Behavior

Pure text responses should only send text. No send_document call should be made when no media was extracted.

Actual Behavior

After every text response delivery:

10:34:56,278 INFO  [Weixin] Sending response (182 chars) to o9cq803o
10:34:56,531 ERROR [Weixin] send_document failed to=o9cq803o: [Errno 21] Is a directory: '/'
10:34:56,532 WARN  [Weixin] Failed to send media (): [Errno 21] Is a directory: '/'

The user sees the text message fine (the text delivery succeeds before this error). The error is logged but doesn't block the conversation.

Impact

  • Benign in terms of user experience (text messages still arrive)
  • Pollutes logs on every single response
  • Indicates a logic bug in the media delivery pipeline — an empty path is being passed unconditionally

Suspected Code Paths

In gateway/platforms/base.py, the media delivery loop:

  • Line 2835: _non_image_media.append((media_path, is_voice))
  • Line 2873: send_document(file_path=media_path) — called with the path from line 2835

Or the _deliver_media_from_response path in gateway/run.py:

  • Line 8081-8083: extracts media and local files from the response text

The question is: how does an empty/invalid path end up in the media list when the response text contains no MEDIA: tags or local file paths?

Environment

  • Hermes: latest
  • Python: 3.12
  • macOS Apple Silicon
  • Weixin channel: @tencent-weixin/openclaw-weixin plugin

extent analysis

TL;DR

The issue can be fixed by ensuring that the media path is validated before calling send_document to prevent empty or root-directory paths from being passed.

Guidance

  • Review the media delivery loop in gateway/platforms/base.py to verify that the media_path is correctly populated and validated before calling send_document.
  • Check the _deliver_media_from_response function in gateway/run.py to ensure that it correctly handles responses without MEDIA: tags or local file paths and does not add empty paths to the media list.
  • Consider adding a conditional check before calling send_document to skip the call if the media_path is empty or resolves to the root directory.
  • Investigate why the _non_image_media list is being populated with an empty path when the response text contains no media attachments.

Example

if media_path and media_path != '/':
    send_document(file_path=media_path)

Notes

The issue seems to be related to the logic bug in the media delivery pipeline, and fixing it will require careful review of the code paths involved. The provided example is a simple conditional check, but the actual fix may require more complex changes.

Recommendation

Apply a workaround by adding a conditional check before calling send_document to prevent empty or root-directory paths from being passed, as this will immediately address the log pollution issue and prevent unnecessary send_document calls.

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 [Bug] Weixin: send_document called with empty path after every text response (EISDIR) [1 pull requests, 1 participants]