Skip to content

fix(weixin): replace aiohttp ClientTimeout with asyncio.wait_for in _api_post/_api_get - #31853

Closed
caojiguang wants to merge 1 commit into
NousResearch:mainfrom
caojiguang:fix/weixin-cron-asyncio-client-timeout
Closed

fix(weixin): replace aiohttp ClientTimeout with asyncio.wait_for in _api_post/_api_get#31853
caojiguang wants to merge 1 commit into
NousResearch:mainfrom
caojiguang:fix/weixin-cron-asyncio-client-timeout

Conversation

@caojiguang

Copy link
Copy Markdown
Contributor

Problem

Cron delivery to WeChat fails with:

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

This happens because _api_post and _api_get use aiohttp's ClientTimeout directly. When the cron scheduler calls send() via asyncio.run_coroutine_threadsafe(), aiohttp cannot find a running task and raises RuntimeError.

Fix

Replace aiohttp.ClientTimeout with asyncio.wait_for() in _api_post and _api_get, following the same pattern already applied to _upload_media, _download_bytes, and _download_remote_media.

The three helper functions above were already fixed to avoid this error (with comments explaining why). _api_post and _api_get were the remaining two iLink API helpers still using the raw ClientTimeout approach.

Notes

  • The _send_session already disables aiohttp timeouts entirely (total=None) to let asyncio.wait_for() manage timeouts externally — this is correct and unchanged.
  • Tested: verified no remaining problematic ClientTimeout usage in weixin.py. Only the intentionally-disabled one on _send_session remains.

…api_post/_api_get

Cron delivery to WeChat fails with 'Timeout context manager should
be used inside a task' because _api_post and _api_get use aiohttp's
ClientTimeout directly.  When the cron scheduler calls send() via
asyncio.run_coroutine_threadsafe(), aiohttp cannot find a running
task and raises RuntimeError.

_upload_media, _download_bytes, and _download_remote_media already
use asyncio.wait_for() to avoid this.  Apply the same pattern to
_api_post and _api_get — the two remaining iLink API helpers that
still use the raw ClientTimeout approach.

This fixes cron delivery errors seen on the WeChat platform adapter
when meyo-external cron jobs attempt to deliver output to WeChat.
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery comp/cron Cron scheduler and job management platform/wecom WeCom / WeChat Work adapter P2 Medium — degraded but workaround exists labels May 25, 2026
@ryan-flow

Copy link
Copy Markdown

Hi @caojiguang, nice fix! I independently found the same issue and wrote a regression test suite (tests/gateway/test_weixin_api_timeout.py) covering cross-event-loop invocation — the exact failure mode here. Happy to open a test-only PR once this merges, or contribute the tests to your branch if you'd like.

banditburai added a commit to banditburai/hermes-agent that referenced this pull request May 30, 2026
The fix commit preserves @caojiguang's authorship (from NousResearch#31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
teknium1 pushed a commit that referenced this pull request Jun 2, 2026
The fix commit preserves @caojiguang's authorship (from #31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
changman pushed a commit to changman/hermes-agent that referenced this pull request Jun 10, 2026
The fix commit preserves @caojiguang's authorship (from NousResearch#31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
alt-glitch pushed a commit that referenced this pull request Jun 14, 2026
The fix commit preserves @caojiguang's authorship (from #31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
kossteg pushed a commit to kossteg/hermes-agent that referenced this pull request Jun 16, 2026
The fix commit preserves @caojiguang's authorship (from NousResearch#31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
The fix commit preserves @caojiguang's authorship (from NousResearch#31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
xyshanren pushed a commit to xyshanren/hermes-agent-cn that referenced this pull request Jun 25, 2026
The fix commit preserves @caojiguang's authorship (from NousResearch#31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
The fix commit preserves @caojiguang's authorship (from NousResearch#31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused Weixin timeout fix. This is already implemented on main by the same contributor commit, so this PR is redundant.

  • Automated hermes-sweeper review verified merged commit 566669013f3f9c0b52cb1392250b76d510d99dc7 (fix(weixin): replace aiohttp ClientTimeout with asyncio.wait_for in _api_post/_api_get), included in v2026.6.5.
  • gateway/platforms/weixin.py:390 and gateway/platforms/weixin.py:414 now enforce the POST and GET deadlines with asyncio.wait_for() rather than forwarding aiohttp.ClientTimeout.
  • The follow-up regression coverage suggested in discussion is present at tests/gateway/test_weixin.py:1106 (commit 765790a216d75440cce69c17abd2356327712863).

@teknium1 teknium1 closed this Jul 13, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 13, 2026
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
The fix commit preserves @caojiguang's authorship (from NousResearch#31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
donbowman pushed a commit to donbowman/hermes-agent that referenced this pull request Jul 13, 2026
The fix commit preserves @caojiguang's authorship (from NousResearch#31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
The fix commit preserves @caojiguang's authorship (from NousResearch#31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
The fix commit preserves @caojiguang's authorship (from NousResearch#31853); the
release-notes AUTHOR_MAP gate requires their email to map to a GitHub
username.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/wecom WeCom / WeChat Work adapter sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants