Skip to content

fix(discord): prevent duplicate threads on create_thread exception (#73032) - #73092

Open
JonthanaHanh wants to merge 1 commit into
NousResearch:mainfrom
JonthanaHanh:fix/discord-duplicate-thread
Open

fix(discord): prevent duplicate threads on create_thread exception (#73032)#73092
JonthanaHanh wants to merge 1 commit into
NousResearch:mainfrom
JonthanaHanh:fix/discord-duplicate-thread

Conversation

@JonthanaHanh

Copy link
Copy Markdown
Contributor

Fixes #73032. When message.create_thread() succeeds on Discord but raises (timeout/connection reset), fallback path creates a second thread. Added check for message.thread after exception to reuse existing thread instead of creating duplicate. 30 auto-thread tests passed, 1 flaky (pre-existing).

…ousResearch#73032)

When message.create_thread() succeeds on Discord's side but raises an
exception (timeout, connection reset), the fallback path sends a seed
message and creates a second thread. Both threads remain active and can
receive separate agent turns, causing duplicate responses.

Fix: after create_thread() raises, check message.thread for an existing
thread before falling back to the seed message path. If the thread was
already created (API succeeded but response was lost), reuse it instead
of creating a duplicate.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins platform/discord Discord bot adapter labels Jul 28, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for addressing the ambiguous-success path. The underlying defect remains on current main: after a direct-create exception, _auto_create_thread() immediately creates the seed-message fallback (plugins/platforms/discord/adapter.py:6580-6590).

Problems

  • The new getattr(message, "thread", None) guard only covers a pre-populated in-memory thread. The deterministic reproduction attached to [Bug]: Discord auto-thread fallback can create duplicate threads and duplicate agent replies #73032 makes the original thread discoverable through fetch_thread() while leaving message.thread unset, so this change still reaches the fallback.
  • This PR changes only plugins/platforms/discord/adapter.py; current auto-thread coverage at tests/gateway/test_discord_slash_commands.py:407-427 covers successful creation, not ambiguous successful creation followed by an exception.

Suggested changes

  • Reconcile the original starter-message thread through an authoritative/cache-or-fetch path before permitting the seed fallback; avoid creating a second remote side effect while the direct result is ambiguous.
  • Add a regression test for a direct create that commits then raises with no message.thread, asserting no seed send or fallback thread creation, plus a confirmed-absence fallback case.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/discord Discord bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Discord auto-thread fallback can create duplicate threads and duplicate agent replies

3 participants