Bug Description
When a cron job attempts to deliver a message to WeChat (Weixin), it fails with the following error:
Timeout context manager should be used inside a task
Root Cause
In weixin.py, the send_weixin_direct() function creates an aiohttp.ClientSession that gets reused across different event loops. When a cron job runs in a new session with a different event loop, the existing session (tied to the old loop) becomes invalid, causing the timeout context manager error.
Proposed Fix
Add an event loop consistency check in send_weixin_direct(). When the current event loop doesn't match the session's loop, create a new session instead of reusing the existing one.
# Before (pseudocode)
if session is None:
session = aiohttp.ClientSession()
# use session...
# After (pseudocode)
current_loop = asyncio.get_event_loop()
if session is None or session._loop is not current_loop:
if session and not session.closed:
await session.close()
session = aiohttp.ClientSession()
# use session...
Steps to Reproduce
- Configure WeChat as a delivery target in
config.yaml
- Create a cron job with
deliver: weixin
- Wait for the cron job to execute
- Observe the error in logs
Environment
- Hermes Agent version: latest (as of 2026-04)
- Delivery target: WeChat (Weixin)
- Trigger: Cron job scheduled delivery
Impact
All cron jobs with WeChat delivery fail silently. Other delivery targets (Feishu, Telegram, etc.) are not affected.
Bug Description
When a cron job attempts to deliver a message to WeChat (Weixin), it fails with the following error:
Root Cause
In
weixin.py, thesend_weixin_direct()function creates anaiohttp.ClientSessionthat gets reused across different event loops. When a cron job runs in a new session with a different event loop, the existing session (tied to the old loop) becomes invalid, causing the timeout context manager error.Proposed Fix
Add an event loop consistency check in
send_weixin_direct(). When the current event loop doesn't match the session's loop, create a new session instead of reusing the existing one.Steps to Reproduce
config.yamldeliver: weixinEnvironment
Impact
All cron jobs with WeChat delivery fail silently. Other delivery targets (Feishu, Telegram, etc.) are not affected.