Repository navigation
fix(setup): local gateway removal fails or leaves stale records during uninstall - #1954
Conversation
…g uninstall Uninstall-LocalGateway.ps1 assigned to $host and declared a $Home parameter. Both are read-only automatic variables, so Test-LocalGatewayUrl always returned false and Expand-ExecApprovalsHomePath always threw. With OPENCLAW_STATE_DIR set, the script exited 1 after wsl --unregister had already deleted the distro. Older local records stayed in gateways.json, and isLocal=false loopback records counted as external and kept root tokens. Rename both variables here and in the validate-wsl-gateway-uninstall.ps1 copy. Accept the expanded [::1] host that .NET Framework's Uri returns under Windows PowerShell 5.1. Add regression tests that load the production functions under 5.1, sharing the host previously private to UninstallOnboardingSettingsTests. Closes openclaw#1953
|
🦞👀 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 changesThe PR fixes PowerShell variable collisions and IPv6 loopback recognition so local Gateway uninstall completes its intended cleanup. Example: Uninstall removes OpenClawGateway with OPENCLAW_STATE_DIR set to ~/state.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain This PR fixes concrete uninstall failures still present on main, preserves the documented cleanup contract, and introduces no identified code defect. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe Inno uninstaller invokes the PowerShell cleanup script, which removes the selected WSL distro and then updates Windows-side gateway records, identities, credentials, and onboarding settings. flowchart TD
A[Inno uninstall choice] --> B[Migration preservation gate]
B --> C[PowerShell cleanup script]
C --> D[Selected WSL distro]
C --> E[Gateway registry and identities]
C --> F[Approval files and onboarding settings]
C --> G[Uninstall result]
Technical reviewBest possible solution: Land the focused helper repair after the required installer compatibility proof confirms intended cleanup and preservation. Do we have a high-confidence way to reproduce the issue? Main source establishes both reserved-variable failures, and the reporter supplies matching Windows PowerShell 5.1 output; this read-only review ran no reproduction. Is this the best way to solve the issue? Renaming the colliding variables and handling .NET Framework's expanded IPv6 host is the smallest complete repair within the existing cleanup owner, with distinct regression coverage. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a4dd026cc5f8. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
Review metrics
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 HistoryReview history (1 earlier review cycle)
Reviewed October 31, 2026, 6:06 PM ET / 22:06 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Closes #1953
What Problem This Solves
Fixes: removing the local WSL gateway during uninstall reports failure after the gateway is already deleted when
OPENCLAW_STATE_DIRis set, and leaves stale gateway records and tokens in other cases.User Impact
User impact: choosing to remove the local gateway now finishes cleanly when
OPENCLAW_STATE_DIRis set, and it removes older local gateway records instead of leaving Companion pointed at a deleted gateway.Behavior to review: three cleanup steps that never ran now run, each matching existing intent.
setupManagedDistroName, friendly nameLocal (<distro>), loopback URL) and their identity directories are removed.isLocal: falseloopback record may need to pair again.OPENCLAW_STATE_DIRset,exec-approvals.jsonin that directory is deleted.TrayArtifactCleanupalready does this on the C# uninstall path.Why This Change Was Made
Uninstall-LocalGateway.ps1assigned to$hostand declared a$Homeparameter. Both are read-only automatic variables in PowerShell, soTest-LocalGatewayUrlalways returned false andExpand-ExecApprovalsHomePathalways threw. This renames them, and applies the same rename to the copy invalidate-wsl-gateway-uninstall.ps1.Fixing the name exposed one more defect in the same check: Windows PowerShell 5.1 runs on .NET Framework, whose
Uri.Hostreturns[::1]in its expanded form, so IPv6 loopback still failed to match. The new test caught this, and the check now accepts that form.Evidence
Real script under Windows PowerShell 5.1, against a throwaway empty distro created with
wsl --import, withOPENCLAW_STATE_DIRset. The distro is really unregistered in both runs:a4dd026)gateways.jsonrecords leftmanagedexec-approvals.jsonleftuninstall-gateway-result.jsonsucceeded=False,Cannot overwrite variable Home...succeeded=True,Local WSL gateway '<distro>' removed.The new tests fail on
a4dd026for the intended reasons (6 of 6, for example every URL classifiedFalse, and2|True|0records instead of1|False|0), and pass with the fix.Through the real Inno uninstaller. Unsigned Dev-variant installers from
scripts/build-inno-local.ps1 -Dev, differing only in the script, withunins000.exe /VERYSILENTandOPENCLAW_STATE_DIRset. A registered throwawayOpenClawGateway-Devdistro was really removed in both runs, next to one managed, one remote and one SSH-tunneled record:a4dd026script)cleanup script exited with code 1,continuing without deleting generated stateexited with code 0,completed successfully,Deleted generated app stateactiveIdactiveIdclearedTheme,EnableNodeMode)Tokeninsettings.jsonexec-approvals.json(state dir and app data)Existing data.
RegistryCleanup_LeavesUnrelatedRecordsLoadableByGatewayRegistrywrites a registry with the productionGatewayRegistry, runs the cleanup under Windows PowerShell 5.1, and reloads it withGatewayRegistry. The remote record (non-ASCII name, shared token,lastConnected, V2 flag) and the tunnel record (SSH config, browser port) come back equal, the active record stays, and only the managed identity is gone. This cleanup already rewritesgateways.jsonfor current managed records; this PR adds no new stored format or field.Change Type
Scope
winnodeRequired proof pools
windows-clean-installer-upgrade: the uninstall path changed. Not run here; it needs exact signed artifacts.Validation
Run on
a4dd026plus this change. Windows 11 x64 build 26200, tr-TR, .NET SDK 10.0.402../build.ps1: all builds succeeded (Shared, WinUI, SetupEngine, Cli, WinNodeCli), documentation validation passed.dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore, with theOPENCLAW_TRAY_*data directories isolated, including the new compatibility test: 4806 passed, 0 failed, 0 skipped.dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj: 4806 passed, 2 failed, 26 skipped. This PR changes no Shared code or Shared tests, and both failures come from this host:ExecReusableCommandBinderTests.PinnedCarrier_IgnoresShadowInsertedAfterApproval: expects the computer name truncated to 15 characters, and this host's name is longer.MxcFolderAdmissionTests.OwnedJunctionAndSymbolicLinkAreRejectedWithoutFollowingTheirChildren(symbolic: True): the account does not hold the symbolic link privilege.git diff --check: clean.validate-wsl-gateway-uninstall.ps1has 0 parse errors under PowerShell 7. It has 4 under Windows PowerShell 5.1 on this host, the same 4 without this change, so that script was not run end to end.The harness that loads production functions from the script moved from
UninstallOnboardingSettingsTestsintoUninstallScriptHostso the new tests reuse it. Those existing tests still pass.Real Behavior Proof
47ca09d; the later commit on this PR adds only a test. CI on the PR head is the current-head result.wsl --importof an empty rootfs as a uniquely named distro, setOPENCLAW_STATE_DIR,OPENCLAW_TRAY_DATA_DIRandOPENCLAW_TRAY_LOCAL_DATA_DIRto temp folders, seedgateways.json, device key andexec-approvals.json, then run the real script withpowershell.exe -File scripts/Uninstall-LocalGateway.ps1 -AppRoot <temp> -DataDirectoryName OpenClawProof -AutoStartName <fake> -StartupTaskName <fake> -DistroName <distro>. The same run was repeated with the script froma4dd026. No other distro was touched.isLocal: falseloopback record no longer counts as external, so root tokens are cleared.Yes/No/N/A): N/Awindows-clean-installer-upgrade). The Inno run above is unsigned, on the Dev identity, so it skips the Store migration check.Security Impact
No)Yes)No)No)No)Yes, explain the risk and mitigation: root device tokens are now cleared at uninstall when only local or loopback records remain, as the README documents. This removes credentials rather than keeping them. The cost is that a remaining loopback gateway may need to pair again.Compatibility and Migration
Yes)No)No)Review Conversations