Repository navigation
fix(discord): replace gateway READY retry fixed backoff with exponential backoff - #104339
bombskyhao wants to merge 4 commits into
Conversation
…ial backoff Discord gateway lifecycle used a fixed 2-second backoff for all READY timeout retries, regardless of failure count. This could create unnecessary gateway pressure and offered no congestion adaptation. Change the backoff strategy to exponential: 2s, 4s, 8s, 16s, then capped at 30s (matching the pattern already used in extensions/browser/chrome-extension/modules/relay-core.js). - Adds getGatewayReconnectDelayMs(attempt) with exponential growth - Replaces DISCORD_GATEWAY_READY_RETRY_BACKOFF_MS with _INITIAL_MS + _MAX_MS constants - First retry behavior is identical (2s); only repeated failures see longer waits
|
Thanks for the contribution. This PR still needs the requested real-behavior proof, and the branch has been idle since that ask. Close this stalled, unproven PR. Its narrow reliability idea remains understandable, but the branch has been unchanged since July 11, 2026, has carried a real-proof request since that date, and still retains the two previously identified lifecycle defects; current main separately merged the abortable retry-sleep repair. So I’m closing this for now to keep the review queue honest. Please reopen or open a fresh PR with real-behavior proof (a live run, logs, or a reproducible validation transcript) and it will be reviewed again. Review detailsBest possible solution: If the reliability policy is still wanted, start from current main, wait with an AbortSignal-aware delay before initiating the next gateway restart, add focused ordering and cancellation coverage, and attach redacted runtime output showing escalating delays and recovery. Do we have a high-confidence way to reproduce the issue? Yes, from source: a READY timeout follows the lifecycle restart path before reaching this PR's new delay, and the branch's timer is not abort-aware. No current-head runtime reproduction was supplied by the contributor. Is this the best way to solve the issue? No. Exponential backoff is a plausible policy, but this implementation waits after starting the replacement gateway and omits cancellation from the longer wait; the merged abort fix on current main is the correct base for any renewed attempt. Security review: Security review cleared: The one-file retry-timing diff adds no dependency, secret, permission, workflow, package-resolution, or supply-chain surface. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 9979ee312d43. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper applied the proposed close for this PR.
|
What Problem This Solves
Discord gateway READY wait retries use a fixed 2-second backoff (
DISCORD_GATEWAY_READY_RETRY_BACKOFF_MS = 2_000). When the gateway is temporarily unstable (e.g. network blips, regional latency, or transient Discord-side issues), the lifecycle loop retries with a constant 2s pause every cycle. This creates two problems:Why This Change Was Made
Exponential backoff is a widely-adopted congestion-control pattern — it starts small (2s) and doubles with each consecutive failure (2s→4s→8s→16s→30s cap). This:
relay-core.js) already uses the same1s→2s→4s→...→30s capstrategy for WebSocket reconnection.Scope: Single file (
extensions/discord/src/monitor/provider.lifecycle.ts), ~12 lines changed. No structural changes — only the backoff strategy.User Impact
Evidence
Test Results
$ pnpm vitest run --config test/vitest/vitest.extension-discord.config.ts \ extensions/discord/src/monitor/provider.lifecycle.test.ts ✓ extension-discord extensions/discord/src/monitor/provider.lifecycle.test.ts (22 tests) 6276ms Test Files 1 passed (1) Tests 22 passed (22)All 22 tests passed — no regressions. The three backoff-sensitive tests were verified to pass under the new exponential schedule:
Manual Verification
relay-core.jsreconnectDelayMsimplementationgetGatewayReconnectDelayMs(0)= 1s,getGatewayReconnectDelayMs(1)= 2s,getGatewayReconnectDelayMs(5)= 30s,getGatewayReconnectDelayMs(99)= 30sAdditional Checks
DISCORD_GATEWAY_READY_RETRY_BACKOFF_MSfully replaced, no remaining references_This PR was created with [AI-assisted] tooling. Code changes were reviewed and validated by the author
Co-authored-by: Codex