Repository navigation
Description
Summary
When the Gateway stops responding but its TCP connection stays open, Companion keeps reporting that it is connected and never reconnects. It only notices when something closes the socket.
Cause
WebSocketClientBase sets ClientWebSocket.Options.KeepAliveInterval to 30 seconds and leaves KeepAliveTimeout unset. With no timeout, .NET only sends unsolicited pong frames, so it never expects an answer. A frozen peer looks the same as a quiet one.
Nothing else covers this. tickIntervalMs is parsed into the Gateway info but has no consumer, while the main repo's Gateway client closes the connection after two missed tick intervals.
The case that worries me most is a Gateway behind the WSL localhost relay or a local proxy, where the local side keeps the TCP connection alive while the process behind it is stuck.
Reproduce
A small Node server using [email protected], the WebSocket library the Gateway uses, with automatic pong replies. After 75 seconds it blocks its event loop, so the TCP connection stays open and nothing answers. The client is the real WebSocketClientBase with its production values, on main a4dd026.
server: 22:46:03 connection
server: 22:47:18 freezing the event loop
client: t+0,0s status Connecting
client: t+0,0s connected=True
client: t+240,1s end connected=True errors=0
The client still reports connected 165 seconds after the freeze, when the measurement ended, with no status change.
Fix I have ready
Set KeepAliveTimeout to 30 seconds, so the client sends real pings and gives up after 60 seconds at most. That matches the main client's limit of two 30-second ticks. When the pong does not arrive, .NET aborts the socket, and the listen loop treated that as a shutdown: it reconnected without ever reporting the loss. The fix reports it as Disconnected, as for any other lost connection, and keeps AbortCurrentWebSocket silent.
Same server with the fix:
server: 22:51:28 ping 1, automatic pong
server: 22:52:05 ping 2, automatic pong
server: 22:52:13 freezing the event loop
client: t+142,5s status Disconnected
client: t+142,5s status Connecting
client: t+158,8s status Error
It detects the freeze 67 seconds later. Two earlier pings also show that a healthy ws server answers, so a working connection is not dropped.
Not verified
- A real Gateway. The server above is a stand-in using the same library.
- Real sleep and wake, and a real network or Tailscale drop. I expect TCP retransmission to end those connections on its own, so this issue is only about a peer that keeps TCP open.
- Whether a Gateway event loop can stall for more than 30 seconds in normal use. If it can, this would now reconnect where it used to wait. [Bug] Hub 2026.9.8-1: premature WebSocket closures and lost system.run.prepare result with WSL Gateway #1689 (
Hub 2026.9.8-1: premature WebSocket closures and lost system.run.prepare result with WSL Gateway) is related but has the opposite symptom, and this change does not address it.
I found no existing issue for this. PR #627 (Harden tray<->gateway keep-alive and reconnect lifecycle) added an application heartbeat in June and was closed without merging. This is a much smaller change.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsBacklog
Activity
clawsweeper commentedon Oct 31, 2026
Codex review: this still needs some work.
Summary
Current main still lacks established-connection liveness detection, so this issue identifies a concrete transport bug with a focused repair path.
Reproducibility: Current source and the .NET contract establish the silent-peer path; the reporter also supplies stand-in server logs, but this read-only review ran no reproduction, builds, or tests.
Next step
Establish a failing silent-peer regression, then add bounded liveness detection and disconnect cleanup while preserving intentional-abort behavior.
Review details
Best possible solution:
Use bounded protocol-level liveness detection that clears stale connection state and reconnects through existing authorization and ownership safeguards.
Do we have a high-confidence way to reproduce the issue?
Current source and the .NET contract establish the silent-peer path; the reporter also supplies stand-in server logs, but this read-only review ran no reproduction, builds, or tests.
Is this the best way to solve the issue?
A finite protocol PONG timeout is a focused approach that avoids the earlier PR's unsupported application-ping assumption; timeout cancellation must also invoke disconnect cleanup while preserving deliberate aborts.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning medium; reviewed against a4dd026cc5f8.
Label changes
Label changes:
P2: Source establishes a bounded connection-recovery defect, without evidence of a widespread current outage.impact:ux-friction: Companion can misleadingly retain connected state while the Gateway is unresponsive and automatic recovery never begins.issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.clawsweeper:queueable-fix: Current issue advisory state selects this label.clawsweeper:fix-shape-clear: Current issue advisory state selects this label.Label justifications:
P2: Source establishes a bounded connection-recovery defect, without evidence of a widespread current outage.impact:ux-friction: Companion can misleadingly retain connected state while the Gateway is unresponsive and automatic recovery never begins.Evidence reviewed
Acceptance criteria:
What I checked:
src/OpenClaw.Shared/WebSocketClientBase.cs:278, a4dd026cc5f8)src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs:198, 60629d14374c)src/OpenClaw.Shared/WebSocketClientBase.cs:486, a4dd026cc5f8)src/OpenClaw.Shared/OpenClawGatewayClient.cs:235, a4dd026cc5f8)tests/OpenClaw.Shared.Tests/WebSocketClientBaseTests.cs:258, a4dd026cc5f8)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.Reviewed October 31, 2026, 7:23 PM ET / 23:23 UTC.