Skip to content

UI: extract magic numbers in GatewayBrowserClient reconnect logic into named constants (#30402)#30498

Closed
chengzhichao-xydt wants to merge 1 commit intoopenclaw:mainfrom
chengzhichao-xydt:fix/30402-extract-gateway-magic-numbers
Closed

UI: extract magic numbers in GatewayBrowserClient reconnect logic into named constants (#30402)#30498
chengzhichao-xydt wants to merge 1 commit intoopenclaw:mainfrom
chengzhichao-xydt:fix/30402-extract-gateway-magic-numbers

Conversation

@chengzhichao-xydt
Copy link
Contributor

…o named constants (#30402)

Summary

  • Problem: GatewayBrowserClient uses raw magic numbers (800, 1.7, 15_000, 750) for WebSocket reconnect logic, with no names or comments.
  • Why it matters: Magic numbers make the logic harder to read, tune, and maintain, and increase the risk of mistakes.
  • What changed: Replaced these values with named constants (INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, BACKOFF_MULTIPLIER, CONNECT_QUEUE_DELAY_MS) and added JSDoc comments.
  • What did NOT change (scope boundary): Reconnect behavior, timing, and backoff logic are unchanged; only code structure was improved.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

None.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Any
  • Runtime/container: Browser
  • Model/provider: N/A
  • Integration/channel (if any): Web control UI
  • Relevant config (redacted): N/A

Steps

  1. Open ui/src/ui/gateway.ts
  2. Confirm all reconnect-related values use named constants
  3. Run pnpm build and pnpm check; both pass

Expected

  • Build and checks pass
  • Reconnect behavior unchanged from before

Actual

  • Matches expected

Evidence

  • No new failing tests; behavior unchanged; existing tests still pass
  • Code diff shows constant extraction and replacement

Human Verification (required)

  • Verified scenarios: Constants defined correctly, all usages updated, JSDoc added
  • Edge cases checked: Numeric values unchanged; behavior equivalent
  • What you did NOT verify: No long-running real-world reconnect validation

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No
  • If yes, exact upgrade steps: N/A

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: git revert <commit>
  • Files/config to restore: ui/src/ui/gateway.ts
  • Known bad symptoms reviewers should watch for: None

Risks and Mitigations

None.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 1, 2026

Greptile Summary

Clean refactoring that extracts WebSocket reconnect magic numbers into well-named constants with JSDoc comments. All four values (INITIAL_BACKOFF_MS, MAX_BACKOFF_MS, BACKOFF_MULTIPLIER, CONNECT_QUEUE_DELAY_MS) are correctly defined and replaced throughout the file.

  • Improved code readability and maintainability
  • No behavioral changes - reconnect logic remains identical
  • All numeric values preserved exactly (800ms, 15_000ms, 1.7x, 750ms)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a straightforward refactoring with no logic changes.
  • Perfect constant extraction refactoring: all magic numbers correctly replaced with descriptive constants, no behavioral changes, values preserved exactly, and improved maintainability. Zero risk to existing functionality.
  • No files require special attention.

Last reviewed commit: 619323c

@steipete
Copy link
Contributor

steipete commented Mar 2, 2026

Thanks for the PR! Multiple PRs address the same gateway reconnect magic-numbers refactor (#30407, #30414, #30435, #30498, #31587). Keeping #30407 as the earliest submission. Closing this one to reduce noise. This is an AI-assisted triage review. If we got this wrong, feel free to reopen or start a new PR — happy to revisit.

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