fix(tools): wrap coroutines in create_task() in _run_async() to fix aiohttp timeout error - #38525
Closed
goodtiding5 wants to merge 1 commit into
Closed
fix(tools): wrap coroutines in create_task() in _run_async() to fix aiohttp timeout error#38525goodtiding5 wants to merge 1 commit into
goodtiding5 wants to merge 1 commit into
Conversation
…iohttp timeout error
Wrap the coroutine in loop.create_task() before passing it to
run_until_complete() in all three code paths of _run_async(). This
ensures asyncio.current_task() returns a valid task, which aiohttp's
TimerContext.__enter__() requires on Python 3.11+.
Without this, when aiohttp creates a TimerContext during an HTTP
request, it calls asyncio.current_task() which returns None because
run_until_complete() schedules the coroutine at the event loop's top
level without creating an asyncio Task. This raises:
RuntimeError: Timeout context manager should be used inside a task
Affects any synchronous tool handler that bridges to async via
_run_async() and uses aiohttp with ClientTimeout — including
send_message for Mattermost, Matrix, Email, SMS, Bluebubbles, QQbot,
HomeAssistant, DingTalk, Feishu, WeCom, and Yuanbao platforms.
The Weixin adapter previously worked around this per-platform
(NousResearch#29037) by disabling aiohttp's ClientTimeout and using
asyncio.wait_for() instead. This fix addresses the root cause,
resolving it for all platforms at once.
Refs: NousResearch#37005 (Mattermost)
This was referenced Jul 28, 2026
Cron delivery to plugin platforms fails: Timeout context manager should be used inside a task
#76799
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wrap the coroutine in
loop.create_task()before passing it torun_until_complete()in all three code paths of_run_async(). This ensuresasyncio.current_task()returns a valid task, which aiohttp'sTimerContext.__enter__()requires on Python 3.11+.Without this, when aiohttp creates a TimerContext during an HTTP request, it calls
asyncio.current_task()which returnsNonebecauserun_until_complete()schedules the coroutine at the event loop's top level without creating an asyncioTask. This raises:Affects any synchronous tool handler that bridges to async via
_run_async()and uses aiohttp withClientTimeout— includingsend_messagefor Mattermost, Matrix, Email, SMS, Bluebubbles, QQbot, HomeAssistant, DingTalk, Feishu, WeCom, and Yuanbao platforms.The Weixin adapter previously worked around this per-platform (#29037) by disabling aiohttp's ClientTimeout and using
asyncio.wait_for()instead. This fix addresses the root cause, resolving it for all platforms at once.Fixes #37005