Skip to content

Windows Companion can hang forever in ClientWebSocket.ConnectAsync after gateway restart; node mode never reconnects #1344

Closed

Description

@couger

Summary

OpenClaw Windows Companion sometimes fails to reconnect Node Mode after the remote gateway is restarted. The gateway is reachable, credentials and pairing are valid, but the Companion process remains stuck at Connecting to gateway until the process is force-killed and restarted.

Environment

  • Windows Companion: v2026.7.1-4
  • Companion ProductVersion: 2026.7.1-4+c7c6fb06be036de512d824986a6eee6eca14abdb
  • Gateway: OpenClaw 2026.9.1 (ad6fe23)
  • Gateway host: remote LAN machine, ws://192.168.10.9:18789
  • Local Windows node IP: 192.168.10.10
  • Node mode enabled

Observed behavior

After restarting the gateway, Companion logs only:

Connecting to last successful gateway during startup: ws://<host>:18789/ (identity.DeviceToken)
Loaded Ed25519 device identity: [REDACTED]
Connecting to gateway: ws://<host>:18789/
Application started (WinUI 3)

It never logs:

gateway connected, waiting for challenge...

The gateway reports the device as paired and approved, but disconnected:

Known: 2 · Paired: 2 · Connected: 0
Windows Node (DESKTOP-1TJT2RH) paired · disconnected · approved

Network and gateway health are fine:

Test-NetConnection 192.168.10.9 -Port 18789 => TcpTestSucceeded: True
GET http://192.168.10.9:18789/healthz => {"ok":true,"status":"live"}

A standalone .NET ClientWebSocket test can connect and immediately receive connect.challenge.

Dump evidence

A process dump captured while Companion was stuck shows the reconnect task awaiting inside the WebSocket HTTP upgrade response path:

System.Net.Http.HttpConnection.<InitialFillAsync>
System.Net.Http.HttpConnection.<SendAsync>
System.Net.Http.HttpConnectionPool.<SendWithVersionDetectionAndRetryAsync>
System.Net.Http.RedirectHandler.<SendAsync>
System.Net.WebSockets.WebSocketHandle.<ConnectAsync>
System.Net.WebSockets.ClientWebSocket.<ConnectAsyncCore>
OpenClaw.Shared.WebSocketClientBase.<ConnectAsync>
OpenClaw.Shared.WebSocketClientBase.<ReconnectWithBackoffAsync>

This matches the log behavior: the app starts the connect attempt but never reaches the transport-connected callback.

Expected behavior

Each WebSocket connect attempt should have a bounded timeout. If ClientWebSocket.ConnectAsync() hangs or does not complete within a reasonable interval, Companion should abort that socket and continue the reconnect/backoff loop.

Actual behavior

The connect attempt can hang indefinitely. Normal app restart did not always recover it. Force-killing OpenClaw.Tray.WinUI.exe and launching it again immediately restored node mode.

Suggested fix

Wrap each ClientWebSocket.ConnectAsync(uri, ...) attempt in a per-attempt timeout, separate from the process lifetime cancellation token. On timeout:

  • Abort/dispose the current ClientWebSocket
  • Mark connection status as error/disconnected
  • Continue the existing reconnect/backoff loop
  • Log a clear message such as gateway connect timed out

This seems related to OpenClaw.Shared.WebSocketClientBase.ConnectAsync.

