Skip to content

Removing the local gateway at uninstall fails or leaves stale state: script assigns to read-only PowerShell variables #1953

Closed

Description

@MertBasar0

Summary

Choosing Yes to "remove the OpenClaw local WSL gateway" during uninstall can report failure after the gateway is already gone, and can leave stale gateway state behind. scripts/Uninstall-LocalGateway.ps1 uses two names that PowerShell reserves as read-only automatic variables, so two of its helpers never work.

Cause

Location Code Effect
Test-LocalGatewayUrl (line 282, since #591) $host = $uri.Host.ToLowerInvariant() Throws Cannot overwrite variable Host. The surrounding catch returns $false, so every URL is classified as not local.
Expand-ExecApprovalsHomePath (line 185, since #1051) param([string]$Path, [string]$Home) Throws Cannot overwrite variable Home on every call. It is only called when OPENCLAW_STATE_DIR is set.

The same $Home parameter is copied in scripts/validate-wsl-gateway-uninstall.ps1:237.

What users see

  • OPENCLAW_STATE_DIR set in the environment: the cleanup that throws runs after wsl --unregister. The distro is deleted, the script exits 1, and the uninstaller shows "OpenClaw could not remove the local WSL gateway". The gateway record, root device tokens and exec-approvals.json stay on disk. From the script's flow, Retry cannot succeed because it reaches the same throw.
  • Older local gateway record without setupManagedDistroName: the script prints "removed successfully", but the record stays in gateways.json as activeId and its identity directory stays. Companion then points at a gateway that no longer exists.
  • isLocal: false record with a loopback URL: it is treated as external, so root device tokens are kept. The README says they are cleared unless an external record remains.

Reproduce

I ran the real script under Windows PowerShell 5.1 on main a4dd026 (Windows 11 x64, build 26200) against a throwaway empty distro from wsl --import, with OPENCLAW_STATE_DIR set:

distro registered before uninstall script: True
script exit code: 1
script output: WARNING: Cannot overwrite variable Home because it is read-only or constant.
distro registered after uninstall script: False
gateways.json ids left: [managed]
identity dir left: True
root tokens left: True
legacy exec-approvals.json left: True
result.json: succeeded=False message=Cannot overwrite variable Home because it is read-only or constant.

The two root causes alone reproduce in any Windows PowerShell 5.1 or PowerShell 7 session:

function A { param([string]$Home) }; A 'x'
# Cannot overwrite variable Home because it is read-only or constant.

Notes

  • I did not run this through the full Inno uninstaller or with a real Gateway inside the distro. The dialog text and Retry behavior above come from reading installer.iss and the script.
  • I found no existing issue or PR for this. PR fix(setup): delete only generated uninstall children #1521 (fix(setup): delete only generated uninstall children) edits the same file but not these lines.

I have a fix with regression tests ready and will open a PR.

Activity

  1. added
    clawsweeper:intake:bug
    clawsweeper:intake:needs-environment
    P0
    clawsweeper:linked-pr-open
    clawsweeper:no-new-fix-pr
    clawsweeper:source-repro
    impact:session-state
    impact:ux-release-blocker
    issue-rating: 🦞 diamond lobster
    and removed
    clawsweeper:intake:bug
    clawsweeper:intake:needs-environment
    on Oct 31, 2026
  2. clawsweeper commented on Oct 31, 2026

    @clawsweeper

    Codex review: this still needs some work.

    Summary
    Current main still contains both PowerShell variable collisions, and the author’s open fixing PR explicitly closes this issue.

    Reproducibility: Current source establishes both reserved-variable failures and their cleanup consequences; the reporter also supplies Windows PowerShell 5.1 output, but this review ran no reproduction or tests.

    Next step
    Review the linked fix PR and verify successful cleanup plus in-product retry through the Inno uninstaller before this issue closes.

    Security
    None.

    Review details

    Best possible solution:

    Complete the linked repair with idempotent cleanup and a working in-product retry that needs no manual state edits.

    Do we have a high-confidence way to reproduce the issue?

    Current source establishes both reserved-variable failures and their cleanup consequences; the reporter also supplies Windows PowerShell 5.1 output, but this review ran no reproduction or tests.

    Is this the best way to solve the issue?

    Renaming the colliding variables and covering production helpers under Windows PowerShell 5.1 is a focused repair; the linked PR already owns it.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • Full Inno uninstall and recovery behavior has not been demonstrated through the signed installer.
    • The repair must preserve genuine external and SSH-tunneled gateway records and their credentials.

    Codex review notes: model internal, reasoning medium; reviewed against a4dd026cc5f8.

    Label changes

    Label changes:

    • add P0: The ordinary uninstall flow can delete the gateway, fail its cleanup, and offer a Retry that repeats the same failure without an in-product recovery path.
    • add impact:session-state: Legacy local gateway records and activeId can remain pointed at an unregistered distro.
    • add impact:ux-release-blocker: Recovering the requested clean uninstall requires environment or state changes outside the uninstall UI.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:linked-pr-open: Current issue advisory state selects this label.
    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.

    Label justifications:

    • P0: The ordinary uninstall flow can delete the gateway, fail its cleanup, and offer a Retry that repeats the same failure without an in-product recovery path.
    • impact:ux-release-blocker: Recovering the requested clean uninstall requires environment or state changes outside the uninstall UI.
    • impact:session-state: Legacy local gateway records and activeId can remain pointed at an unregistered distro.
    Evidence reviewed

    What I checked:

    • Current default branch: GitHub main and the review checkout both resolve to a4dd026. (a4dd026cc5f8)
    • Home parameter aborts cleanup: Expand-ExecApprovalsHomePath declares the read-only automatic variable Home as a parameter. OPENCLAW_STATE_DIR makes this function reachable; artifact cleanup calls it before gateway registry and root-token cleanup, after distro removal. (scripts/Uninstall-LocalGateway.ps1:185, a4dd026cc5f8)
    • Loopback classification fails: Test-LocalGatewayUrl assigns to the read-only automatic variable Host and catches the error as false. Both legacy managed-record matching and external-record classification depend on this helper. (scripts/Uninstall-LocalGateway.ps1:282, a4dd026cc5f8)
    • Documented cleanup contract and recovery: README promises removal of the selected gateway identity and clearing root tokens unless external records remain. The installer offers Retry or Cancel after failure; retrying an already absent distro still enters the same broken cleanup. (installer.iss:685, a4dd026cc5f8)
    • Existing regression coverage misses these helpers: UninstallOnboardingSettingsTests executes selected production reset functions under Windows PowerShell 5.1, excluding URL classification and approval-path resolution; InstallerIssAssertionTests largely checks script text. (tests/OpenClaw.Tray.Tests/UninstallOnboardingSettingsTests.cs:117, a4dd026cc5f8)
    • Open fix owns the repair: fix(setup): local gateway removal fails or leaves stale records during uninstall #1954 (fix(setup): local gateway removal fails or leaves stale records during uninstall) is open, authored by the reporter, and explicitly closes this issue. It reports before/after Windows PowerShell 5.1 execution against a throwaway WSL distro, while acknowledging full Inno proof remains unverified. (47ca09ddfa92)
    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; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed October 31, 2026, 2:26 PM ET / 18:26 UTC.

  3. added a commit that references this issue on Nov 5, 2026
    78d08e4
  4. locked as resolved and limited conversation to collaborators on Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0clawsweeper:linked-pr-openclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:session-stateimpact:ux-release-blockerissue-rating: 🦞 diamond lobster

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions