fix(discord): spawn handle_message to unblock event loop#430
Merged
Conversation
Wraps the handle_message() call in tokio::spawn so the serenity event handler returns immediately. This prevents a long-running streaming response from blocking all other incoming Discord messages. Fixes #429
|
All PRs must reference a prior Discord discussion to ensure community alignment before implementation. Please edit the PR description to include a link like: This PR will be automatically closed in 3 days if the link is not added. |
thepagent
approved these changes
Apr 17, 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.
Problem
When one session is streaming a long response, all other incoming Discord messages are blocked until the streaming completes. The serenity event handler awaits
handle_message()directly, which runs the entire streaming loop (30s+) before returning. This serializes all concurrent sessions behind one active response.Reported in #429.
Fix
Wrap the
handle_message()call intokio::spawnso the event handler returns immediately. The router isArc<AdapterRouter>, so cloning is cheap. All other variables (adapter,thread_channel,sender,prompt,extra_blocks,trigger_msg) are moved into the spawned task.Changes
src/discord.rs: Cloneself.router(Arc) and spawnhandle_messageas a detached tokio task instead of awaiting it inline.Fixes #429