fix(discord): force fresh gateway reconnects#54697
Conversation
Greptile SummaryThis PR fixes a race condition in the Discord gateway reconnect path where Carbon's socket
Confidence Score: 4/5
Reviews (1): Last reviewed commit: "fix(discord): force fresh gateway reconn..." | Re-trigger Greptile |
f2ac744 to
02e02d9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02e02d908d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Addressed both review items in
Validation:
Also rolled this updated branch build onto the mac-mini (
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Addressed the latest Aisle comment in What changed:
Validation:
Also updated the mac-mini branch install to this exact commit and verified:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca558d8f05
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Addressed the latest Codex + Aisle feedback in What changed:
Regression coverage:
Validation:
mac-mini branch install is also updated to this exact commit and verified:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 391db13c4c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Addressed the latest Codex comment in What changed:
Validation:
mac-mini branch install is updated to this exact commit and verified:
|
d2fa229 to
85967ca
Compare
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
Vulnerabilities1. 🟡 Denial of Service: gateway lifecycle force-stops if old WebSocket never emits "close" during reconnect
DescriptionThe new reconnect path introduces a fail-closed behavior in
This creates an availability risk: a network condition or gateway behavior that prevents the Vulnerable flow:
Vulnerable code: terminateCloseTimeout = setTimeout(() => {
...
rejectClose(new Error(
`discord gateway socket did not close within ${DISCORD_GATEWAY_DISCONNECT_DRAIN_TIMEOUT_MS}ms before reconnect`,
));
}, DISCORD_GATEWAY_FORCE_TERMINATE_CLOSE_TIMEOUT_MS);and in the HELLO timeout restart path: await reconnectGateway({ resume: true });
...
} catch (err) {
...
triggerForceStop(err);
}RecommendationAvoid turning an inability-to-observe Recommended hardening options (choose one or combine):
// After terminate timeout, proceed with reconnect but mark old socket as abandoned
// and keep suppressing its error events.
resolve();
The goal is to keep the monitor self-healing under adverse network conditions, reserving Analyzed PR: #54697 at commit Last updated on: 2026-03-26T10:08:07Z |
|
Landed via temp rebase onto main.
Thanks @ngutman! |
* fix(discord): force fresh gateway reconnects * fix(discord): harden forced reconnect teardown * fix(discord): retry after socket drain timeouts * fix(discord): guard forced socket teardown * fix(discord): stop cleanly during reconnect drain
Summary
Describe the problem and fix in 2–5 bullets:
Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
For bug fixes or regressions, explain why this happened, not just what changed. Otherwise write
N/A. If the cause is unclear, writeUnknown.disconnect()+connect(false)for forced reconnects, but Carbon still lets the old socket'sclosehandler trigger its own reconnect path and will still send RESUME on HELLO when resume state is cached.connect(false)alone guaranteed a fresh IDENTIFY.git blame, prior PR, issue, or refactor if known): existing lifecycle guards already handled HELLO stalls and startup-not-ready timeouts, but they still relied on Carbon's socket lifecycle underneath.FailoverErrorhandling; the reproduced failure mechanism was in Discord gateway reconnect sequencing.Regression Test Plan (if applicable)
For bug fixes or regressions, name the smallest reliable test coverage that should have caught this. Otherwise write
N/A.extensions/discord/src/monitor/provider.lifecycle.test.tsUser-visible / Behavior Changes
List user-visible changes (including defaults/config).
If none, write
None.Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
Steps
Expected
Actual
Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
pnpm buildandpnpm check.Review Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoFailure Recovery (if this breaks)
extensions/discord/src/monitor/provider.lifecycle.ts.extensions/discord/src/monitor/provider.lifecycle.ts,extensions/discord/src/monitor/provider.lifecycle.test.tsRisks and Mitigations
List only real risks for this PR. Add/remove entries as needed. If none, write
None.