fix(gateway): offload channel directory session scans off the event loop#60984
Merged
Conversation
2 tasks
13d0769 to
94e974e
Compare
This was referenced Jul 9, 2026
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
Channel directory builds no longer block the gateway event loop. Salvages PR #60810 by @embwl0x (earliest and most complete of three competing fixes; #60840 by @AlexFucuson9 and #60919 by @AIalliAI closed as duplicates with credit).
Root cause:
build_channel_directory()is async and runs on the gateway event loop, but_build_discord()(guild/channel cache walk) and_build_from_sessions()(synchronous SQLite SessionDB scans) were called inline — on large session databases this stalls message delivery for every connected platform.Changes
gateway/channel_directory.py: wrap all five blocking builder call sites inasyncio.to_thread— the Discord cache walk, session-based discovery, plugin-platform discovery, and both_build_from_sessions("slack")merges inside_build_slack()(the two sites the duplicate PRs missed).tests/gateway/test_channel_directory.py: thread-identity regression tests asserting the builders never run on the loop thread (+80 LOC).scripts/release.py: AUTHOR_MAP entry for @embwl0x.Validation
Contributor authorship preserved via cherry-pick; merge with rebase.
Infographic