Activity

  1. added
    P0
    clawsweeper:source-repro
    impact:crash-loop
    impact:ux-release-blocker
    issue-rating: 🦞 diamond lobster
    on Sep 6, 2026
  2. clawsweeper commented on Sep 6, 2026

    @clawsweeper

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed September 7, 2026, 9:09 AM ET / 13:09 UTC.

    Summary
    The reported hang remains source-supported on current main. The linked setup PR explicitly excludes this runtime failure, so it does not establish a fix or supersession.

    Reproducibility: yes. at source level: a peer that accepts TCP but withholds the HTTP upgrade response leaves the lifetime-token-only await pending and prevents another retry. This review did not execute that scenario.

    Next step
    Keep this P0 recovery blocker with its active owner for a focused timeout repair and Windows validation; the setup PR is not its implementation candidate, and a parallel automated dispatch is inappropriate.

    Review details

    Best possible solution:

    Add an attempt-scoped transport deadline with socket cleanup and continued backoff, preserve shutdown and authorization guards, and provide a visible Retry or Fix action if automatic recovery fails.

    Do we have a high-confidence way to reproduce the issue?

    Yes, at source level: a peer that accepts TCP but withholds the HTTP upgrade response leaves the lifetime-token-only await pending and prevents another retry. This review did not execute that scenario.

    Is this the best way to solve the issue?

    Yes. A deadline in the shared transport is the narrow repair boundary; it must distinguish timeout from shutdown and preserve current socket ownership rather than add a parallel reconnect mechanism.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The exact Windows/LAN trigger has not been reproduced by this review; source establishes the missing deadline, while recovery under a stalled HTTP upgrade still needs runtime validation.

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

    Label changes

    Label changes:

    • add clawsweeper:linked-pr-open: Current issue advisory state selects this label.
    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.

    Label justifications:

    • P0: The reported Companion recovery path remains stuck until process termination, leaving no demonstrated in-product way forward.
    • impact:crash-loop: An indefinitely pending transport connection prevents Node Mode from recovering.
    • impact:ux-release-blocker: The reporter needed to force-kill and relaunch the Companion to restore operation.
    Evidence reviewed

    What I checked:

    • Current transport has no attempt deadline: ConnectAsync passes only the client lifetime token to ClientWebSocket.ConnectAsync. Status changes to Connecting before that await, and the transport-connected callback runs afterward. (src/OpenClaw.Shared/WebSocketClientBase.cs:262, 2bdcfc253310)
    • Stalled attempt blocks further retries: The single active reconnect loop awaits ConnectAsync before checking connection success or advancing to another attempt. The existing endpoint-authorization and socket-generation guards must remain intact in a repair. (src/OpenClaw.Shared/WebSocketClientBase.cs:568, 2bdcfc253310)
    • Reported release still matches main: The complete shared transport file has no differences between v2026.7.1-4 and the reviewed main revision. The release tag resolves to c7c6fb0; no fix is established in either revision. (src/OpenClaw.Shared/WebSocketClientBase.cs:262, c7c6fb06be03)
    • Existing retry contract and coverage: ConnectAsync_WhenConnectionFails_StartsReconnectLoop asserts Error followed by another Connecting state against a refused connection. That establishes the intended retry behavior but does not exercise an accepted TCP connection whose HTTP upgrade never completes. (tests/OpenClaw.Shared.Tests/WebSocketClientBaseTests.cs:314, 2bdcfc253310)
    • Caller cancellation is not an attempt deadline: NodeConnector registers caller cancellation to disconnect the current generation, then awaits client.ConnectAsync without a timer. Both WindowsNodeClient and OpenClawGatewayClient inherit the shared transport. (src/OpenClaw.Connection/NodeConnector.cs:191, 2bdcfc253310)
    • Discussion distinguishes the setup PR: Although supplied closing-reference metadata lists fix(setup): recognize the gateway service on its own port after install #1349, its captured body explicitly states that its setup-time listener ownership repair does not fix or close this runtime reconnect issue. The timeline also records shanselman taking active ownership through the actively-landing label.

    Likely related people:

    • shanselman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
    • Barbara Kudiess: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
    • Christine Yan: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
    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.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  3. added
    status: 🚢 actively landing
    on Sep 7, 2026
  4. added
    clawsweeper:linked-pr-open
    clawsweeper:no-new-fix-pr
    on Sep 7, 2026
  5. removed
    status: 🚢 actively landing
    on Sep 7, 2026
  6. locked as resolved and limited conversation to collaborators on Sep 10, 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

    P0clawsweeper:linked-pr-openclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:crash-loopimpact:ux-release-blockerissue-rating: 🦞 diamond lobster

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions