Repository navigation
fix: keep this PC's node listed after a Gateway restart rebuilds the connection - #2416
Conversation
|
🦞👀 ClawSweeper review completeClawSweeper finished reviewing this revision. |
|
Codex review: passed. What this changesThis PR refreshes Gateway snapshots when a replacement client connects before GatewayService subscribes to its events. Example: A Gateway restart rebuilds the connection while the UI dispatcher is busy.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a source-confirmed late-subscription race still present on main, with no actionable defect found in the patch. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGatewayConnectionManager creates operator clients, App dispatches client swaps to GatewayService, and GatewayService publishes Gateway events into AppState for UI and local app commands. flowchart LR
A[GatewayConnectionManager] --> B[App dispatcher]
B --> C[GatewayService]
C --> D[Operator client]
D --> E[Gateway]
D --> C
C --> F[AppState]
F --> G[UI and app commands]
Technical reviewBest possible solution: Keep snapshot recovery in GatewayService immediately after subscription, using the existing readiness gate and request methods. Do we have a high-confidence way to reproduce the issue? The source establishes that a connected client can publish its initial snapshot before UI-dispatched subscription; the PR reports that the added regression fails without the fix, but this read-only review did not execute it. Is this the best way to solve the issue? The patch repairs the missed-subscription boundary in its existing owner, preserves normal pre-connect attachment, and adds no parallel cache, protocol or retry framework. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fd600e4c4cf2. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall readiness starts with the lower of the proof and patch scores. It is capped at 3/6 if the fix is partial, the change offers little benefit, a product decision is still open, or the PR reverses an earlier decision without saying why. ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 30, 2026, 4:54 PM ET / 21:54 UTC. |
130ebc4 to
e7519ef
Compare
…late The connection manager raises OperatorClientChanged before it connects the new client, but GatewayService subscribes on the UI thread. When the Gateway restart repair rebuilt the client and the UI thread lagged, the new client finished its handshake and published node.list (and health, sessions, usage, agents, Connected) with no subscriber. AppState.Nodes stayed empty, so app.nodes returned [] and NetworkRecoveryTests timed out (main run 46499427168). After subscribing to a swapped-in client that is already connected, GatewayService now requests that snapshot again and clears the stale auth failure the lost Connected status would have cleared. The normal path, where the attach runs before the connect, sends nothing extra. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
e7519ef to
8538a2f
Compare
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
8538a2fd851887f18f959debb7ca7949cb9a7b60↑ Build, Shared (6179) and Tray (7087) suites passed. The dual-model review found no open MEDIUM or higher issue.
↑ CI run 46548316757 on this exact head passed on the first attempt, including Network recovery E2E (WSL Latest) and the new-and-changed test soak.
↓ That E2E ran without an injected late attach, so it shows no regression but does not reproduce the race.
↑ After 02.99 GatewayService wrote no further status, and no "Nodes x/y online" item appeared. The first restart, which reconnected without a rebuild, passed.
↓ The dropped NodesUpdated event is not logged directly. The UI-thread lag is inferred from the swap side-effect timestamps.
↓ No end-to-end reproduction. The local WSL E2E failed twice in SetupEngine before the tray launched, and the Crabbox hosts have no WSL.
What Problem This Solves
After the WSL Gateway restarts, Companion can show the Gateway as connected while its node list stays empty: this PC's node disappears from the tray, Systems pages and
app.nodesuntil something else changes. It happens when the automatic repair rebuilds the connection and the app's UI thread is briefly busy. It turned main red in run 46499427168 (NetworkRecoveryTests.RepeatedGatewayRestart_TrayAndNodeRecoverEachTime: "app.nodes never returned an online node with capabilities within 90s. Last response: []").User Impact
User impact: after a Gateway restart, the node list, gateway health, sessions, usage and agents come back even when the connection was rebuilt while the UI thread was busy, and an old sign-in error no longer stays on screen once the new connection is live.
Why This Change Was Made
The connection manager announces a new operator client before connecting it, but the app subscribes to it on the UI thread. When the restart repair rebuilt the client and the UI thread lagged by about 1.8 s, the client finished its handshake and published its first snapshot (including
node.list) before anything was listening. Nothing asked for it again, so the cached node list stayed empty.GatewayService.AttachClientnow checks, right after subscribing, whether the new client is already connected. If so, it asks again for the snapshot that was missed (nodes first, then health, sessions, usage and agents) and clears the stale sign-in error that the missed Connected status would have cleared. In the normal order, where the subscription happens before the connection, nothing extra is sent.Flake class: product race (class 10). Why now: the second restart in that run took 25 s instead of 18 s. That let the repair monitor's probe reach the Gateway before the old client's 8 to 9 s reconnect backoff, so the repair rebuilt the client instead of the old client reconnecting itself. The released Gateway (2026.11.12), WSL image and runner image are not implicated: the same run's first restart passed on the same inputs. 14-day history has no other real occurrence; the other hits on this job were build failures or the known no-log WSL cancel.
Sibling sweep and review
GatewayServiceis the only subscriber that writes these snapshot fields intoAppState. The other swap consumers (InboxGatewaySource, theme catalogs, usage provider) request their own data onSetConnection. The node-connected refresh inApp.OnNodeStatusChangedwas also lost, because it fired before the late subscription.Evidence
LateAttachToConnectedClient_RecoversTheNodeSnapshotPublishedBeforeSubscriptionfails becauseAppState.Nodesstays empty after attaching an already-connected client; the class's 7 other tests pass. On the final test revision e7519ef with onlyGatewayService.csreverted, 2 of 2 runs failed (screenshots 0 and 1) on Crabbox RTX 2 (ARM64,C:\oc\nrr-out\e75-red). Earlier test revisions also failed before the fix on RTX 1 (C:\oc\nrr-out\red3).C:\oc\nrr-out\e75).C:\oc\nrr-out\green3).Get-CiChangedTestsandInvoke-CiTestSoakpassed 10 of 10 runs at each screenshot setting, 3 of each under CPU burners. This ran locally on x64 under the desktop lock because the soak targets win-x64 and the ARM64 Crabbox hosts have no x64 .NET host../build.ps1: exit 0.dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj: 6179 passed, 0 failed, 29 skipped.dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj: 7087 passed, 0 failed.scripts/validate-test-timing-patterns.ps1: passed.git diff --check: clean.pair-node, then the Gateway wizard) before the tray launched, so they prove nothing either way. Both throwaway distros were removed. The Crabbox hosts have no WSL.Required proof pools
none: tray state publication after a client swap. No MXC, installer, GPU or interactive WinUI surface changed. The real-dispatcher UI test and the CI WSL network-recovery E2E cover it.