hermes - ✅(Solved) Fix Weixin: Voice send fails - asyncio Task attached to different loop [1 pull requests, 3 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#13365Fetched 2026-04-22 08:06:50
View on GitHub
Comments
3
Participants
3
Timeline
9
Reactions
0
Timeline (top)
labeled ×5commented ×3cross-referenced ×1

Voice messages fail to send via Weixin platform with multiple issues: asyncio error: Task attached to a different loop when sending voice bubbles Token expiration: ret=-2 errmsg=unknown error indicates session timeout Gateway instability: Frequent restarts cause cron jobs to miss scheduled times Error Logs 2026-04-21 08:31:27 WARNING: Task <Task pending name='Task-102' coro=<_api_post.<locals>._do_post() running at gateway/platforms/weixin.py:367>> got Future attached to a different loop 2026-04-21 08:31:30 ERROR: [Weixin] send failed: Task attached to a different loop 2026-04-21 08:31:25 ERROR: [Weixin] send failed: iLink ilink/bot/sendmessage error: ret=-2 errmsg=unknown error Affected Code gateway/platforms/weixin.py:367 - _api_post function gateway/platforms/weixin.py:2133 - ClientTimeout usage in non-task context Environment Platform: Weixin/WeChat via iLink API Python: 3.11.15 Running in WSL2 on Windows TTS provider: gtts (generates mp3, converted to SILK) Steps to Reproduce Setup Weixin platform with hermes gateway setup Send voice message via text_to_speech tool Message conversion to SILK succeeds but sending fails Expected Behavior Voice messages should be delivered as native WeChat voice bubbles. Actual Behavior SILK conversion works Sending fails with asyncio error or token expiration Messages never reach the recipient Additional Context Tried fixing ClientTimeout with asyncio.wait_for() wrapper Token validity is 4-7 days but session expires unpredictably Gateway restarts frequently, missing cron job schedules

Error Message

asyncio error: Task attached to a different loop when sending voice bubbles Token expiration: ret=-2 errmsg=unknown error indicates session timeout Error Logs 2026-04-21 08:31:30 ERROR: [Weixin] send failed: Task attached to a different loop 2026-04-21 08:31:25 ERROR: [Weixin] send failed: iLink ilink/bot/sendmessage error: ret=-2 errmsg=unknown error Sending fails with asyncio error or token expiration

Root Cause

Voice messages fail to send via Weixin platform with multiple issues: asyncio error: Task attached to a different loop when sending voice bubbles Token expiration: ret=-2 errmsg=unknown error indicates session timeout Gateway instability: Frequent restarts cause cron jobs to miss scheduled times Error Logs 2026-04-21 08:31:27 WARNING: Task <Task pending name='Task-102' coro=<_api_post.<locals>._do_post() running at gateway/platforms/weixin.py:367>> got Future attached to a different loop 2026-04-21 08:31:30 ERROR: [Weixin] send failed: Task attached to a different loop 2026-04-21 08:31:25 ERROR: [Weixin] send failed: iLink ilink/bot/sendmessage error: ret=-2 errmsg=unknown error Affected Code gateway/platforms/weixin.py:367 - _api_post function gateway/platforms/weixin.py:2133 - ClientTimeout usage in non-task context Environment Platform: Weixin/WeChat via iLink API Python: 3.11.15 Running in WSL2 on Windows TTS provider: gtts (generates mp3, converted to SILK) Steps to Reproduce Setup Weixin platform with hermes gateway setup Send voice message via text_to_speech tool Message conversion to SILK succeeds but sending fails Expected Behavior Voice messages should be delivered as native WeChat voice bubbles. Actual Behavior SILK conversion works Sending fails with asyncio error or token expiration Messages never reach the recipient Additional Context Tried fixing ClientTimeout with asyncio.wait_for() wrapper Token validity is 4-7 days but session expires unpredictably Gateway restarts frequently, missing cron job schedules

Fix Action

Fixed

PR fix notes

PR #13419: fix: resolve asyncio event loop issue in weixin voice send (fixes #13365)

Description (problem / solution / changelog)

Problem

Weixin voice send fails with "asyncio Task attached to different loop" error (#13365).

Root Cause

aiohttp.ClientSession created in one event loop is used in another loop when gateway restarts or cron jobs run in different threads.

Fix

  • Added RuntimeError catch for 'attached to a different loop' in _api_post, _api_get, _upload_ciphertext, _download_remote_media
  • Creates new aiohttp.ClientSession in current event loop when error is detected and retries the request
  • Added unit tests for event loop handling

Testing

  • 44 tests passed including 2 new tests for event loop handling
  • Syntax validation passed

Files Changed

  • gateway/platforms/weixin.py
  • tests/gateway/test_weixin.py

Changed files

  • gateway/platforms/weixin.py (modified, +623/-149)
  • tests/gateway/test_weixin.py (modified, +344/-24)
RAW_BUFFERClick to expand / collapse

Description Voice messages fail to send via Weixin platform with multiple issues: asyncio error: Task attached to a different loop when sending voice bubbles Token expiration: ret=-2 errmsg=unknown error indicates session timeout Gateway instability: Frequent restarts cause cron jobs to miss scheduled times Error Logs 2026-04-21 08:31:27 WARNING: Task <Task pending name='Task-102' coro=<_api_post.<locals>._do_post() running at gateway/platforms/weixin.py:367>> got Future attached to a different loop 2026-04-21 08:31:30 ERROR: [Weixin] send failed: Task attached to a different loop 2026-04-21 08:31:25 ERROR: [Weixin] send failed: iLink ilink/bot/sendmessage error: ret=-2 errmsg=unknown error Affected Code gateway/platforms/weixin.py:367 - _api_post function gateway/platforms/weixin.py:2133 - ClientTimeout usage in non-task context Environment Platform: Weixin/WeChat via iLink API Python: 3.11.15 Running in WSL2 on Windows TTS provider: gtts (generates mp3, converted to SILK) Steps to Reproduce Setup Weixin platform with hermes gateway setup Send voice message via text_to_speech tool Message conversion to SILK succeeds but sending fails Expected Behavior Voice messages should be delivered as native WeChat voice bubbles. Actual Behavior SILK conversion works Sending fails with asyncio error or token expiration Messages never reach the recipient Additional Context Tried fixing ClientTimeout with asyncio.wait_for() wrapper Token validity is 4-7 days but session expires unpredictably Gateway restarts frequently, missing cron job schedules

extent analysis

TL;DR

The most likely fix involves addressing the asyncio error by ensuring tasks are attached to the correct event loop, potentially by using asyncio.run() or loop.create_task().

Guidance

  • Verify that the _api_post function in weixin.py is properly handling asynchronous tasks and ensure it's using the correct event loop.
  • Check the usage of ClientTimeout in weixin.py:2133 to ensure it's being used within a task context to avoid conflicts with asyncio.
  • Investigate the gateway instability and frequent restarts causing cron jobs to miss scheduled times, as this might be contributing to the token expiration issues.
  • Consider implementing a retry mechanism for sending voice messages to handle temporary failures due to token expiration or gateway instability.

Example

import asyncio

# Ensure tasks are attached to the correct event loop
loop = asyncio.get_event_loop()
loop.create_task(_api_post())

Notes

The provided information suggests that there are multiple issues at play, including asyncio errors, token expiration, and gateway instability. Addressing these issues may require a combination of code changes and infrastructure adjustments.

Recommendation

Apply a workaround by implementing a retry mechanism for sending voice messages and ensuring tasks are attached to the correct event loop, as this can help mitigate the immediate issues while a more permanent fix is developed.

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