hermes - 💡(How to fix) Fix send_message weixin: asyncio 'Future attached to a different loop' bug [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

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#23371Fetched 2026-05-11 03:29:47
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×5commented ×1

Error Message

The send_message tool fails with a cross-event-loop asyncio error when trying to send to Weixin: 5. Inside _send_to_platform, await _send_weixin(...) fails with the error above The send_message_tool runs in the agent/LLM tool-execution context, NOT inside the gateway's async stack. When _run_async is called, asyncio.get_running_loop() returns the gateway's loop (which IS running), so the code takes the worker-thread path. But the error occurs inside _send_to_platform itself — not inside send_weixin_direct. Key observation: Even though send_weixin_direct was patched to always use the standalone aiohttp.ClientSession path (bypassing _LIVE_ADAPTERS), the error persists. This means the problem is not in send_weixin_direct — it's at the await _send_weixin() call site inside _send_to_platform at line 524.

Root Cause

Call chain:

  1. send_message tool → _handle_send()
  2. _run_async(_send_to_platform(...)) — since Hermes gateway has a running event loop, this takes the worker-thread path
  3. Worker thread creates asyncio.new_event_loop()worker_loop
  4. worker_loop.run_until_complete(_send_to_platform())
  5. Inside _send_to_platform, await _send_weixin(...) fails with the error above

Why it fails: The send_message_tool runs in the agent/LLM tool-execution context, NOT inside the gateway's async stack. When _run_async is called, asyncio.get_running_loop() returns the gateway's loop (which IS running), so the code takes the worker-thread path. But the error occurs inside _send_to_platform itself — not inside send_weixin_direct.

This suggests that either:

  1. Some import-time side effect in gateway/platforms/weixin.py creates objects bound to the gateway loop, OR
  2. The await _send_weixin() expression itself is where the cross-loop Future is encountered

Key observation: Even though send_weixin_direct was patched to always use the standalone aiohttp.ClientSession path (bypassing _LIVE_ADAPTERS), the error persists. This means the problem is not in send_weixin_direct — it's at the await _send_weixin() call site inside _send_to_platform at line 524.

Affected code path:

  • tools/send_message_tool.py line ~524: return await _send_weixin(pconfig, chat_id, message, media_files=media_files)
  • _send_weixin is an async def that imports and calls gateway.platforms.weixin.send_weixin_direct

Fix Action

Fix / Workaround

Key observation: Even though send_weixin_direct was patched to always use the standalone aiohttp.ClientSession path (bypassing _LIVE_ADAPTERS), the error persists. This means the problem is not in send_weixin_direct — it's at the await _send_weixin() call site inside _send_to_platform at line 524.

Current Workaround

Code Example

Task <Task pending name='Task-1857' coro=<_send_to_platform() running at tools/send_message_tool.py:524>> got Future <Future pending> attached to a different loop
RAW_BUFFERClick to expand / collapse

Bug Description

The send_message tool fails with a cross-event-loop asyncio error when trying to send to Weixin:

Task <Task pending name='Task-1857' coro=<_send_to_platform() running at tools/send_message_tool.py:524>> got Future <Future pending> attached to a different loop

This happens every time send_message is invoked for Weixin, regardless of the message content.

Root Cause Analysis

Call chain:

  1. send_message tool → _handle_send()
  2. _run_async(_send_to_platform(...)) — since Hermes gateway has a running event loop, this takes the worker-thread path
  3. Worker thread creates asyncio.new_event_loop()worker_loop
  4. worker_loop.run_until_complete(_send_to_platform())
  5. Inside _send_to_platform, await _send_weixin(...) fails with the error above

Why it fails: The send_message_tool runs in the agent/LLM tool-execution context, NOT inside the gateway's async stack. When _run_async is called, asyncio.get_running_loop() returns the gateway's loop (which IS running), so the code takes the worker-thread path. But the error occurs inside _send_to_platform itself — not inside send_weixin_direct.

This suggests that either:

  1. Some import-time side effect in gateway/platforms/weixin.py creates objects bound to the gateway loop, OR
  2. The await _send_weixin() expression itself is where the cross-loop Future is encountered

Key observation: Even though send_weixin_direct was patched to always use the standalone aiohttp.ClientSession path (bypassing _LIVE_ADAPTERS), the error persists. This means the problem is not in send_weixin_direct — it's at the await _send_weixin() call site inside _send_to_platform at line 524.

Affected code path:

  • tools/send_message_tool.py line ~524: return await _send_weixin(pconfig, chat_id, message, media_files=media_files)
  • _send_weixin is an async def that imports and calls gateway.platforms.weixin.send_weixin_direct

Environment

  • macOS (macOS-aarch64)
  • Python 3.11 via uv
  • Hermes Agent gateway running (hermes gateway run)
  • Weixin platform connected

Current Workaround

None — the bug blocks all Weixin file sends via the send_message tool.

Suggested Fix

The _run_async function's worker-thread path is correctly isolating the coroutine to a fresh loop. The issue likely lies in how the from gateway.platforms.weixin import ... import interacts with module-level singletons or cached objects from the gateway's loop.

A proper fix should ensure that:

  1. No module-level aiohttp.ClientSession, asyncio.Task, or asyncio.Event objects from the gateway loop are referenced when running in the worker thread's loop
  2. Alternatively, lazy-import the weixin module INSIDE the worker thread to avoid pre-existing loop-bound objects

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 - 💡(How to fix) Fix send_message weixin: asyncio 'Future attached to a different loop' bug [1 comments, 2 participants]