openclaw - 💡(How to fix) Fix [Feature]: Control UI should auto-reconnect after gateway restart [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#56299Fetched 2026-04-08 01:42:35
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

With the current stale-socket regression (#55346), our gateway has restarted 28 times today. Each restart kicks the user out of the control UI to the login page, even though the gateway is back within seconds. A simple WebSocket reconnect would eliminate this friction entirely.

Error Message

When the gateway restarts (either planned or due to a crash like #55346), the control UI's WebSocket connection drops. The user is immediately redirected to the login page, followed by a 502 error while the gateway is still booting. After a few seconds they can refresh and log back in, but this is disruptive — especially when restarts are frequent.

Root Cause

With the current stale-socket regression (#55346), our gateway has restarted 28 times today. Each restart kicks the user out of the control UI to the login page, even though the gateway is back within seconds. A simple WebSocket reconnect would eliminate this friction entirely.

RAW_BUFFERClick to expand / collapse

Problem

When the gateway restarts (either planned or due to a crash like #55346), the control UI's WebSocket connection drops. The user is immediately redirected to the login page, followed by a 502 error while the gateway is still booting. After a few seconds they can refresh and log back in, but this is disruptive — especially when restarts are frequent.

Desired behavior

After a gateway restart, the control UI should:

  1. Detect the WebSocket disconnection
  2. Wait and retry the connection (with backoff)
  3. Once the gateway is back, automatically reconnect using the existing session/token
  4. Resume where the user left off (same chat, same context)

Constraints

  • Should not override the existing session timeout — if the auth token has genuinely expired (e.g. user was away for hours), the normal login flow should still apply
  • The 502 window is typically only a few seconds (5-10s), so a short reconnect window with backoff should be sufficient

Context

With the current stale-socket regression (#55346), our gateway has restarted 28 times today. Each restart kicks the user out of the control UI to the login page, even though the gateway is back within seconds. A simple WebSocket reconnect would eliminate this friction entirely.

Environment

  • OpenClaw: 2026.3.24
  • OS: Linux 6.8.0 (x64)
  • Node: 22.22.1
  • Gateway: local loopback (127.0.0.1:18789)

extent analysis

Fix Plan

To implement a WebSocket reconnect mechanism with backoff, follow these steps:

  • Modify the control UI's WebSocket connection establishment code to include a reconnect function with exponential backoff.
  • Use the existing session/token to reconnect automatically when the gateway is back online.

Example Code

// WebSocket connection with reconnect
const wsUrl = 'ws://127.0.0.1:18789';
let ws;
let reconnectTimeout;
let reconnectAttempts = 0;
const maxReconnectAttempts = 5;
const reconnectBackoff = 500; // initial backoff in milliseconds

function establishConnection() {
  ws = new WebSocket(wsUrl);
  ws.onclose = () => {
    reconnect();
  };
  ws.onmessage = (event) => {
    // handle incoming messages
  };
  ws.onerror = (event) => {
    // handle errors
  };
}

function reconnect() {
  reconnectAttempts++;
  if (reconnectAttempts <= maxReconnectAttempts) {
    reconnectTimeout = setTimeout(() => {
      establishConnection();
    }, reconnectBackoff * reconnectAttempts);
  } else {
    // handle max reconnect attempts exceeded
  }
}

establishConnection();

Verification

To verify the fix, restart the gateway and observe the control UI's behavior. The UI should detect the WebSocket disconnection, wait, and retry the connection with backoff. Once the gateway is back online, the UI should automatically reconnect using the existing session/token and resume where the user left off.

Extra Tips

  • Ensure the reconnect backoff values are adjusted according to the typical gateway restart duration (5-10 seconds in this case).
  • Consider implementing a maximum reconnect attempts limit to prevent infinite reconnect loops.
  • Monitor the control UI's behavior and adjust the reconnect mechanism as needed to ensure a seamless user experience.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Feature]: Control UI should auto-reconnect after gateway restart [1 participants]