hermes - ✅(Solved) Fix [Bug]: WeChat send_message causes "Timeout context manager should be used inside a task" error [1 pull requests]

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…

Error Message

This error occurs consistently when attempting to send any message to WeChat, regardless of message content or recipient. The asyncio.timeout() context manager is being called outside of an async task context.

  • #12154 (similar error pattern, different aspect of WeChat integration)
  1. Observe the error in logs/response Error: "Timeout context manager should be used inside a task"

Additional Logs / Traceback (optional)

Root Cause

Root Cause Analysis (optional)

PR fix notes

PR #13520: fix(weixin): avoid cross-loop live session reuse

Description (problem / solution / changelog)

Summary

  • only reuse the live Weixin adapter when its aiohttp send session belongs to the current event loop
  • fall back to a temporary session for sync bridges like send_message and cron delivery
  • add a regression test that covers the foreign-loop live adapter path

Closes #13099

Testing

  • pytest -o addopts='' tests/gateway/test_weixin.py

Changed files

  • gateway/platforms/weixin.py (modified, +328/-86)
  • tests/gateway/test_weixin.py (modified, +319/-24)

Code Example

2026-04-20 10:00:53,891 INFO agent.auxiliary_client: Vision auto-detect: using main provider alibaba-sub (qwen3.6-plus)
2026-04-20 10:00:54,511 INFO agent.auxiliary_client: Auxiliary auto-detect: using main provider custom (qwen3.6-plus)
2026-04-20 10:08:28,370 INFO gateway.run: Stopping gateway for restart...
2026-04-20 10:08:28,372 INFO gateway.platforms.feishu: [Feishu] Disconnected
2026-04-20 10:08:28,372 INFO gateway.run: ✓ feishu disconnected
2026-04-20 10:08:28,374 INFO gateway.platforms.weixin: [Weixin] Disconnected
2026-04-20 10:08:28,374 INFO gateway.run: ✓ weixin disconnected
2026-04-20 10:08:28,375 INFO gateway.run: Gateway stopped

---
RAW_BUFFERClick to expand / collapse

Bug Description

I added a scheduled reminder task to send a notification via WeChat, but when the reminder is triggered, the gateway exits and cannot be automatically restarted; it can only be restarted manually.

  • Hermes Agent v0.10.x
  • Python 3.11
  • Platform: WeChat via iLink Bot API

When calling send_message with target=weixin, the message fails to send and throws:

Weixin send failed: Timeout context manager should be used inside a task

This error occurs consistently when attempting to send any message to WeChat, regardless of message content or recipient. The asyncio.timeout() context manager is being called outside of an async task context.

  • #12154 (similar error pattern, different aspect of WeChat integration)

Steps to Reproduce

  1. Connect WeChat account to Hermes
  2. Send a message via send_message to a WeChat target (e.g., send_message(target="weixin", message="test"))
  3. Observe the error in logs/response

Expected Behavior

Messages should be sent successfully to WeChat without asyncio context errors.

Actual Behavior

Error: "Timeout context manager should be used inside a task"

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform (if gateway-related)

N/A (CLI only)

Debug Report

2026-04-20 10:00:53,891 INFO agent.auxiliary_client: Vision auto-detect: using main provider alibaba-sub (qwen3.6-plus)
2026-04-20 10:00:54,511 INFO agent.auxiliary_client: Auxiliary auto-detect: using main provider custom (qwen3.6-plus)
2026-04-20 10:08:28,370 INFO gateway.run: Stopping gateway for restart...
2026-04-20 10:08:28,372 INFO gateway.platforms.feishu: [Feishu] Disconnected
2026-04-20 10:08:28,372 INFO gateway.run: ✓ feishu disconnected
2026-04-20 10:08:28,374 INFO gateway.platforms.weixin: [Weixin] Disconnected
2026-04-20 10:08:28,374 INFO gateway.run: ✓ weixin disconnected
2026-04-20 10:08:28,375 INFO gateway.run: Gateway stopped

Operating System

MacOS 25.4.0

Python Version

Python: 3.11.15

Hermes Version

Hermes Agent v0.10.0 (2026.4.16)

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

果然复现了!微信发送失败,错误信息: Timeout context manager should be used inside a task 这是一个异步上下文的问题——微信发送功能需要在内置 task 中调用,不能直接在外层使用 send_message。这可能就是之前会话中断的原因。 结论:微信通道存在 bug,直接调用 send_message 到微信会抛出异常。这个问题需要修复微信的发送逻辑,让它在非异步上下文中也能正常工作。

Proposed Fix (optional)

No response

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

extent analysis

TL;DR

The most likely fix is to ensure the send_message function with target=weixin is called within an async task context to resolve the asyncio timeout context manager issue.

Guidance

  • Review the send_message function to verify it is properly wrapped in an async context when sending messages to WeChat.
  • Check if the Hermes Agent's WeChat integration documentation provides guidance on using async tasks for sending messages.
  • Consider modifying the code to use an async task context manager, such as asyncio.create_task() or asyncio.run(), when calling send_message with target=weixin.
  • Investigate if there are existing fixes or workarounds in the Hermes Agent version or in related issues like #12154.

Example

import asyncio

async def send_wechat_message(message):
    # Assuming send_message is an async function
    await send_message(target="weixin", message=message)

# Usage
async def main():
    await send_wechat_message("test")

asyncio.run(main())

Notes

The provided debug report and logs do not directly point to the issue but indicate a problem with the WeChat integration. The root cause analysis suggests a bug in the WeChat sending logic that needs to be fixed to work outside an async context.

Recommendation

Apply a workaround by ensuring all WeChat message sends are executed within an async task context until a proper fix is implemented for the Hermes Agent's WeChat integration.

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