Skip to content

Companion stays connected when the Gateway stops responding but TCP stays open #1958

Closed

Description

@MertBasar0

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.

Activity

  1. added
    clawsweeper:intake:bug
    clawsweeper:intake:needs-environment
    P2
    clawsweeper:fix-shape-clear
    clawsweeper:queueable-fix
    clawsweeper:source-repro
    impact:ux-friction
    issue-rating: 🦞 diamond lobster
    no-stale
    and removed
    clawsweeper:intake:bug
    clawsweeper:intake:needs-environment
    on Oct 31, 2026
  2. clawsweeper commented on Oct 31, 2026

    @clawsweeper

    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:

    • The proposed 30-second PONG timeout still needs real-Gateway compatibility and sleep/wake validation.
    • A receive handler that blocks control-frame processing could cause false liveness failures; the related premature-disconnect report does not establish that trigger.

    Codex review notes: model internal, reasoning medium; reviewed against a4dd026cc5f8.

    Label changes

    Label changes:

    • add P2: Source establishes a bounded connection-recovery defect, without evidence of a widespread current outage.
    • add impact:ux-friction: Companion can misleadingly retain connected state while the Gateway is unresponsive and automatic recovery never begins.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:queueable-fix: Current issue advisory state selects this label.
    • add 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:

    • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --filter 'FullyQualifiedName~WebSocketClientBaseTests'
    • ./build.ps1
    • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore
    • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore
    • dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj

    What I checked:

    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed October 31, 2026, 7:23 PM ET / 23:23 UTC.

  3. locked as resolved and limited conversation to collaborators on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2clawsweeper:fix-shape-clearclawsweeper:queueable-fixclawsweeper:source-reproimpact:ux-frictionissue-rating: 🦞 diamond lobsterno-stale

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions