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
{{ message }}
Repository navigation
Reconnect / "re-approval, repair" loop connecting to a pre-existing (self-hosted) gateway over wss #696
P2Normal priority bug or improvement with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.impact:auth-providerThis issue is about auth, provider routing, model choice, or SecretRef resolution.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
Connecting the Companion to my own existing gateway over Tailscale (wss), rather than the wizard-managed distro, it pairs and goes green for a minute, then drops into a constant "re-approval, repair" loop — roughly 10 reconnect/pairing events every couple of minutes on 0.6.3.
I tried the change on the websocket-lifecycle-correctness branch (the connection-generation counter) on top of current main, and the loop's gone — zero reconnect events over several minutes, and it holds a stable operator connection. So that approach looks like it fixes the connect-to-an-existing-gateway case. Might be worth getting onto a release.
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 5, 2026, 7:28 AM ET / 11:28 UTC.
Summary
Keep open. The reported self-hosted wss reconnect/re-approval loop is not solved on current master: the relevant WebSocket lifecycle files are unchanged from v0.6.3, and the branch the reporter tested remains a closed-unmerged prior PR rather than code on the default branch.
Reproducibility: no. live self-hosted wss reproduction was run. The reporter gives a concrete v0.6.3 scenario plus a tested branch result, and current source still lacks the branch's WebSocket connection-generation guard.
Ways to help us reproduce this
Add a screenshot or short recording showing the behavior.
Add expected vs actual behavior.
Next step
A repair lane can attempt the fresh focused current-master PR requested by the closed prior WebSocket lifecycle PR, but it must stay narrow and include connection lifecycle validation.
Review details
Best possible solution:
Land a fresh current-master WebSocket lifecycle fix that generation-guards stale socket/listen/reconnect work and proves stable self-hosted wss operator connection without reviving broad unrelated branch churn.
Do we have a high-confidence way to reproduce the issue?
No live self-hosted wss reproduction was run. The reporter gives a concrete v0.6.3 scenario plus a tested branch result, and current source still lacks the branch's WebSocket connection-generation guard.
Is this the best way to solve the issue?
Unclear; the reported connection-generation approach is promising and branch-tested by the reporter, but the prior PR was closed unmerged as too dirty/high-risk, so the maintainable solution is a fresh focused current-master implementation with lifecycle validation.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
The exact self-hosted gateway over Tailscale/wss runtime was not reproduced locally, so gateway-side timing or hosted-gateway behavior may still be part of the failure.
A WebSocket lifecycle fix touches shared operator and node reconnect behavior; it needs focused stale-socket, cancellation, pairing, and upgrade validation before release.
Codex review notes: model gpt-5.5, reasoning high; reviewed against 99efc50cbc22.
Label changes
Label changes:
add P2: This is a current release connection bug with a concrete external report, but the blast radius is limited to a self-hosted wss gateway scenario rather than a confirmed repo-wide outage.
add impact:auth-provider: The symptom is a repeated pairing/re-approval loop, so the affected maintainer surface is gateway authentication and pairing state.
add issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.
add clawsweeper:needs-live-repro: Current issue advisory state selects this label.
Label justifications:
P2: This is a current release connection bug with a concrete external report, but the blast radius is limited to a self-hosted wss gateway scenario rather than a confirmed repo-wide outage.
impact:auth-provider: The symptom is a repeated pairing/re-approval loop, so the affected maintainer surface is gateway authentication and pairing state.
Evidence reviewed
Acceptance criteria:
./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
Manual Windows smoke: connect Companion to an existing self-hosted wss gateway over Tailscale and verify no repeated pairing/reconnect events for at least 5 minutes.
What I checked:
Current source lacks the tested WebSocket generation guard: Current master still starts ConnectAsync without a per-socket connection-generation token and its listen loop reads the mutable _webSocket field, so stale socket close/error work can still feed the shared reconnect path. (src/OpenClaw.Shared/WebSocketClientBase.cs:106, 99efc50cbc22)
Relevant lifecycle files are unchanged from v0.6.3 to current master: The diff from latest release v0.6.3 to HEAD is empty for WebSocketClientBase, WindowsNodeClient, GatewayConnectionManager, and the targeted lifecycle tests, so the reported 0.6.3 behavior has not been fixed in the checked source. (99efc50cbc22)
Prior branch shows the intended fix shape: Commit e60efcb added WebSocket lifecycle responsiveness changes across GatewayConnectionManager, WebSocketClientBase, and focused tests, including connection-generation and in-flight cancellation coverage. (src/OpenClaw.Shared/WebSocketClientBase.cs:1, e60efcb12713)
Prior maintainer context asks for a fresh focused PR: The closing comment on Fix WebSocket lifecycle responsiveness #443 says the concern is valid but should return as a fresh focused PR against current master with targeted lifecycle validation. (e60efcb12713)
Repository docs put this in core connection ownership: The connection architecture says GatewayConnectionManager owns connection lifecycle and that the tray consumes it instead of creating parallel gateway clients, making this a core connection-layer bug rather than external support only. (docs/CONNECTION_ARCHITECTURE.md:17, 99efc50cbc22)
Likely related people:
shanselman: Authored the closed websocket-lifecycle-correctness branch and has substantial history in WebSocketClientBase, reconnect behavior, diagnostics, and Windows node mode. (role: recent adjacent contributor; confidence: high; commits: e60efcb12713, 76f7811a1448, 7a95b190f147; files: src/OpenClaw.Shared/WebSocketClientBase.cs, src/OpenClaw.Shared/WindowsNodeClient.cs, src/OpenClaw.Connection/GatewayConnectionManager.cs)
Ranjesh Jaganathan: Introduced and iterated the current connection architecture, per-gateway identity, node connector, and pairing lifecycle code paths that this loop exercises. (role: connection architecture contributor; confidence: high; commits: e3c6504aaf27, 2e5dd14d136f, 398420a92843; files: src/OpenClaw.Connection/GatewayConnectionManager.cs, src/OpenClaw.Connection/NodeConnector.cs, src/OpenClaw.Shared/WindowsNodeClient.cs)
Vincent Koc: Recent commits hardened Windows node bootstrap reconnects, persisted node-token startup, and app-version handshakes near the reported re-approval loop surface. (role: recent pairing and token contributor; confidence: medium; commits: 64b650cb3313, ee8fd4ef4ff0, 66683a33e770; files: src/OpenClaw.Connection/GatewayConnectionManager.cs, src/OpenClaw.Shared/WindowsNodeClient.cs)
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.
I had a look at WebSocketClientBase.cs to understand the reconnect loop root cause.
What's happening
ConnectAsync() assigns a new socket to _webSocket, then fires ListenForMessagesAsync() as a fire-and-forget Task.Run. When the listen loop exits (e.g., ConnectionClosedPrematurely), it calls ReconnectWithBackoffAsync(). The reconnect loop then sets _webSocket = null, disposes the old socket, and calls ConnectAsync() again — which fires anotherListenForMessagesAsync().
The race is in ConnectAsync():
_webSocket=newClientWebSocket();// shared field mutated hereawait_webSocket.ConnectAsync(uri,_cts.Token);awaitOnConnectedAsync();// may trigger pairing/challenge exchange_=Task.Run(()=>ListenForMessagesAsync(),_cts.Token);// fire-and-forget
There's no generation guard — if the reconnect loop races with an in-flight OnConnectedAsync() (e.g., because a transient socket error during TCP connect started a second reconnect path), a stale listen task can end up calling ReconnectWithBackoffAsync() against the wrong socket generation, triggering another pairing challenge.
The fix from websocket-lifecycle-correctness
The closed PR #443 added a _connectionGeneration counter (long, Interlocked.Increment in ConnectAsync). Each call captures its generation, and after each async step checks IsCurrentConnection(ws, connectGeneration) before proceeding. ListenForMessagesAsync receives the socket ref and generation as parameters, so it won't interfere with a newer connection even if it exits late.
A focused fresh PR against current main implementing just this guard — plus the cancellation-propagation changes from that branch — would likely fix the re-approval loop. The _reconnectLoopActive int guard prevents concurrent reconnect loops, but doesn't prevent a stale listen task from triggering ReconnectWithBackoffAsync() when _reconnectLoopActive has already been reset to 0 by the previous loop.
Since this touches core connection lifecycle, live testing with a self-hosted wss gateway is needed before merging (hence the clawsweeper:needs-live-repro label).
Hi @markbdean01, I have PR #739 that implements the generation guard suggested by Copilot above. Could you try out that branch with your Tailscale gateway setup and see if it helps?
Thanks Christine — tested #739. Built the branch and ran the connection-layer test suites: the new WebSocketClientBase generation-guard tests pass 24/24, and OpenClaw.Connection.Tests (pairing/state-machine) is green at 297/297 with no regressions. Looks solid. I'll follow up if I see the reconnect/re-approval loop recur against my self-hosted Tailscale gateway in normal use.
Thanks for taking a look @markbdean01. Were you able to try the build with the fix against your own gateway? Did it resolve the issue that you were hitting?
Yes — built #739 and ran it live against my own self-hosted gateway (OpenClaw over wss, reached via Tailscale). It resolves it for me.
Test suites first: the generation-guard tests pass (StaleEventGuard 5/5) and OpenClaw.Connection.Tests is 297/297 green, no regressions. (One unrelated MXC desktop-path test fails only under my SYSTEM-context build runner — environment, not the fix.)
Then live: the node reconnects as operator reusing its persisted device token — no re-pairing — and the operator RPCs that used to get rejected (sessions.list, chat.history) now come back clean. I forced several transient drops including a full cold restart of the node (socket fully gone, reconnected in ~3s): 0 re-approval requests, 0 PolicyViolation, 0 rate-limits across all of it. Before the fix the same setup span up ~10-20 pairing/re-approval events in a couple of minutes, so the difference is night and day.
So from my side #696 is fixed by the generation-guard. Happy to leave it running for the week and shout if anything recurs.
P2Normal priority bug or improvement with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.impact:auth-providerThis issue is about auth, provider routing, model choice, or SecretRef resolution.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
Activity
clawsweeper commentedon Jun 5, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 5, 2026, 7:28 AM ET / 11:28 UTC.
Summary
Keep open. The reported self-hosted wss reconnect/re-approval loop is not solved on current master: the relevant WebSocket lifecycle files are unchanged from v0.6.3, and the branch the reporter tested remains a closed-unmerged prior PR rather than code on the default branch.
Reproducibility: no. live self-hosted wss reproduction was run. The reporter gives a concrete v0.6.3 scenario plus a tested branch result, and current source still lacks the branch's WebSocket connection-generation guard.
Ways to help us reproduce this
Next step
A repair lane can attempt the fresh focused current-master PR requested by the closed prior WebSocket lifecycle PR, but it must stay narrow and include connection lifecycle validation.
Review details
Best possible solution:
Land a fresh current-master WebSocket lifecycle fix that generation-guards stale socket/listen/reconnect work and proves stable self-hosted wss operator connection without reviving broad unrelated branch churn.
Do we have a high-confidence way to reproduce the issue?
No live self-hosted wss reproduction was run. The reporter gives a concrete v0.6.3 scenario plus a tested branch result, and current source still lacks the branch's WebSocket connection-generation guard.
Is this the best way to solve the issue?
Unclear; the reported connection-generation approach is promising and branch-tested by the reporter, but the prior PR was closed unmerged as too dirty/high-risk, so the maintainable solution is a fresh focused current-master implementation with lifecycle validation.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 99efc50cbc22.
Label changes
Label changes:
P2: This is a current release connection bug with a concrete external report, but the blast radius is limited to a self-hosted wss gateway scenario rather than a confirmed repo-wide outage.impact:auth-provider: The symptom is a repeated pairing/re-approval loop, so the affected maintainer surface is gateway authentication and pairing state.issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.clawsweeper:needs-live-repro: Current issue advisory state selects this label.Label justifications:
P2: This is a current release connection bug with a concrete external report, but the blast radius is limited to a self-hosted wss gateway scenario rather than a confirmed repo-wide outage.impact:auth-provider: The symptom is a repeated pairing/re-approval loop, so the affected maintainer surface is gateway authentication and pairing state.Evidence reviewed
Acceptance criteria:
What I checked:
src/OpenClaw.Shared/WebSocketClientBase.cs:106, 99efc50cbc22)src/OpenClaw.Shared/WebSocketClientBase.cs:1, e60efcb12713)docs/CONNECTION_ARCHITECTURE.md:17, 99efc50cbc22)Likely related people:
src/OpenClaw.Shared/WebSocketClientBase.cs,src/OpenClaw.Shared/WindowsNodeClient.cs,src/OpenClaw.Connection/GatewayConnectionManager.cs)src/OpenClaw.Connection/GatewayConnectionManager.cs,src/OpenClaw.Connection/NodeConnector.cs,src/OpenClaw.Shared/WindowsNodeClient.cs)src/OpenClaw.Connection/GatewayConnectionManager.cs,src/OpenClaw.Shared/WindowsNodeClient.cs)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 autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.github-actions commentedon Jun 10, 2026
🤖 This is an automated response from Repo Assist.
I had a look at
WebSocketClientBase.csto understand the reconnect loop root cause.What's happening
ConnectAsync()assigns a new socket to_webSocket, then firesListenForMessagesAsync()as a fire-and-forgetTask.Run. When the listen loop exits (e.g.,ConnectionClosedPrematurely), it callsReconnectWithBackoffAsync(). The reconnect loop then sets_webSocket = null, disposes the old socket, and callsConnectAsync()again — which fires anotherListenForMessagesAsync().The race is in
ConnectAsync():There's no generation guard — if the reconnect loop races with an in-flight
OnConnectedAsync()(e.g., because a transient socket error during TCP connect started a second reconnect path), a stale listen task can end up callingReconnectWithBackoffAsync()against the wrong socket generation, triggering another pairing challenge.The fix from
websocket-lifecycle-correctnessThe closed PR #443 added a
_connectionGenerationcounter (long,Interlocked.IncrementinConnectAsync). Each call captures its generation, and after each async step checksIsCurrentConnection(ws, connectGeneration)before proceeding.ListenForMessagesAsyncreceives the socket ref and generation as parameters, so it won't interfere with a newer connection even if it exits late.A focused fresh PR against current
mainimplementing just this guard — plus the cancellation-propagation changes from that branch — would likely fix the re-approval loop. The_reconnectLoopActiveint guard prevents concurrent reconnect loops, but doesn't prevent a stale listen task from triggeringReconnectWithBackoffAsync()when_reconnectLoopActivehas already been reset to 0 by the previous loop.Since this touches core connection lifecycle, live testing with a self-hosted wss gateway is needed before merging (hence the
clawsweeper:needs-live-reprolabel).Add this agentic workflows to your repo
To install this agentic workflow, run
ranjeshj commentedon Jun 10, 2026
Update from #741:
The reconnect/re-approval loop class should be improved by the Windows-client fixes in #741:
Still pending / not covered by #741:
The specific connection/pairing flows in #741 were validated with full real WSL E2E passing (17/17).
christineyan4 commentedon Jun 10, 2026
Hi @markbdean01, I have PR #739 that implements the generation guard suggested by Copilot above. Could you try out that branch with your Tailscale gateway setup and see if it helps?
moosebuilds commentedon Jun 10, 2026
kmahone commentedon Jun 12, 2026
Thanks for taking a look @markbdean01. Were you able to try the build with the fix against your own gateway? Did it resolve the issue that you were hitting?
moosebuilds commentedon Jun 18, 2026
Yes — built #739 and ran it live against my own self-hosted gateway (OpenClaw over wss, reached via Tailscale). It resolves it for me.
Test suites first: the generation-guard tests pass (StaleEventGuard 5/5) and OpenClaw.Connection.Tests is 297/297 green, no regressions. (One unrelated MXC desktop-path test fails only under my SYSTEM-context build runner — environment, not the fix.)
Then live: the node reconnects as operator reusing its persisted device token — no re-pairing — and the operator RPCs that used to get rejected (sessions.list, chat.history) now come back clean. I forced several transient drops including a full cold restart of the node (socket fully gone, reconnected in ~3s): 0 re-approval requests, 0 PolicyViolation, 0 rate-limits across all of it. Before the fix the same setup span up ~10-20 pairing/re-approval events in a couple of minutes, so the difference is night and day.
So from my side #696 is fixed by the generation-guard. Happy to leave it running for the week and shout if anything recurs.