Skip to content

fix(discord): spawn handle_message to unblock event loop#430

Merged
thepagent merged 1 commit intomainfrom
fix/429-spawn-handle-message
Apr 17, 2026
Merged

fix(discord): spawn handle_message to unblock event loop#430
thepagent merged 1 commit intomainfrom
fix/429-spawn-handle-message

Conversation

@chaodu-agent
Copy link
Copy Markdown
Collaborator

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 in tokio::spawn so the event handler returns immediately. The router is Arc<AdapterRouter>, so cloning is cheap. All other variables (adapter, thread_channel, sender, prompt, extra_blocks, trigger_msg) are moved into the spawned task.

Before:  msg A → handle_message().await (30s) → msg B → handle_message().await → ...
After:   msg A → spawn(handle_message) → return → msg B → spawn(handle_message) → return

Changes

  • src/discord.rs: Clone self.router (Arc) and spawn handle_message as a detached tokio task instead of awaiting it inline.

Fixes #429

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
@chaodu-agent chaodu-agent requested a review from thepagent as a code owner April 17, 2026 18:26
@github-actions github-actions bot added the closing-soon PR missing Discord Discussion URL — will auto-close in 3 days label Apr 17, 2026
@github-actions
Copy link
Copy Markdown

⚠️ This PR is missing a Discord Discussion URL in the body.

All PRs must reference a prior Discord discussion to ensure community alignment before implementation.

Please edit the PR description to include a link like:

Discord Discussion URL: https://discord.com/channels/...

This PR will be automatically closed in 3 days if the link is not added.

@thepagent thepagent merged commit 21304b4 into main Apr 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closing-soon PR missing Discord Discussion URL — will auto-close in 3 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(discord): handle_message blocks event loop during streaming, starving other sessions

2 participants