Skip to content

UI: replace gateway reconnect magic numbers with constants#31587

Closed
liuxiaopai-ai wants to merge 1 commit intoopenclaw:mainfrom
liuxiaopai-ai:codex/refactor-gateway-reconnect-constants
Closed

UI: replace gateway reconnect magic numbers with constants#31587
liuxiaopai-ai wants to merge 1 commit intoopenclaw:mainfrom
liuxiaopai-ai:codex/refactor-gateway-reconnect-constants

Conversation

@liuxiaopai-ai
Copy link

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: GatewayBrowserClient reconnect flow used inline magic numbers (800, 1.7, 15000, 750) in multiple places.
  • Why it matters: reconnect behavior tuning/review was harder because the same values were repeated without semantic names.
  • What changed: extracted reconnect timing knobs into named constants (INITIAL_RECONNECT_BACKOFF_MS, RECONNECT_BACKOFF_MULTIPLIER, MAX_RECONNECT_BACKOFF_MS, CONNECT_QUEUE_DELAY_MS) and replaced inline literals.
  • What did NOT change (scope boundary): no reconnect algorithm/ordering changes, no protocol changes, no behavior changes.

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:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: local dev checkout
  • Model/provider: N/A
  • Integration/channel (if any): Control UI gateway client
  • Relevant config (redacted): default

Steps

  1. Open ui/src/ui/gateway.ts.
  2. Inspect reconnect queue/backoff code paths (backoffMs init, growth/cap, reset, connect queue delay).
  3. Verify literals are replaced by named constants and references compile.

Expected

  • Reconnect constants are named and centralized.

Actual

  • Constants are now declared once and reused in reconnect logic.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: reconnect code paths now reference named constants only.
  • Edge cases checked: backoff reset after successful connect still uses initial backoff value.
  • What you did not verify: live browser reconnect timing against a running gateway.

Compatibility / Migration

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

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert commit 947609308.
  • Files/config to restore: ui/src/ui/gateway.ts.
  • Known bad symptoms reviewers should watch for: unexpected reconnect delay changes (should not occur; value-only extraction).

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: accidental constant mismatch could alter reconnect cadence.
    • Mitigation: constants preserve original literal values exactly.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

This PR extracts four reconnection timing magic numbers from GatewayBrowserClient into named constants, improving code readability and maintainability.

  • Replaced inline literals 800, 1.7, 15000, 750 with INITIAL_RECONNECT_BACKOFF_MS, RECONNECT_BACKOFF_MULTIPLIER, MAX_RECONNECT_BACKOFF_MS, CONNECT_QUEUE_DELAY_MS
  • All constant values match their original literals exactly
  • Complete replacement across all reconnection code paths (initial backoff, exponential growth, reset after success, connect queue delay)
  • No behavior changes, purely a code quality improvement

Confidence Score: 5/5

  • This PR is safe to merge with no risk - it's a pure refactoring that preserves all original values and behavior
  • Score reflects that this is a straightforward constant extraction with zero functional changes. All magic numbers are replaced correctly with exact value preservation, complete coverage, and semantic naming
  • No files require special attention

Last reviewed commit: 9476093

@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.

@steipete steipete closed this Mar 2, 2026
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