Skip to content

UI: extract gateway reconnect magic numbers into named constants#30407

Open
DhineshPonnarasan wants to merge 1 commit intoopenclaw:mainfrom
DhineshPonnarasan:fix/gateway-backoff-constants
Open

UI: extract gateway reconnect magic numbers into named constants#30407
DhineshPonnarasan wants to merge 1 commit intoopenclaw:mainfrom
DhineshPonnarasan:fix/gateway-backoff-constants

Conversation

@DhineshPonnarasan
Copy link

Summary

Replaces raw magic numbers in GatewayBrowserClient reconnect logic with named, JSDoc-documented constants.

Fixes #30402

Changes

ui/src/ui/gateway.ts

  • Extracted 4 magic numbers into exported, documented module-level constants:
    • INITIAL_BACKOFF_MS = 800 — initial delay before first reconnect
    • MAX_BACKOFF_MS = 15_000 — reconnect backoff ceiling
    • BACKOFF_MULTIPLIER = 1.7 — exponential growth factor per attempt
    • CONNECT_QUEUE_DELAY_MS = 750 — grace window for server challenge nonce

Notes

  • No behavior changes — pure readability and maintainability improvement
  • All existing tests pass
  • Format check passes (pnpm check)

Copilot AI review requested due to automatic review settings March 1, 2026 07:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves readability/maintainability of the UI WebSocket reconnect flow by replacing inline “magic numbers” in GatewayBrowserClient with named constants in ui/src/ui/gateway.ts (per #30402).

Changes:

  • Introduces documented module-level constants for reconnect backoff parameters and connect-queue delay.
  • Updates reconnect scheduling and connect-handshake timing to reference the new constants (no behavioral intent).

Comment on lines +69 to +88
export const INITIAL_BACKOFF_MS = 800;

/**
* Reconnect backoff: maximum delay (ms) between reconnect attempts.
* Prevents unbounded growth during prolonged disconnections.
*/
export const MAX_BACKOFF_MS = 15_000;

/**
* Reconnect backoff: exponential growth multiplier applied after each failed attempt.
* e.g. 800 → 1360 → 2312 → ... → capped at MAX_BACKOFF_MS.
*/
export const BACKOFF_MULTIPLIER = 1.7;

/**
* Delay (ms) between WebSocket open and sending the connect handshake.
* Provides a window for the server to send a challenge nonce before the
* client initiates authentication.
*/
export const CONNECT_QUEUE_DELAY_MS = 750;
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These reconnect tuning values are exported, but they appear to be only used internally within this module right now. If they aren’t intended to be part of the module’s supported surface area, consider removing export to avoid growing a de-facto public API (and making future tuning changes harder). If the export is intentional (e.g., for tests/config), it may be worth adding a brief note indicating the intended external consumers.

Suggested change
export const INITIAL_BACKOFF_MS = 800;
/**
* Reconnect backoff: maximum delay (ms) between reconnect attempts.
* Prevents unbounded growth during prolonged disconnections.
*/
export const MAX_BACKOFF_MS = 15_000;
/**
* Reconnect backoff: exponential growth multiplier applied after each failed attempt.
* e.g. 800 1360 2312 ... capped at MAX_BACKOFF_MS.
*/
export const BACKOFF_MULTIPLIER = 1.7;
/**
* Delay (ms) between WebSocket open and sending the connect handshake.
* Provides a window for the server to send a challenge nonce before the
* client initiates authentication.
*/
export const CONNECT_QUEUE_DELAY_MS = 750;
const INITIAL_BACKOFF_MS = 800;
/**
* Reconnect backoff: maximum delay (ms) between reconnect attempts.
* Prevents unbounded growth during prolonged disconnections.
*/
const MAX_BACKOFF_MS = 15_000;
/**
* Reconnect backoff: exponential growth multiplier applied after each failed attempt.
* e.g. 800 1360 2312 ... capped at MAX_BACKOFF_MS.
*/
const BACKOFF_MULTIPLIER = 1.7;
/**
* Delay (ms) between WebSocket open and sending the connect handshake.
* Provides a window for the server to send a challenge nonce before the
* client initiates authentication.
*/
const CONNECT_QUEUE_DELAY_MS = 750;

Copilot uses AI. Check for mistakes.
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 1, 2026

Greptile Summary

Extracted 4 magic numbers from GatewayBrowserClient reconnect logic into well-documented, exported constants (INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, BACKOFF_MULTIPLIER, CONNECT_QUEUE_DELAY_MS).

  • Clean refactoring with zero behavior changes
  • Each constant includes clear JSDoc explaining its purpose
  • All original values preserved exactly (800ms, 15000ms, 1.7x, 750ms)
  • Improves code maintainability and makes reconnect timing configurable

Confidence Score: 5/5

  • This PR is safe to merge with zero risk
  • Perfect refactoring - all magic numbers replaced with identical values, no logic changes, comprehensive documentation, and all existing tests pass
  • No files require special attention

Last reviewed commit: 704d702

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI: Extract magic numbers in GatewayBrowserClient reconnect logic into named constants

2 participants