Repository navigation
fix: gateway remove and switch fail after setup is closed - #1864
Conversation
Native setup writes the gateway list from its own registry instance. Closing the setup window without Open left the running tray on the old list, so the next save failed and a removed gateway returned after restart. Adopt the saved list on setup close when this session has no unsaved edits. Remove and save in one step and restore the row if the save fails. A failed switch still restores the previous active gateway and now raises the error the connection page already shows. Signed-off-by: Sebastien Tardif <[email protected]>
The setup-close adopt, the remove rollback, and the switch error stay. ConnectionPage, WindowManager, and the contract tests had moved on main. Signed-off-by: Sebastien Tardif <[email protected]>
|
🦞👀 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 real behavior proof before merge. What this changesRefresh the tray’s saved gateways after setup closes, reconcile the live connection, and preserve gateway state when removal or switching cannot be saved. Example: Setup makes Adopted side record active while the tray is connected to Fixture Gateway.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain This PR repairs a source-verifiable bug still present on current main, preserves the existing ownership boundaries, and has no identified correctness findings. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherSetup and the tray use separate registry instances backed by gateways.json; WindowManager coordinates setup cleanup, GatewayRegistry owns persistence, and GatewayConnectionManager owns live connections. flowchart TD
Setup[Setup registry] --> Disk[gateways.json]
Close[Setup window closes] --> Window[WindowManager]
Disk --> Registry[Tray GatewayRegistry]
Window --> Registry
Window --> Manager[GatewayConnectionManager]
Registry --> Page[Connection page]
Page --> Manager
Technical reviewBest possible solution: Land guarded setup-close adoption and transactional gateway actions through the existing registry and connection owners. Do we have a high-confidence way to reproduce the issue? Source establishes that setup can update the shared registry file while the tray retains its previous persistence baseline, causing later saves to reject the changed file; no current-main reproduction was run. Is this the best way to solve the issue? The patch addresses the stale registry at setup cleanup, reuses existing snapshot validation and conditional connection teardown, and keeps failed persistence from appearing successful. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2ff4d168588d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed November 2, 2026, 6:34 PM ET / 23:34 UTC (Revision 3). |
…w list Signed-off-by: Sebastien Tardif <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review Head f475b9c loads a stable-shaped gateways.json from v2026.9.8-1 and adopts that file on setup close. The saved gateway and its identity file stay in place. The signed v2026.9.8-1 installer was checked and was not launched, because it writes the real local and roaming profile. |
|
🦞👀 Re-review progress:
|
|
I'm a Copilot triage agent, not Scott. Thanks for the isolated setup-close proof. Main has since changed the connection manager and window/page owners touched here, so the green CI predates their integration. Could you update this branch from main and rerun the checks when you have a chance? That will give us coverage of the current combined behavior. |
|
Updated this branch onto current main so the connection manager and window owners from main are in this build. On efb9f56, build.ps1 exited 0, shared tests passed 4831 (24 skipped), and tray tests passed 4835. |
PR cleanup reviewReviewed head: Thanks for the setup-close repair. I compared efb9f56 with main e59374c: setup close still omits catalog adoption, removal is still separate from persistence, and switch-save failure still returns silently. Your complete patch applies cleanly and its hosted CI Gate passes. This is a strong bounded candidate, but the visible workflow evidence in the body is for f475b9c. Before landing, we need the current-main integration reviewed and the setup-close/remove/switch workflow verified on that exact head. The diff does not change the registry format; the earlier upgrade request should be dispositioned separately rather than treated as a demonstrated migration defect. Action in this cleanup pass: leaving this PR open. No branch changes or runtime-proof waiver. The findings above come from source, discussion and recorded-CI review; Windows validation was not rerun in this pass. |
|
Verified head efb9f56 without another merge. An isolated tray opened setup on its own. Closing that window without finishing the wizard logged On this head the connection tests passed 5. Remove restores the record when the save fails. A switch whose save fails throws and keeps the previous active gateway. |
|
I'm a Copilot triage agent, not Scott. Thanks, Seb. Your update addresses the earlier adoption, UI-thread wait, recovery-message and removal-ordering concerns. I added maintainer commit Validation on the committed source (ARM64):
Test-report and quiet-output flags are omitted from the table. The focused conditional-disconnect selection passed all six cases with no skips. The stale-same-gateway regression failed before its fix; a separate failed-native-stop regression failed before the published-snapshot comparison. Cases also cover node-only replacement, completed disconnect and device-ID updates. Independent source review and a bounded rubber-duck review are complete. Current-source real-app proof: repeated with fresh isolated profiles in Debug and unsigned non-Dev Release. In each already-connected app, I opened setup, used the production registry writer externally to add gateway B and make it active, then closed setup without continuing. Computer Use observed The Release fixture used the documented The previous overnight hold is superseded by this evidence and the small patch. Required CI passed on |
A missing or unreadable gateways.json stays out of memory, and the file lease wait runs off the UI thread. Unsaved edits raise the existing recovery notice. Remove saves before it disconnects, so a failed save leaves the live connection up. A device-id update no longer keeps the previous gateway connected after setup close. Signed-off-by: Sebastien Tardif <[email protected]>
A missing or unreadable gateways.json no longer replaces a loaded list, so closing setup cannot disconnect the live gateway just because the file is gone. An existing well-formed file is still adopted, because this close path does not have a separate expected snapshot. Known pipeline output still goes through ReconcileSetupOutcome. The lease wait is off the UI thread. Unsaved edits show the existing recovery notice. Remove saves before it disconnects, so a failed save leaves the connection up. A device-id update no longer blocks that disconnect. Isolated tray on |
Preserve snapshot generations across metadata updates, reject superseded same-gateway connections, and keep failed unpublished teardown retryable. Cover operator, node-only, disconnect and native-stop failure boundaries. Co-authored-by: Copilot App <[email protected]>
Closes #1673
What Problem This Solves
Fixes: closing setup without Open leaves Remove gateway and the active-gateway switch failing until the tray is restarted.
User Impact
User impact: after setup closes, the running tray uses the saved gateway list. A failed remove puts the row back. A failed switch restores the previous gateway and shows the connection error.
Why This Change Was Made
Native setup writes the gateway list from its own registry. The tray kept its old copy, so the next save saw a changed file and failed. Setup close now adopts the saved list when this session has no unsaved edits, then reconciles the live connection through the existing setup-close path. If the active gateway changed, the previous connection is disconnected only when it is still the current one. Remove and save is one step and restores the row if the save fails. A failed switch still restores the previous active gateway and raises the error the connection page already shows.
This branch was merged onto current main. The adopt, the remove rollback, and the switch error are unchanged.
Evidence
On head
f475b9c48514bc49faae07587532714978df46a0, an isolated fixture tray connected to its gateway, opened setup, and then adopted a token-free gateway written beside it. Closing setup reloaded the list and left the page disconnected. Remove deleted that side record. Connect on the original row completed a new handshake.The signed stable installer
OpenClawCompanion-Setup-x64.exefrom releasev2026.9.8-1is product version2026.9.8-1. Authenticode status isValid. Signer isCN=OpenClaw Foundation. It was not launched.installer.issinstalls under{localappdata}and also writes{userappdata}and a WSL directory under{localappdata}.GatewayRecordis unchanged since tagv2026.9.8-1.GatewayRegistry.Loadon this head read a stable-shapedgateways.jsonforws://127.0.0.1:9namedProof gateway. The shared token was still the value written in that file. The identity filedevice-key-ed25519.jsonkept sha256EDDE9B9F92FFDD9DE012B1EC20BB762995620928F8D090125302C5407FACC92C. A second registry loaded an empty list, thenTryAdoptExternalSnapshotreturned true for that same file. The same record was active, and the identity hash did not change.Head efb9f56
Isolated tray of this head,
OPENCLAW_SKIP_UPDATE_CHECK=1, empty data directory. The setup window opened by itself. It was closed without finishing the wizard. The log recordedGateway list refreshed after setup closed.That process had no TCP connection to port 18789. The stable installer was not launched, and no hand-written gateways.json was used.On this same head,
dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --filter FullyQualifiedName~TryAdoptExternalSnapshot|FullyQualifiedName~RemoveAndSave|FullyQualifiedName~SwitchGatewayAsync_SaveFailurepassed 5. Remove rolls the in-memory list back when the save fails. A switch whose save fails throws and keeps the previous active gateway.Head 4055bcc
Isolated tray of this head,
OPENCLAW_SKIP_UPDATE_CHECK=1, empty data directory. The setup window opened by itself (OpenClaw Setup, pid 20704). It was closed without finishing the wizard. The log recordedGateway list refreshed after setup closed.That process had no TCP connection to port 18789. The stable installer was not launched, and no hand-written gateways.json was used.A missing or unreadable saved list no longer replaces a registry this session already loaded. Unsaved edits raise the existing recovery notice. Remove saves before it disconnects. A device-id update of the connection snapshot still disconnects that same gateway.
./build.ps1exited 0. Shared tests passed 5761 (27 skipped). Tray tests passed 6277. Connection tests for adopt, remove, and the device-id disconnect passed 10.Change Type
Scope
winnodeRequired proof pools
Validation
./build.ps1 -Project Traysucceeded on headf475b9c48514bc49faae07587532714978df46a0.Real Behavior Proof
4055bcc2, isolated fixture profile, synthetic loopback gateway. The signed stable installer was not launched.4055bcc2f94ab694da80de2754d2cb88d07c1629openclaw://setupto that process. Write a token-free gateway namedAdopted side recordintogateways.jsonand make it active. Close the setup window. Open Connection. Remove that side record. Connect the original fixture row.gateway connected, waiting for challenge...at 10:47:36 andHandshake complete (hello-ok)at 10:47:36.Opened tray-hosted setup windowat 10:47:58.Gateway list refreshed after setup closed.at 10:48:19.app.connection.statusthen reportedIdle/Disconnected, with the active nameAdopted side record. UI Automation readConnectionPageMarkerNot connected, saved rowsFixture Gateway (4c34b551)andAdopted side record, each withSavedGatewayConnectAction. After Remove,Adopted side recordwas gone and one row remained. Connect on the fixture row logged a new challenge at 10:49:03 andHandshake complete (hello-ok)at 10:49:03. The status marker readConnected, andapp.connection.statusreportedReady/ConnectedforFixture Gateway (4c34b551).v2026.9.8-1installer. That would replace the real profile.Security Impact
Compatibility and Migration
Review Conversations