You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When authentication fails (token mismatch, device signature invalid, or rate-limited), the reconnect logic retries every 1 second with no backoff. This creates a tight loop that:
Floods the gateway with failed auth attempts
Triggers the gateway's rate limiter (too many failed authentication attempts)
Makes the rate limit worse — once rate-limited, every retry resets the cooldown
Fills the log file with hundreds of identical errors per minute
Good diagnosis. I dug into the reconnect logic to confirm the root cause and map out a fix.
Root cause confirmed
The counter _reconnectAttempts lives in WebSocketClientBase and is reset to 0 at line 126 of WebSocketClientBase.cs, only when ConnectAsync reaches the await _webSocket.ConnectAsync(...) call and succeeds at the TCP/HTTP layer:
await_webSocket.ConnectAsync(uri,_cts.Token);_reconnectAttempts=0;// ← resets here
The backoff schedule (1s→2s→4s→8s→15s→30s→60s) therefore only applies to TCP-level failures. When the connection reaches the WebSocket handshake stage successfully but the gateway then closes it with PolicyViolation (token mismatch, rate-limit), the sequence is:
ConnectAsync succeeds → _reconnectAttempts = 0
ListenForMessagesAsync receives a Close frame
Code falls through to ReconnectWithBackoffAsync()
_reconnectAttempts is 0 again → next delay is 1 second → cycle repeats forever
The fix in OpenClawGatewayClient
OpenClawGatewayClient already has a ShouldAutoReconnect() override and a _pairingRequiredAwaitingApproval flag that pauses reconnection. The same pattern can be extended for auth failures:
Option A (minimal): In HandleRequestError, when the close reason is an auth error ("token mismatch", "too many failed authentication attempts") set a _authFailedAwaitingUserIntervention flag and return false from ShouldAutoReconnect(). Fire a new AuthenticationFailed event so the UI can show a persistent banner.
Option B (backoff-preserving, more surgical): Move the _reconnectAttempts = 0 reset from the TCP-connect success path into a new virtual method OnHandshakeSucceeded() called only after the gateway's hello-ok message is received. This way, auth failures at the challenge/response stage don't reset the counter.
Option A is simpler and directly addresses the gateway-rate-limiter problem. Option B is more correct but touches WebSocketClientBase.
Tests added this run
I've opened a draft PR (pending merge) adding 13 tests that cover the HandleRequestError paths, including verifying _pairingRequiredAwaitingApproval is set and ConnectionStatus.Error is raised. These will guard against regressions once the fix lands.
Activity
github-actions commentedon Apr 23, 2026
🤖 This is an automated response from Repo Assist.
Good diagnosis. I dug into the reconnect logic to confirm the root cause and map out a fix.
Root cause confirmed
The counter
_reconnectAttemptslives inWebSocketClientBaseand is reset to0at line 126 ofWebSocketClientBase.cs, only whenConnectAsyncreaches theawait _webSocket.ConnectAsync(...)call and succeeds at the TCP/HTTP layer:The backoff schedule (
1s→2s→4s→8s→15s→30s→60s) therefore only applies to TCP-level failures. When the connection reaches the WebSocket handshake stage successfully but the gateway then closes it withPolicyViolation(token mismatch, rate-limit), the sequence is:ConnectAsyncsucceeds →_reconnectAttempts = 0ListenForMessagesAsyncreceives aCloseframeReconnectWithBackoffAsync()_reconnectAttemptsis 0 again → next delay is 1 second → cycle repeats foreverThe fix in
OpenClawGatewayClientOpenClawGatewayClientalready has aShouldAutoReconnect()override and a_pairingRequiredAwaitingApprovalflag that pauses reconnection. The same pattern can be extended for auth failures:Option A (minimal): In
HandleRequestError, when the close reason is an auth error ("token mismatch","too many failed authentication attempts") set a_authFailedAwaitingUserInterventionflag and returnfalsefromShouldAutoReconnect(). Fire a newAuthenticationFailedevent so the UI can show a persistent banner.Option B (backoff-preserving, more surgical): Move the
_reconnectAttempts = 0reset from the TCP-connect success path into a new virtual methodOnHandshakeSucceeded()called only after the gateway'shello-okmessage is received. This way, auth failures at the challenge/response stage don't reset the counter.Option A is simpler and directly addresses the gateway-rate-limiter problem. Option B is more correct but touches
WebSocketClientBase.Tests added this run
I've opened a draft PR (pending merge) adding 13 tests that cover the
HandleRequestErrorpaths, including verifying_pairingRequiredAwaitingApprovalis set andConnectionStatus.Erroris raised. These will guard against regressions once the fix lands.fix: stop aggressive retry on auth failures, add setup nudge
fix: stop aggressive retry on auth failures, add setup nudge (opencla…