hermes - 💡(How to fix) Fix fix(weixin): replace aiohttp ClientTimeout with asyncio.wait_for() [1 comments, 2 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#29037Fetched 2026-05-20 04:00:27
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Author
Participants
Timeline (top)
labeled ×4closed ×1commented ×1cross-referenced ×1

Error Message

The timeout= argument to session.post() requires an active asyncio task context. When called via asyncio.run_coroutine_threadsafe() from cron jobs (which run in concurrent.futures.ThreadPoolExecutor), there is no asyncio task context — triggering the error.

Root Cause

Root Cause

RAW_BUFFERClick to expand / collapse

When sending files (documents, images, videos) via the WeChat gateway from a cron job or any background thread, the operation fails with:

Timeout context manager should be used inside a task


Root Cause

_api_post and _api_get in gateway/platforms/weixin.py use aiohttp.ClientTimeout as a context manager passed directly to session.post/get():

python
timeout = aiohttp.ClientTimeout(total=timeout_ms / 1000)
async with session.post(url, data=body, headers=..., timeout=timeout) as response:


The timeout= argument to session.post() requires an active asyncio task context. When called via asyncio.run_coroutine_threadsafe() from cron jobs (which run in concurrent.futures.ThreadPoolExecutor), there is no asyncio task context — triggering the error.

Note that _upload_ciphertext (line ~579) and _download_bytes (line ~595) already use asyncio.wait_for() for this reason — the same fix was never applied to _api_post and _api_get.

Fix

Replace aiohttp.ClientTimeout with asyncio.wait_for() for both functions, matching the existing pattern:

python
async def _do_post() -> Dict[str, Any]:
    async with session.post(url, data=body, headers=_headers(token, body)) as response:
        raw = await response.text()
        if not response.ok:
            raise RuntimeError(f"iLink POST {endpoint} HTTP {response.status}: {raw[:200]}")
        return json.loads(raw)

Use asyncio.wait_for() instead of aiohttp ClientTimeout to avoid
"Timeout context manager should be used inside a task" errors when
invoked via asyncio.run_coroutine_threadsafe() from cron jobs.
return await asyncio.wait_for(_do_post(), timeout=timeout_ms / 1000)


Same pattern applied to _api_get.

Files Changed

- gateway/platforms/weixin.py: _api_post and _api_get — ~23 lines changed

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

hermes - 💡(How to fix) Fix fix(weixin): replace aiohttp ClientTimeout with asyncio.wait_for() [1 comments, 2 participants]