fix(discord): use gateway event loop for approval box coroutines (#74470) - #74493
Closed
webtecnica wants to merge 4 commits into
Closed
fix(discord): use gateway event loop for approval box coroutines (#74470)#74493webtecnica wants to merge 4 commits into
webtecnica wants to merge 4 commits into
Conversation
When a desktop zone (e.g. terminal panel) is minimized/collapsed, the header collapse button now shows chevron-up instead of chevron-down. Chevron-down indicates 'click to collapse' (expanded state), while chevron-up indicates 'click to restore' (collapsed state). Fixes NousResearch#74006
…sResearch#74470) The discord.py client's aiohttp session is bound to the gateway event loop. Previously, sync tool-handler contexts scheduled adapter coroutines through model_tools._run_async(), which creates a private/per-worker event loop — causing aiohttp to reject with "Timeout context manager should be used inside a task". Fix: - Add _gateway_loop attribute to BasePlatformAdapter, set by the gateway runner alongside gateway_runner so every adapter knows its owning loop. - Add DiscordAdapter._run_coro_on_loop() helper that schedules coroutines on the stored gateway loop via asyncio.run_coroutine_threadsafe (thread-safe, preserves session binding), falling back to _run_async() for standalone/cron contexts. - Gateway runner injects _gateway_loop at all three adapter-creation sites. Regression tests prove: 1. With _gateway_loop set, the coroutine runs on the correct loop. 2. _run_async is never called when the gateway loop is available. 3. Without _gateway_loop, the helper falls back to _run_async. 4. Existing three-control render tests pass unchanged.
Collaborator
Duplicate of cleaner focused #74471 for the Discord approval-box gateway-loop repair. This branch also carries unrelated agent, Desktop, and Himalaya changes that should not be merged with that fix. |
Contributor
|
Thanks for the report and the focused regression investigation. This automated hermes-sweeper review found that the requested gateway-loop behavior is already implemented on current
Closing as implemented on main. |
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.
Summary
Fixes #74470 — Discord approval boxes were using the wrong asyncio event loop, causing
Timeout context manager should be used inside a taskfrom aiohttp.Root Cause
The discord.py client's
aiohttpsession is bound to the gateway event loop. Sync tool-handler contexts were scheduling adapter coroutines throughmodel_tools._run_async(), which creates a private/per-worker event loop. Whenchannel.send()tried to use the aiohttp session from the wrong loop, it raised"Timeout context manager should be used inside a task".Changes
gateway/platforms/base.py_gateway_loopclass attribute toBasePlatformAdapter(analogous togateway_runner) so every adapter can know its owning event loop.gateway/run.py_gateway_loopalongsidegateway_runnerat all three adapter-creation sites (plugin-registered platforms, APIServerAdapter, WebhookAdapter).plugins/platforms/discord/adapter.pyself._gateway_looptoDiscordAdapter.__init__()._run_coro_on_loop()helper that schedules coroutines on the stored gateway loop viaasyncio.run_coroutine_threadsafe(thread-safe, preserves aiohttp session binding). Falls back to_run_async()when no gateway loop is available (standalone/cron).tests/gateway/test_discord_exec_approval_content.pytest_run_coro_on_loop_uses_gateway_loop— proves coroutines run on the correct loop and_run_asyncis NOT called when the gateway loop is available.test_run_coro_on_loop_falls_back_to_run_async_without_gateway_loop— proves the helper falls back gracefully for standalone contexts.Testing
_run_asyncis bypassed when the gateway loop is available.