Skip to content

[Bug] Weixin send_message fails with "Timeout context manager should be used inside a task" #17347

@NickLJing

Description

@NickLJing

Bug Description

在微信平台上调用 send_message 工具发送文件/媒体时,发送逻辑持续失败,报错:

Timeout context manager should be used inside a task

重试 5 次全部失败后消息彻底丢失。有趣的是,普通对话回复路径完全正常,只有 send_message 工具的文件发送路径触发此 bug。

Steps to Reproduce

  1. 在微信平台上使用 Hermes Agent
  2. 让 Agent 执行 send_message 工具发送带 MEDIA 附件的消息(如 .docx 文件)
  3. 观察网关日志

Expected Behavior

文件正常通过微信发送给用户。

Actual Behavior

2026-04-29 16:18:20 WARNING [Weixin] send chunk failed to=o9cq801z attempt=1/5: Timeout context manager should be used inside a task
2026-04-29 16:18:21 WARNING [Weixin] send chunk failed to=o9cq801z attempt=2/5: Timeout context manager should be used inside a task
2026-04-29 16:18:23 WARNING [Weixin] send chunk failed to=o9cq801z attempt=3/5: Timeout context manager should be used inside a task
2026-04-29 16:18:26 WARNING [Weixin] send chunk failed to=o9cq801z attempt=4/5: Timeout context manager should be used inside a task
2026-04-29 16:18:30 ERROR   [Weixin] send failed to=o9cq801z: Timeout context manager should be used inside a task

Analysis

两种发送路径对比:

路径 状态 说明
普通对话回复(response ready → Send to weixin) ✅ 正常 走 session reply pipeline
send_message 工具 → 微信直接发送 ❌ 失败 走独立发送路径

根本原因推断:send_message 的微信适配器代码中使用了 async with timeout() 等异步上下文管理器,但调用上下文不在合法的 asyncio task 中。普通对话回复走的是另一条代码路径,不触发此问题。

Environment

  • OS: Deepin 23 (Linux 6.18.19-amd64-desktop-rolling)
  • Hermes Agent: latest (cnb.cool mirror)
  • Platform: Weixin (微信)
  • Python: 3.12

Related Log Evidence

同一次会话中,此问题反复出现(两次独立的 send_message 调用均失败):

  • 第一次:16:18:20-16:18:30(发送 .docx 需求说明书)
  • 第二次:16:18:35-16:18:45(重试同一文件)

而此前的正常文字对话响应全部成功送达(16:09, 16:19, 16:19 均有正常 reply)

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