Skip to content

fix: keep this PC's node listed after a Gateway restart rebuilds the connection - #2416

Merged
bkudiess merged 1 commit into
openclaw:mainfrom
bkudiess:bkudiess/flake-network-recovery-restart
Dec 1, 2026
Merged

bkudiess merged 1 commit into
openclaw:mainfrom
bkudiess:bkudiess/flake-network-recovery-restart

Conversation

@bkudiess

@bkudiess bkudiess commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 8538a2fd851887f18f959debb7ca7949cb9a7b60

Dimension Assessment Rationale
Change confidence 9/10 ↑ The regression test fails without the product change and passes with it on the real WinUI dispatcher (latest test revision: RED 2/2, exact-head lane 10/10, soak 20/20 with 6 runs under CPU burners).
↑ 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.
Diagnosis confidence 9/10 ↑ The failing run's tray log shows a full client rebuild at 20:00:07.716, hello-ok at 08.17, node registration at 09.14, and the UI-thread swap side effects only at 09.50.
↑ 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.
Evidence fit 8.5/10 ↑ It explains the exact symptom: app.nodes stayed [] for 90 s while app.status reported Connected and nodeConnected=true.
↓ 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.nodes until 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.AttachClient now 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
  • Same path: GatewayService is the only subscriber that writes these snapshot fields into AppState. The other swap consumers (InboxGatewaySource, theme catalogs, usage provider) request their own data on SetConnection. The node-connected refresh in App.OnNodeStatusChanged was also lost, because it fired before the late subscription.
  • Hanselman dual review (claude-opus-5.5 and gpt-6-astra long_context, high effort) on base 3670fcd, with delta re-reviews:
    • Opus MEDIUM: the late attach also lost health and the Connected status, and my comment wrongly said health was polled. Fixed: health added back and the stale sign-in error cleared.
    • Opus LOW: request nodes first; don't pin request order; deliver the reply through the queued dispatcher path. Fixed.
    • Astra MEDIUM: the test reply relied on the thread pool, which could starve under the soak. Fixed with a dedicated thread.
    • Final delta: no findings from either model.

Evidence

  • RED (before the fix): the new test LateAttachToConnectedClient_RecoversTheNodeSnapshotPublishedBeforeSubscription fails because AppState.Nodes stays empty after attaching an already-connected client; the class's 7 other tests pass. On the final test revision e7519ef with only GatewayService.cs reverted, 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).
  • GREEN:
  • Soak (e7519ef): Get-CiChangedTests and Invoke-CiTestSoak passed 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.
  • Local closeout:
    • ./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.
  • Not verified:
    • The WSL network-recovery E2E was not re-run with an injected late attach. I wrote an env-gated, uncommitted injection that delays the UI-thread client attach by 5 s. Both local runs (Gateway 2026.11.12) failed in SetupEngine (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.
    • CI run 46548316757 on head 8538a2f passed every job on the first attempt, including Network recovery E2E (WSL Latest) without injection.

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.

@clawsweeper

clawsweeper Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

🦞👀
Pull request received.

ClawSweeper review complete

ClawSweeper finished reviewing this revision.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. impact:session-state This issue is about session, memory, transcript, context, or agent state drift. clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 30, 2026
@clawsweeper

clawsweeper Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codex review: passed.

What this changes

This 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.

  • Before: Companion reports Connected, but app.nodes remains [] after missing the initial node.list publication.
  • After: Late subscription requests node.list again and publishes the returned node inventory.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, worthwhile repair with a credible dispatcher regression; the specific late-attach recovery has supporting harness evidence rather than demonstrated real-client execution.
Proof confidence 🦐 gold shrimp (3/6) The maintainer proof exemption applies; supplied RED/GREEN evidence exercises GatewayService with a proxy on the native dispatcher, and ordinary network-recovery CI passed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: After Gateway restart recovery, Companion can show Connected while this PC disappears from the node inventory.
Reason: Recovering the missed snapshot restores existing behavior, and the maintainer-authored PR establishes direction without introducing a new product option.

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: 130ebc4f04aebad0a7bf481064c7b88a6a683dd0

Before merge

None.

Findings

None.

Agent review details

How this fits together

GatewayConnectionManager 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]
Loading

Technical review

Best 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

  • GatewayService client subscription and AppState publication keeps the original intent (cff1033: The service extraction centralized Gateway subscriptions and observable application state, as recorded in Introduce single AppState model + service extractions #423.)
  • UI-thread client attachment keeps the original intent (0b31e21: The lifecycle-hardening commit added dispatcher enforcement before changing subscriptions and service state; this patch retains that boundary.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned diff adds post-subscription recovery in GatewayService and one regression in the existing dispatcher test class; no other production owner changes. (src/OpenClaw.Tray.WinUI/Services/GatewayService.cs:97, 130ebc4f04ae)
  • Reachable subscription gap: The manager announces its new client before connecting it, while App queues the subscription work onto the UI dispatcher. (src/OpenClaw.Tray.WinUI/App.xaml.cs:2568, 130ebc4f04ae)
  • Existing readiness and snapshot contract: IsConnectedToGateway requires an authenticated current socket, and the existing post-handshake burst already requests health, sessions, usage, nodes and agents; the patch reuses those supported operations. (src/OpenClaw.Shared/OpenClawGatewayClient.cs:529, 130ebc4f04ae)
  • Focused regression: The added test drops a publication before attachment, delivers the replacement reply from a worker thread through the real dispatcher, checks recovered nodes and cleared auth error, and verifies that a not-yet-connected client sends no extra requests. (tests/OpenClaw.Tray.UITests/GatewayServiceSessionPublicationTests.cs:81, 130ebc4f04ae)
  • Validation and its limits: The PR reports baseline failures, native-dispatcher GREEN runs, and successful build, Shared and Tray suites. GitHub confirms successful changed-test soak and network-recovery E2E checks for the reviewed head; other lanes remain pending. The E2E job log download was blocked at its artifact host, so its detailed execution receipt was not inspected. (130ebc4f04ae)
  • Current main and discussion: The default branch remains at the pinned base without this recovery. The discussion contains bot status comments and no contrary product decision; the author association is COLLABORATOR. (fd600e4c4cf2)

Likely related people:

  • Ranjesh Jaganathan: Raw commit cff1033 adds src/OpenClaw.Tray.WinUI/Services/GatewayService.cs:50 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cff1033b3bb3; files: src/OpenClaw.Tray.WinUI/Services/GatewayService.cs)
  • Scott Hanselman: Raw commit 0b31e21 adds src/OpenClaw.Tray.WinUI/Services/GatewayService.cs:52 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0b31e210a421; files: src/OpenClaw.Tray.WinUI/Services/GatewayService.cs)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 30, 2026, 4:54 PM ET / 21:54 UTC.

@bkudiess
bkudiess force-pushed the bkudiess/flake-network-recovery-restart branch from 130ebc4 to e7519ef Compare December 1, 2026 00:48
…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>
@bkudiess
bkudiess force-pushed the bkudiess/flake-network-recovery-restart branch from e7519ef to 8538a2f Compare December 1, 2026 00:49
@bkudiess
bkudiess merged commit caa94d5 into openclaw:main Dec 1, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:session-state This issue is about session, memory, transcript, context, or agent state drift. P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant