Skip to content

[Bug] Weixin send_message fails with event-loop errors in non-gateway sessions (v0.11.0)Β #18437

@fubaobao2023

Description

@fubaobao2023

πŸ‘οΈ Bug: Weixin send_message tool fails with event-loop errors in non-gateway sessions

Hermes Version: v0.11.0 (2026.4.23)
Platform: Weixin (Enterprise WeChat / iLink)
Python: 3.11.15
websockets: 15.0.1 (downgraded to 14.0)


Description

The send_message tool (send_document / send_image_file) fails when called from CLI or cron contexts. Gateway text sends work fine, but media sends fail with:

websockets 15.x: Timeout context manager should be used inside a task
websockets 14.x: Future <Future pending> attached to a different loop


Steps to Reproduce

  1. Run hermes weixin
  2. Call send_message with media: action=send, platform=weixin, target=weixin:<chat_id>, message=MEDIA:/path/to/file.png
  3. Tool returns event-loop error; gateway text sends work fine

Root cause: _handle_send() -> _run_async() -> _send_to_platform() -> _send_weixin() -> send_weixin_direct() -> tries to reuse _LIVE_ADAPTERS (gateway WeixinAdapter) running in a different event loop (ThreadPoolExecutor -> asyncio.run() creates a new loop).


Affected Timeline

Date Observation
Apr 28 First Timeout context manager errors in background agents
Apr 30 23:41 Image send succeeded via gateway own session (not tool call)
May 1 Same errors; text OK, media fails
May 1 (ws 14.0) Different error symptom, same root cause

Environment

Hermes Agent v0.11.0 (2026.4.23)
Python: 3.11.15  websockets: 14.0
gateway: weixin connected

Key files:

  • gateway/platforms/weixin.py - send_weixin_direct()
  • tools/send_message_tool.py - _send_to_platform()
  • model_tools.py - _run_async()

Suggested Fix

When _LIVE_ADAPTERS is unavailable or in the wrong loop, send_weixin_direct() should fall back to creating a fresh aiohttp.ClientSession + WeixinAdapter in the calling context, instead of trying to reuse the gateway adapter from a different event loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium β€” degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliveryplatform/wecomWeCom / WeChat Work adaptersweeper:implemented-on-mainSweeper: behavior already present on current maintype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions