fix(discord): close old client before reconnect to prevent zombie websockets#18224
Closed
luyao618 wants to merge 1 commit into
Closed
fix(discord): close old client before reconnect to prevent zombie websockets#18224luyao618 wants to merge 1 commit into
luyao618 wants to merge 1 commit into
Conversation
…sockets (NousResearch#18187) When DiscordAdapter.connect() is called during reconnect, it creates a new commands.Bot client without closing the previous one. The old client's websocket remains connected to Discord's gateway, causing both to fire on_message for every incoming event — resulting in double responses. Fix: before creating a new Bot instance, check if a previous client exists and close it. This ensures only one websocket connection is active at any time. Closes NousResearch#18187
teknium1
added a commit
that referenced
this pull request
May 2, 2026
…ect() Covers PR #18224 fix for issue #18187 — when DiscordAdapter.connect() is called a second time without an intervening disconnect(), the previous commands.Bot must be closed before a new one is created. Otherwise both websockets stay connected to Discord's gateway and both fire on_message, producing double responses with different wording.
Contributor
nickdlkk
pushed a commit
to nickdlkk/hermes-agent
that referenced
this pull request
May 11, 2026
…ect() Covers PR NousResearch#18224 fix for issue NousResearch#18187 — when DiscordAdapter.connect() is called a second time without an intervening disconnect(), the previous commands.Bot must be closed before a new one is created. Otherwise both websockets stay connected to Discord's gateway and both fire on_message, producing double responses with different wording.
jsboige
pushed a commit
to jsboige/hermes-agent
that referenced
this pull request
May 14, 2026
…ect() Covers PR NousResearch#18224 fix for issue NousResearch#18187 — when DiscordAdapter.connect() is called a second time without an intervening disconnect(), the previous commands.Bot must be closed before a new one is created. Otherwise both websockets stay connected to Discord's gateway and both fire on_message, producing double responses with different wording.
dannyJ848
pushed a commit
to dannyJ848/hermes-agent
that referenced
this pull request
May 17, 2026
…ect() Covers PR NousResearch#18224 fix for issue NousResearch#18187 — when DiscordAdapter.connect() is called a second time without an intervening disconnect(), the previous commands.Bot must be closed before a new one is created. Otherwise both websockets stay connected to Discord's gateway and both fire on_message, producing double responses with different wording.
gweeteve
pushed a commit
to gweeteve/hermes-agent
that referenced
this pull request
Jun 2, 2026
…ect() Covers PR NousResearch#18224 fix for issue NousResearch#18187 — when DiscordAdapter.connect() is called a second time without an intervening disconnect(), the previous commands.Bot must be closed before a new one is created. Otherwise both websockets stay connected to Discord's gateway and both fire on_message, producing double responses with different wording.
Egavasyug
pushed a commit
to Egavasyug/hermes-agent
that referenced
this pull request
Jun 10, 2026
…ect() Covers PR NousResearch#18224 fix for issue NousResearch#18187 — when DiscordAdapter.connect() is called a second time without an intervening disconnect(), the previous commands.Bot must be closed before a new one is created. Otherwise both websockets stay connected to Discord's gateway and both fire on_message, producing double responses with different wording.
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 #18187 — Discord adapter creates zombie websocket connection on reconnect, causing double responses.
Problem
When
DiscordAdapter.connect()is called during a reconnect cycle (e.g. gateway restart), it unconditionally creates a newcommands.Botclient without closing the previous one. The old client's websocket remains connected to Discord's gateway, so both clients fireon_messagefor every incoming event — resulting in double responses with different wording.The existing
MessageDeduplicatorcannot prevent this because the two websockets deliver events independently, and the twoon_messagecoroutines race on the dedup check.Fix
Before creating a new
Botinstance inconnect(), check if a previous client exists and close it:This ensures only one Discord websocket connection is ever active for the adapter.
Scope
gateway/platforms/discord.py(+15 lines)Testing
python -m pytest tests/tools/test_discord_tool.py tests/gateway/ -k discord # 375 passed, 1 skipped