Skip to content

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

Closed as not planned

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.

Activity

  1. added
    type/bugSomething isn't working
    P2Medium β€” degraded but workaround exists
    comp/gatewayGateway runner, session dispatch, delivery
    on May 1, 2026
  2. alt-glitch commented on May 1, 2026

    @alt-glitch

    Likely duplicate of #13281 / #17595 β€” same root cause: cross-event-loop aiohttp session reuse in send_weixin_direct(). Fix PRs already open: #14873, #12810.

  3. alt-glitch commented on May 1, 2026

    @alt-glitch

    Likely duplicate of #13281 / #17595 β€” same root cause: cross-event-loop aiohttp session reuse in send_weixin_direct(). Fix PRs already open: #14873, #12810.

  4. teknium1 commented on Jun 10, 2026

    @teknium1
    Collaborator

    This appears to be fixed on current main by the dedicated Weixin cross-loop session guard.

    Automated hermes-sweeper review evidence:

    • gateway/platforms/weixin.py:2286-2290 now only reuses _LIVE_ADAPTERS when the live adapter's _send_session is open and send_session._loop is asyncio.get_running_loop().
    • If that loop check fails, gateway/platforms/weixin.py:2315-2334 falls through to a fresh aiohttp.ClientSession + WeixinAdapter in the calling context, which is the fallback requested in the issue.
    • tools/send_message_tool.py:598-599 routes Weixin send_message calls, including media, through _send_weixin() β†’ send_weixin_direct().
    • The fixing commit is a22465e07ab4b71019f711e7a6463f6590c50742 (fix(weixin): send_weixin_direct cross-loop session check), whose commit message describes the exact reported failure mode: _run_async worker loop plus gateway-owned aiohttp session reuse causing Timeout context manager should be used inside a task.
    • The earliest normal release tag I found containing that commit is v2026.5.7.

    Thanks for the detailed root-cause writeup and timeline; it matches the fix that landed after the reported v2026.4.23 build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions