fix: reconnect Discord gateway on silent WS disconnect#791
Open
chaodu-agent wants to merge 2 commits into
Open
fix: reconnect Discord gateway on silent WS disconnect#791chaodu-agent wants to merge 2 commits into
chaodu-agent wants to merge 2 commits into
Conversation
When serenity's client.start() returns (either Ok or transient error), the Discord adapter now automatically reconnects with exponential backoff instead of silently dying. - Wrap client build + start in a retry loop - Fatal errors (bad token, bad intents) still exit immediately - Transient errors use exponential backoff (1s → 60s max) - Successful sessions reset backoff to 1s - Graceful shutdown via shutdown_rx breaks the loop - Log reconnect attempts at WARN level for observability Fixes #790
…mulation, F3 backoff logic) - F1 (🔴): Wrap Client::builder().await in match to retry on transient build failures instead of crashing main with ? - F2 (🟡): Abort shutdown listener task after client.start() returns to prevent task accumulation across reconnect iterations - F3 (🟡): Move backoff escalation into Err arm only; Ok path resets to 1s and does not escalate
Collaborator
Author
|
LGTM ✅ — Solid reconnect loop with correct backoff semantics and clean shutdown handling. What This PR DoesWhen serenity's How It WorksWraps the Discord client lifecycle in a Findings
Baseline Check
What's Good (🟢)
|
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 #790 — Discord gateway silently dies after WS disconnect with no reconnect.
Problem
When serenity's
client.start()returnsOk(())(internal reconnect exhausted), the Discord adapter permanently stops receiving events while the container remains "healthy".Changes
Wraps the Discord client lifecycle in a reconnect loop with exponential backoff:
client.start()returningOk(())or transient errors triggers a reconnect attemptDisallowedGatewayIntentsandInvalidAuthenticationstill callprocess::exit(1)shutdown_rxsignal (SIGINT/SIGTERM)How it works
Handler is rebuilt each iteration — all shared state (
router,dispatcher) isArc-wrapped so cloning is cheap. Thread-local caches (participated_threads,multibot_threads) are fresh per reconnect, which is correct since Discord will re-dispatch theREADYevent.Testing
Not included (future work)
https://discord.com/channels/1491295327620169908/1491365157010542652/1503355477612957696