Repository navigation
Bound WebSocket reconnect attempts - #1352
Conversation
Add a per-attempt HTTP upgrade deadline, abort timed-out sockets, and preserve reconnect ownership across manual connection and authorization races. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4f97b3a3-def7-4f33-b7d5-ece171b4fd0b
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 10:41 AM ET / 14:41 UTC. ClawSweeper reviewWhat this changesBounds WebSocket connection attempts to 15 seconds, preserves retry ownership across concurrent connections, and adds real-loopback regression coverage. Merge readiness✅ Ready for maintainer review This PR remains necessary: main and the latest release still allow an unbounded WebSocket upgrade wait. The previous lost-recovery finding is addressed, and no remaining blocking code defect was found. Priority: P0 Review scores
Verification
How this fits togetherThe shared WebSocket transport connects Windows Companion’s operator and node clients to a gateway. It establishes the connection, delivers incoming messages, and retries unexpected connection failures. flowchart TD
A[Operator and node clients] --> B[WebSocket connection attempt]
B --> C{Upgrade completes within deadline?}
C -->|Yes| D[Receive gateway messages]
C -->|No| E[Dispose socket and report timeout]
E --> F[Backoff and endpoint authorization]
F --> G{Retry still owns recovery?}
G -->|Yes| B
G -->|No| D
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep automatic recovery bounded at transport establishment while preserving shutdown cancellation, endpoint authorization, and newer healthy connections. Do we have a high-confidence way to reproduce the issue? Yes: a TCP peer that accepts the upgrade request but withholds its HTTP response reaches the unbounded await on main. The inspected loopback harness exercises that mechanism; this review did not execute it or independently reproduce the original LAN incident. Is this the best way to solve the issue? Yes: the deadline belongs in the shared transport, and the revised ownership handoff addresses the prior finding without adding another reconnect mechanism or changing stored settings. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2bdcfc253310. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Keep the active reconnect loop running when a newer manual connection supersedes it but also fails, while still yielding to newer open sockets. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4f97b3a3-def7-4f33-b7d5-ece171b4fd0b
Problem
Fixes #1344.
A gateway peer can accept TCP but never complete the WebSocket HTTP upgrade.
WebSocketClientBase.ConnectAsyncpreviously awaitedClientWebSocket.ConnectAsyncwith only the client lifetime token, so one stalled attempt could block the single reconnect loop forever and leave node mode stuck at Connecting until the tray process was force-killed.Fix
Required proof pools
windows-wsl-gateway-e2e: verified on current head by real Gateway stop/start recovery and three repeated Gateway restart recoveries.Validation
Current head:
8134a76e.dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --filter "FullyQualifiedName~WebSocketClientBaseTests": 35 passed per run, repeated 5 consecutive times.\build.ps1: passeddotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: 3,943 passed, 32 skippeddotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: 2,860 passeddotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restore: 718 passedgit diff --check: passed34133976203: CI Gate, setup/connect E2E, network recovery E2E, revocation recovery E2E, core/CLI, tray/setup/integration, UI/accessibility, CodeQL, and security checks passedCommandRunnerTests.RunAsync_ReturnsWhenDescendantKeepsOutputPipesOpentiming flake at 5.81 seconds against a 5-second assertion; the failed job rerun passedpython .agents\skills\autoreview\scripts\autoreview --mode local --stream-engine-output: clean, no accepted/actionable findingsReal behavior proof
The focused suite uses a real loopback TCP peer, not a mocked
ClientWebSocket:Current-head GitHub
Network recovery E2Epassed both real WSL Gateway scenarios:GatewayStopAndStart_TrayLeavesReadyThenRecovers: passed in 25 secondsRepeatedGatewayRestart_TrayAndNodeRecoverEachTime: passed in 55 seconds, covering three consecutive Gateway restartsThe original intermittent remote-LAN incident and reporter dump were not independently reproduced. The deterministic peer directly reproduces the source-level failure mode shown by the dump: TCP is accepted while
ClientWebSocketwaits indefinitely for the HTTP upgrade response.Review notes
ClawSweeper identified a lost-recovery handoff when a newer manual attempt superseded an in-flight retry and also failed. That finding was accepted and fixed with the four-attempt real-loopback regression above. Its current-head review reports no findings and marks the PR ready for maintainer review.
An earlier autoreview TOCTOU finding was rejected after tracing the locked state transition. It assumed disposing a newer closing socket would make atomic publication reject the retry and leave the client disconnected. The implementation intentionally permits the active single-flight loop to adopt a null or closing transport; only a newer open or connecting socket blocks publication. Existing and new tests prove both the closing-socket handoff and newer-open-socket preservation. The final structured autoreview is clean.
Security impact
No credential or endpoint-authorization policy changes. Authorization still runs before every client-owned reconnect. The change only bounds transport establishment and prevents stale retry or authorization work from replacing a newer healthy socket.