Skip to content

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

@DhineshPonnarasan

Description

@DhineshPonnarasan

Summary

GatewayBrowserClient in ui/src/ui/gateway.ts uses several raw magic numbers to control WebSocket reconnect behavior. These numbers have no names or comments, making the reconnect logic difficult to understand, tune, or safely modify.

Steps to reproduce

  1. Open ui/src/ui/gateway.ts
  2. Search for backoffMs
  3. Observe raw numbers: 800, 1.7, 15_000, and 750 scattered across the class with no explanation

Expected behavior

Reconnect-related values should be defined as named, documented constants at the top of the file so their purpose is clear and they can be adjusted in one place:

const INITIAL_BACKOFF_MS = 800;
const MAX_BACKOFF_MS = 15_000;
const BACKOFF_MULTIPLIER = 1.7;
const CONNECT_QUEUE_DELAY_MS = 750;

Actual behavior

Raw numbers are hardcoded inline across multiple methods with no documentation:

private backoffMs = 800;
this.backoffMs = Math.min(this.backoffMs * 1.7, 15_000);
this.backoffMs = 800; // reset on success
window.setTimeout(..., 750);

OpenClaw version

2026.2.18

Operating system

Windows 11

Install method

No response

Logs, screenshots, and evidence

Relevant code from ui/src/ui/gateway.ts:

// Line 73 β€” initial value (magic number)
private backoffMs = 800;

// Line 117 β€” backoff growth and cap (magic numbers)
this.backoffMs = Math.min(this.backoffMs * 1.7, 15_000);

// Line 227 β€” reset on successful connect (magic number)
this.backoffMs = 800;

// Line 310 β€” connect queue delay (magic number)
this.connectTimer = window.setTimeout(() => {
  void this.sendConnect();
}, 750);

No crash or functional bug β€” this is a maintainability/readability issue in the source code.


### Impact and severity

_No response_

### Additional information

_No response_

---

I am working on this issue and will submit a PR with the fix shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions