fix(discord): delete orphaned auto-thread seed message on fallback failure - #52423
Open
benbarclay wants to merge 1 commit into
Open
benbarclay wants to merge 1 commit into
benbarclay wants to merge 1 commit into
Conversation
…ilure When auto-threading is rate-limited, _auto_create_thread() posted the 'Thread created by Hermes' announcement before confirming the fallback create_thread() succeeded. On a 429 the announcement was left orphaned and the agent replied inline, so users saw 'Thread created' with no thread behind it. Delete the seed message when the fallback create_thread() fails so the announcement only survives when a real thread exists. Adds tests/gateway/test_discord_auto_thread_orphan_seed.py covering the three paths (fallback-fail deletes seed, fallback-success keeps seed, direct-success posts no seed). Fixes #52422
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-assignment |
1 |
unresolved-import |
1 |
unresolved-attribute |
1 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`
tests/gateway/test_discord_auto_thread_orphan_seed.py:24: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
tests/gateway/test_discord_auto_thread_orphan_seed.py:83: [unresolved-attribute] unresolved-attribute: Module `discord` has no member `MessageType`
✅ Fixed issues (2):
| Rule | Count |
|---|---|
unresolved-attribute |
2 |
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
run_agent.py:2989: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`
Unchanged: 5941 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
tonydwb
approved these changes
Jun 25, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Clean fix for Discord auto-threading. When thread creation fails (commonly a 429 rate-limit), the seed announcement message was left orphaned in the channel. The fix deletes the orphaned seed message so the announcement only survives when a real thread exists.
Looks Good
- Correct initialization of
seed_msg = Nonebefore the try block to handle the variable being potentially unbound in the except handler - Graceful cleanup:
seed_msg.delete()wrapped in its own try/except with debug logging - 143-line test file covers the key scenarios: direct error with fallback success, direct error with fallback failure (orphan cleanup), no seed message to clean
- Minimal diff (2 files, 161 additions)
Reviewed by Hermes Agent (cron)
Open
8 tasks
This was referenced Aug 2, 2026
Open
This was referenced Sep 15, 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
Fixes #52422.
When Discord auto-threading is enabled (
discord.auto_thread: true) and thread creation is rate-limited (HTTP 429),_auto_create_thread()posted the "\U0001f9f5 Thread created by Hermes: ..." announcement to the channel before confirming that the fallbackcreate_thread()succeeded. On a 429 the fallback also failed, the function returnedNone, and the caller responded inline in the main channel \u2014 leaving an orphaned "Thread created" announcement with no thread behind it.Production log for the reported case:
Fix
In the fallback
exceptbranch, delete the seed message ifcreate_thread()then fails, so the announcement only ever survives when a real thread exists. Deletion failures are swallowed atdebuglevel (best-effort cleanup).Test Plan
New
tests/gateway/test_discord_auto_thread_orphan_seed.pycovers three paths:NoneVerified the new test fails against unpatched code (asserts
seed.deleted is True) and passes with the fix. Existingtests/gateway/test_discord_double_dispatch.py(12 tests, same function) stays green.Notes / follow-up
This fixes the immediate user-visible defect (orphaned announcement + inline reply). A larger follow-up would be to back off or suppress auto-threading under sustained 429s rather than retrying per-message; out of scope here.