hermes - 💡(How to fix) Fix [Weixin] File/image sending fails with asyncio timeout error [2 comments, 3 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#17595Fetched 2026-04-30 06:46:31
View on GitHub
Comments
2
Participants
3
Timeline
8
Reactions
0
Author
Timeline (top)
labeled ×4commented ×2mentioned ×1subscribed ×1

Error Message

When sending images/files to WeChat via the send_message tool, if the Gateway is running, the following error operations on the aiohttp session cause Python 3.11+'s asyncio.timeout() to raise an exception.

Root Cause

Root Cause The send_weixin_direct function in gateway/platforms/weixin.py attempts to reuse the aiohttp.ClientSession from the already-connected adapter in _LIVE_ADAPTERS.

Fix Action

Fix / Workaround

This bug has been reported and patched multiple times without being merged:

Code Example

Timeout context manager should be used inside a task
Task <Task pending name='Task-2844' coro=<_send_to_platform() running at
home/*/hermes-agent/tools/send_message_tool.py:507> got Future attached to a different loop
RAW_BUFFERClick to expand / collapse

Bug Description: When sending images/files to WeChat via the send_message tool, if the Gateway is running, the following error

Timeout context manager should be used inside a task
Task <Task pending name='Task-2844' coro=<_send_to_platform() running at
home/*/hermes-agent/tools/send_message_tool.py:507> got Future attached to a different loop

Plain text messages are sent successfully, but messages with media (images, files) fail.

Root Cause The send_weixin_direct function in gateway/platforms/weixin.py attempts to reuse the aiohttp.ClientSession from the already-connected adapter in _LIVE_ADAPTERS.

When send_message tool is called from CLI or cron, _run_async creates a separate event loop (loop B) in a new thread, while the live adapter's session is bound to the Gateway's main event loop (loop A). Cross-loop operations on the aiohttp session cause Python 3.11+'s asyncio.timeout() to raise an exception. Environment

  • Hermes Agent version: latest
  • Python version: 3.11+
  • aiohttp version: 3.10+
  • Platform: Weixin Related Issues

This bug has been reported and patched multiple times without being merged:

  • #12016, #12810, #13350, #13361, #13520, #14384, #14530, #14873, #15911, #16074, #16540, #17557

Maintainer @alt-glitch has commented on several of these marking them as duplicates and suggesting consolidation.

Questions for Maintainers

  1. This bug makes Weixin file/image sending completely unusable (text works fine, but media always fails with Timeout context manager should be used inside a task). Over 10 contributors have submitted PRs for this issue, yet none have been merged — we're hoping to understand if there are any ongoing technical considerations or concerns that have made it difficult to land a fix.
  2. Is there an existing plan or preferred approach to resolve this? We'd love to know if there's a direction the maintainers favor (e.g., detecting loop mismatch and falling back to a fresh session, vs. scheduling sends onto the adapter's loop with run_coroutine_threadsafe).

extent analysis

TL;DR

The most likely fix involves ensuring that the aiohttp.ClientSession is used within the same event loop as the Gateway's main event loop to avoid cross-loop operations.

Guidance

  • Verify that the send_weixin_direct function in gateway/platforms/weixin.py is indeed attempting to reuse the aiohttp.ClientSession from the already-connected adapter in _LIVE_ADAPTERS, which is bound to the Gateway's main event loop.
  • Consider using asyncio.run_coroutine_threadsafe to schedule the send operation onto the adapter's loop, ensuring that the aiohttp.ClientSession is used within the same event loop.
  • Investigate the possibility of detecting loop mismatch and falling back to a fresh session as an alternative solution.
  • Review the related issues and maintainer comments to understand the technical considerations and concerns that have prevented a fix from being merged.

Notes

The issue seems to be specific to Python 3.11+ and aiohttp version 3.10+, and the maintainers have marked several related issues as duplicates, suggesting a need for consolidation.

Recommendation

Apply a workaround by using asyncio.run_coroutine_threadsafe to schedule the send operation onto the adapter's loop, ensuring that the aiohttp.ClientSession is used within the same event loop, as this approach seems to be a viable solution to the cross-loop operation issue.

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