Skip to content

Add uninstall choice for local WSL gateway - #591

Merged
ranjeshj merged 2 commits into
openclaw:masterfrom
ranjeshj:fix/uninstall-gateway-choice
May 29, 2026
Merged

ranjeshj merged 2 commits into
openclaw:masterfrom
ranjeshj:fix/uninstall-gateway-choice

Conversation

@ranjeshj

Copy link
Copy Markdown
Contributor

Summary

This changes the Windows installer uninstall flow so users explicitly choose whether the local WSL gateway should be removed.

  • Adds an interactive uninstall prompt for the local OpenClawGateway WSL distro.
  • Keeps uninstall silent-safe: silent uninstall removes the local gateway automatically.
  • Avoids launching OpenClaw tray/setup binaries from {app} during uninstall, preventing install-directory file locks.
  • Uses direct WSL cleanup (--terminate, --shutdown, --unregister) and waits synchronously before uninstall continues.
  • Preserves generated gateway state when the user selects No so the registered WSL distro is not partially deleted.
  • Cleans setup-managed Windows-side artifacts after gateway removal: gateway records, identity directories, root device tokens when no external gateways remain, setup/run/keepalive markers, autostart, logs, and onboarding settings.
  • Adds installer/script structural assertions to guard the uninstall contract.

Screenshots

Standard uninstall confirmation

Standard uninstall confirmation

New local gateway choice prompt

Local gateway choice prompt

Gateway removal progress

Removing local WSL gateway

Completion dialog

Uninstall complete

Verification

Automated validation:

  • ./build.ps1
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore
  • PowerShell parser validation for scripts/Uninstall-LocalGateway.ps1
  • Targeted InstallerIssAssertionTests
  • ARM64 Inno compile:
    • ./scripts/build-inno-local.ps1 -Arch arm64 -Fast -Version 0.0.0-local -NoPublish

Real installer smoke validation with disposable temp install roots and a disposable imported OpenClawGateway WSL distro:

  • Silent uninstall: removed the WSL distro, install/generated state, setup-managed gateway record, identity directory, root tokens, settings, logs, and markers.
  • Interactive No: showed the gateway prompt, skipped gateway cleanup, preserved the registered disposable WSL distro and generated gateway state, and removed installed app files.
  • Interactive Yes: showed the gateway prompt, removed the WSL distro, removed install/generated state, and cleaned gateway records/tokens/settings/logs.
  • Dialog capture smoke: repeated the interactive Yes flow and saved the cropped screenshots above.

Cleanup checks after smoke validation:

  • No disposable OpenClawGateway distro remained.
  • No test installer registration remained.
  • The pre-existing openclaw:// protocol registration was restored after each smoke run.

Prompt users during uninstall before removing the local WSL gateway and route the uninstall through a direct WSL cleanup helper so OpenClaw binaries are not launched from the install directory.

The helper unregisters OpenClawGateway, cleans setup-managed gateway artifacts, and preserves generated gateway state when the user declines removal.

Co-authored-by: Copilot <[email protected]>
@clawsweeper

clawsweeper Bot commented May 29, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed May 29, 2026, 5:55 PM ET / 21:55 UTC.

Summary
The PR replaces the Inno [UninstallRun] gateway cleanup hook with [Code]-driven interactive/silent cleanup, rewrites Uninstall-LocalGateway.ps1 to unregister the local WSL gateway directly, adds structural assertions, and adds uninstall screenshots.

Reproducibility: not applicable. as a bug reproduction; this PR changes installer behavior. The PR body plus inspected screenshots give a high-confidence behavior path for the prompt/progress/completion flow, while cleanup postconditions are supported by contributor smoke notes.

Review metrics: 2 noteworthy metrics.

  • Files Changed: 7 files: 3 text files plus 4 screenshots. The patch combines installer logic, a rewritten cleanup helper, test assertions, and proof assets.
  • Cleanup Helper Size: 79-line wrapper replaced by 625-line direct cleanup script. The uninstall behavior now lives in a much larger PowerShell implementation that deserves maintainer ownership review.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Risk before merge

  • [P1] The PR intentionally moves destructive uninstall behavior from SetupEngine into an installer-owned PowerShell path that unregisters WSL and edits/deletes gateway identity and token state; unit tests do not fully settle that ownership choice.
  • [P1] I did not execute the Windows installer in this read-only Linux review, so runtime confidence relies on the contributor's real smoke notes plus the inspected screenshots.

Maintainer options:

  1. Accept Direct Cleanup With Proof (recommended)
    Merge if maintainers are comfortable that the posted installer smoke coverage and structural assertions are enough for the WSL unregister and credential cleanup path.
  2. Ask For Independent Windows Smoke
    Request or run one maintainer-side disposable WSL uninstall smoke that confirms distro removal, gateways.json, identity tokens, and the preserved No flow.
  3. Pause For SetupEngine Ownership
    Pause if maintainers want all uninstall artifact cleanup to remain in SetupEngine instead of maintaining a parallel PowerShell implementation.

Next step before merge

  • [P2] No narrow code repair remains; maintainers should decide whether to accept this security-sensitive direct uninstall cleanup path and then use normal merge validation.

Security
Cleared: No concrete security regression was found after the reparse-point guard was added, but the destructive uninstall path remains a maintainer-visible security-boundary merge risk.

Review details

Best possible solution:

Land the interactive uninstall flow once maintainers accept the installer-owned direct cleanup path, keeping the reparse-point guard and silent/Yes/No smoke coverage as the merge standard.

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

Not applicable as a bug reproduction; this PR changes installer behavior. The PR body plus inspected screenshots give a high-confidence behavior path for the prompt/progress/completion flow, while cleanup postconditions are supported by contributor smoke notes.

Is this the best way to solve the issue?

Yes, with maintainer acceptance: copying the helper to {tmp} and using direct WSL cleanup is a maintainable way to avoid install-directory file locks, and the reparse-point guard now protects the app-owned WSL directory. The remaining question is ownership of duplicated cleanup logic rather than a line-level defect.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 64b650cb3313.

Label changes

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): The PR includes inspected screenshots of the changed uninstall UI and reports real installer smoke validation for silent, interactive No, and interactive Yes flows.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a normal-priority installer UX and cleanup improvement with limited blast radius but meaningful uninstall impact.
  • merge-risk: 🚨 security-boundary: The PR changes a destructive path that unregisters a local WSL distro and edits/deletes gateway identity and token state.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): The PR includes inspected screenshots of the changed uninstall UI and reports real installer smoke validation for silent, interactive No, and interactive Yes flows.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR includes inspected screenshots of the changed uninstall UI and reports real installer smoke validation for silent, interactive No, and interactive Yes flows.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR includes inspected screenshots of the changed uninstall UI and reports real installer smoke validation for silent, interactive No, and interactive Yes flows.
Evidence reviewed

Acceptance criteria:

  • [P1] ./build.ps1.
  • [P1] dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore.
  • [P1] dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore.
  • [P1] PowerShell parser validation for scripts/Uninstall-LocalGateway.ps1.
  • [P1] Targeted InstallerIssAssertionTests.

What I checked:

  • Repository policy read: Read the full target AGENTS.md; its gateway/installer validation guidance applies, but this review stayed read-only and did not run build/test commands that create artifacts. (AGENTS.md:1, 64b650cb3313)
  • Current main behavior: Current master still uses [UninstallRun] to launch Uninstall-LocalGateway.ps1 from {app} and then deletes {app} through [UninstallDelete], so the new interactive choice is not already on main. (installer.iss:94, 64b650cb3313)
  • PR installer path: The PR moves uninstall handling into [Code], prompts non-silent users with Yes/No, copies the helper to {tmp}, waits synchronously, and only deletes generated app state after successful gateway cleanup. (installer.iss:94, 59f373a11975)
  • Reparse-point repair verified: The latest PR helper refuses to recursively delete the app-owned wsl\OpenClawGateway directory when it is a reparse point, addressing the previous review blocker. (scripts/Uninstall-LocalGateway.ps1:540, 59f373a11975)
  • Structural coverage: The updated installer assertions pin the prompt, silent cleanup, direct WSL unregister path, removal of the old CLI wrapper path, and the reparse-point guard string. (tests/OpenClaw.Tray.Tests/InstallerIssAssertionTests.cs:78, 59f373a11975)
  • Proof inspected: Downloaded and inspected the posted screenshots; they show the standard uninstall confirmation, the new local WSL gateway choice prompt, gateway removal progress, and completion dialog. The PR body also reports silent, interactive No, and interactive Yes installer smoke validation. (docs/images/uninstall-local-gateway-choice.png, 59f373a11975)

Likely related people:

  • ranjeshj: Prior current-main history shows Ranjesh on the SetupEngine redesign and recent installer uninstall cleanup, both central to this PR's behavior. (role: recent area contributor; confidence: high; commits: cefce3952ab1, 191f4d6f86cd; files: src/OpenClaw.SetupEngine/SetupSteps.cs, src/OpenClaw.SetupEngine/TrayArtifactCleanup.cs, installer.iss)
  • Scott Hanselman: Git history shows Scott introduced the local Inno installer helper and primary installer path that this PR modifies. (role: installer path introducer; confidence: medium; commits: 006fcd288b43, aaf50b758504, 5a555abf9e4c; files: installer.iss)
  • Mike Harsh: History shows Mike introduced the WSL gateway uninstall feature and related docs/scripts/tests that form the older behavior this installer hook replaced. (role: original uninstall feature contributor; confidence: medium; commits: 223db1fb847e; files: scripts/Uninstall-LocalGateway.ps1, docs/uninstall-portable.md, tests/OpenClaw.Tray.Tests/LocalGatewayUninstallTests.cs)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

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.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. labels May 29, 2026
Refuse recursive gateway directory deletion when the target is a junction or symlink, matching the SetupEngine safety guard and preventing cleanup from crossing outside the app-owned WSL directory.

Co-authored-by: Copilot <[email protected]>
@ranjeshj

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review please. I added a reparse-point guard before recursive deletion of the app-owned WSL gateway directory and pinned it with installer assertion coverage. Validation rerun: PowerShell parser, targeted InstallerIssAssertionTests, ./build.ps1, Shared tests, Tray tests, reparse-point dry-run, and ARM64 Inno compile all passed.

@clawsweeper

clawsweeper Bot commented May 29, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper assist is taking a look at your question.

I queued a lightweight read-only assist pass. It will post a separate answer comment and will not edit the durable ClawSweeper review comment or trigger close, merge, repair, label, or branch changes.

Request: re-review please. I added a reparse-point guard before recursive deletion of the app-owned WSL gateway directory and pinned it with installer assertion coverage. Validation rerun: PowerShell parser, targeted InstallerIssAssertionTests, ./build.ps1, Shared tests, Tray tests, reparse-point dry-run, and ARM64 Inno compile all passed.

@clawsweeper

clawsweeper Bot commented May 29, 2026

Copy link
Copy Markdown

ClawSweeper assist: This needs a full correctness re-review, not a lightweight Q&A answer. The supplied context shows the prior blocker was the missing reparse-point guard, and the PR now has a new commit claiming to add that guard plus assertion coverage.

Evidence:

Suggested next action: Use @clawsweeper review on #591 so ClawSweeper can inspect the new diff and update the prior findings.


Source: #591 (comment)
Assist model: gpt-5.5, reasoning low.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels May 29, 2026
@ranjeshj
ranjeshj merged commit 8af4b70 into openclaw:master May 29, 2026
10 checks passed
natalie-aguinaldo added a commit to natalie-aguinaldo/openclaw-windows-node that referenced this pull request Sep 23, 2026
Real uninstall proof on a guest without WSL surfaced two pre-existing
defects in the gateway cleanup helper, both dating to openclaw#591. Neither was
reachable before, because earlier proof runs declined gateway removal and
never executed this branch.

wsl.exe writes UTF-16LE on many Windows builds while the redirected pipe is
decoded as 8-bit, so captured output arrived NUL-interleaved. Every pattern
in Test-DistroNotFound matched against that text and none could ever fire,
leaving the "already unregistered" success path unreachable in practice.
Strip NUL in the captured output instead of pinning an encoding that varies
by Windows version.

A host with no WSL, or with WSL but no distributions, cannot be holding our
gateway. Treat both as nothing to remove rather than surfacing "OpenClaw
could not remove the local WSL gateway. Exit code: 1", which offered Retry
against a condition no retry can fix.

The new test executes the real functions extracted from the script rather
than asserting on source text, since a source-text contract cannot detect
an encoding defect. Reverting either half fails it.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a
karkarl pushed a commit that referenced this pull request Sep 25, 2026
…e gateway on uninstall (#1461)

* feat(migration): checkpoint Inno preservation and gated Store startup

Add protected migration records, read-only source inventory, completion-aware Inno safeguards, exact installation discovery, and disabled-by-default Store startup admission. Consent, adoption, and finalization remain future work. Local build, focused tests, and x64 fixture proof passed before checkpoint; structured review remains deferred.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: a91896be-e75b-4a88-932e-61b78125ab4a

* feat(migration): add Store consent and close-Inno retry preview

Keep the preview build-time gated and read-only. Consent only observes the Inno mutex and stops before adoption, completion, uninstall, or normal startup. Required validation and x64 packaged VM proof passed; structured review remains deferred.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: a91896be-e75b-4a88-932e-61b78125ab4a

* feat(migration): prepare Inno state under exclusive ownership

Co-authored-by: Copilot <[email protected]>

Copilot-Session: a91896be-e75b-4a88-932e-61b78125ab4a

* feat(migration): record validated Store completion

Co-authored-by: Copilot <[email protected]>

Copilot-Session: a91896be-e75b-4a88-932e-61b78125ab4a

* feat(migration): finalize Store adoption after verified Inno removal

Co-authored-by: Copilot <[email protected]>
Copilot-Session: a91896be-e75b-4a88-932e-61b78125ab4a

* fix(migration): serialize uninstall and scope process inspection

Hold the migration operation lock across Inno removal and cleanup, and re-detect the source under the completion lock. Use limited-information process queries to exclude proven unrelated processes while failing closed on uncertain source candidates. Add regression coverage and document the ownership guarantees.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: a91896be-e75b-4a88-932e-61b78125ab4a

* fix(migration): preserve completion across clock rollback

Keep completed-receipt reads independent of the current wall clock while retaining write-time timestamp checks, intent policy, and all binding and structural validation. Add backward-clock regressions through the codec, Windows PowerShell checker, and cleanup preservation path.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: a91896be-e75b-4a88-932e-61b78125ab4a

* fix(migration): exclude source runtime across Windows sessions

Hold an Inno runtime reader until process exit and validate source activity under Store's exclusive migration lock. Share process inspection, preserve fail-closed startup guidance, and cover contention, exit, and completion retry.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(migration): disclose consent consequences in every locale

Explain protected migration records, the Inno startup block after successful validation, manual source uninstall, and the Store restart requirement. Clarify retry guidance and cover all six locales with disclosure regression tests.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(migration): simplify preview Yes and No wording

Remove action legends and refer directly to native Yes/No buttons in all six locales without changing consent or retry semantics.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* test(migration): preserve timeout diagnostics and terminate child processes

Keep the existing 30-second deadline and parallel test execution. Run fixture scripts noninteractively, terminate timed-out child trees before teardown, and retain the original timeout when cleanup or diagnostic capture fails. Add synchronized parent/child regressions including an unreadable diagnostic log. This hardens the test harness without claiming to resolve the original CI-only timeout.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* test(migration): synchronize timeout fixture with a named event

Replace the readiness-file handshake that hit a sharing violation on a Windows CI runner. Signal a named event after diagnostic output is written, and pass the child PID through stdout. This fixes the regression fixture only; the original cleanup timeout remains unresolved.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(migration): fail closed on unverifiable migration receipts

Harden the Inno-to-Store migration safety path against outcomes that
previously authorized destructive gateway cleanup on incomplete evidence.

- Treat a present-but-unverifiable completion receipt as "preserve", not
  "absent". Only FileNotFoundException/DirectoryNotFoundException exit 0;
  every other validation failure exits 2.
- Bound every child process wait in both shipped scripts via a shared
  Start-BoundedProcess helper built on ProcessStartInfo, and retain the
  checker's diagnostics instead of discarding them.
- Launch the checker watchdog through the explicit System32 Windows
  PowerShell path, since $PSHOME under PowerShell 7 has no powershell.exe.
- Narrow the destructive admission phase to Enter-DestructivePhase so
  pre-destructive failures report uncertainty rather than completion.
- Route installer exit code 2 to preservation instead of a retry prompt,
  renumber internal failure codes to 102/103, and keep the cleanup script
  installed so the uninstaller no longer names a file it deletes.
- Allow startup after a failed or refused startup preference, and show a
  user-visible notice when Windows durably refuses the startup task, since
  only the user can re-enable it.

Validation: build.ps1; Shared 4087 passed; Tray 3098 passed;
Connection 1072 passed. Watchdog timeout and admission-phase mutation
proofs run locally.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(migration): stop migration state from blocking startup and uninstall

Migration coordination is preview-only, but its lock sat outside the preview
gate on two ordinary paths. An unreadable prepare.lock refused to launch the
app and aborted the uninstaller outright, for users who never migrated.

- Inno startup now blocks only when the lock is genuinely contended, which
  proves a live migration. Any other acquisition failure logs and continues,
  because an unreachable lock says nothing about migration. The completion
  receipt check below remains authoritative and still fails closed.
- InitializeUninstall never returns False for inaccessible migration state.
  Only a contended lock stops an uninstall; otherwise removal proceeds and
  destructive gateway cleanup is suppressed instead. The reparse-point check
  stays sequential so a rejected path can never reach ForceDirectories.
- Apply directory security on create or on drift rather than on every
  acquisition, so an ordinary launch no longer needs WRITE_DAC/WRITE_OWNER.
- Make preservation self-contained: the notice now names the in-app removal
  path and the wsl --unregister command instead of pointing at documentation
  the uninstaller does not link, and the silent path logs the preserved
  distro and directory for enterprise audit.
- Document the installer preservation case and why no override is offered.

Validation: build.ps1; Shared 4087 passed; Connection 1075 passed;
Tray 3100 passed. ActivationRouterTests passed 5/5 on this head, consistent
with a baseline flake rather than a regression from this branch.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(migration): bound the preservation checker and stop stranding helpers

The checker exists because Add-Type can stall on a contended %TEMP% or an
antivirus scan, and installer.iss waits for it with ewWaitUntilTerminated.
Falling back to the inline check when the watchdog could not start
reintroduced exactly that unbounded stall. Report the uncertain verdict
instead; exit 2 already fails closed and preserves the gateway.

The three uninstall helpers also carried uninsneveruninstall, but they run
during usUninstall, which happens before Inno removes files. Generated
app-state deletion only runs after successful gateway cleanup, so any
uninstall that kept the local gateway, including the ordinary "No" choice
unrelated to migration, left executable helpers behind in the former app
directory.

The retained-helper contract test pinned the flags it should have rejected,
so it is inverted rather than deleted.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(migration): scrub foreign grants from the migration directory DACL

RequiresHardening skipped re-hardening whenever the DACL was protected and
owned by the current user, without inspecting what those rules granted. A
pre-existing store-migration directory can satisfy both conditions and still
carry an Allow rule for an unrelated principal.

That principal could delete completed.dpapi. Test-InnoMigration.ps1 maps a
missing receipt to "no migration happened" and exits 0, which authorizes
destructive local gateway cleanup during uninstall. The same receipt gates
ordinary Inno startup.

Before the hardening shortcut landed, SetAccessControl ran on every
acquisition and would have removed such a grant. Restore that guarantee
without reintroducing per-launch DACL churn by re-hardening only when a rule
falls outside the owner, LocalSystem, and BuiltinAdministrators.

RepeatAcquisition_LeavesAnAlreadyHardenedDirectoryUntouched used an
Everyone: Read ACE as its no-rewrite canary, which is the grant this change
must scrub. Its canary is now a trusted principal with distinct inheritance
flags, so it still proves the absence of churn.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(uninstall): treat a WSL-less host as nothing to remove

Real uninstall proof on a guest without WSL surfaced two pre-existing
defects in the gateway cleanup helper, both dating to #591. Neither was
reachable before, because earlier proof runs declined gateway removal and
never executed this branch.

wsl.exe writes UTF-16LE on many Windows builds while the redirected pipe is
decoded as 8-bit, so captured output arrived NUL-interleaved. Every pattern
in Test-DistroNotFound matched against that text and none could ever fire,
leaving the "already unregistered" success path unreachable in practice.
Strip NUL in the captured output instead of pinning an encoding that varies
by Windows version.

A host with no WSL, or with WSL but no distributions, cannot be holding our
gateway. Treat both as nothing to remove rather than surfacing "OpenClaw
could not remove the local WSL gateway. Exit code: 1", which offered Retry
against a condition no retry can fix.

The new test executes the real functions extracted from the script rather
than asserting on source text, since a source-text contract cannot detect
an encoding defect. Reverting either half fails it.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(migration): reject foreign mutating grants on the uninstall receipt

The Inno uninstall checker decided whether to clean up gateway state based
on a receipt file it did not verify it could trust. A non-trusted principal
who could write the receipt (or its directory) could suppress or forge the
cleanup decision.

Trust is now established before the receipt is read:

- Owner must be the current user, SYSTEM, or Administrators.
- Any foreign Allow ACE that can mutate the receipt breaks authority.
  Read/list grants are tolerated, since installer.iss creates the state
  directory with plain ForceDirectories and inheritable read ACEs are
  common in managed fleets.
- Generic rights (GENERIC_ALL, GENERIC_WRITE) count as mutating. They
  intersect no named FileSystemRights bit but the kernel maps them onto
  FILE_ALL_ACCESS / FILE_ADD_FILE, so a named-bit mask alone missed them.
- Inherit-only ACEs are skipped; they do not apply to the object itself.

When authority cannot be established the checker exits 2 and the uninstaller
preserves state, rather than silently proceeding.

Also replaces Get-Acl and Get-ChildItem with .NET types throughout. The
uninstaller launches PowerShell in a constrained environment where
Microsoft.PowerShell.Security fails to autoload, which made the check throw
for every user and strand cleanup unconditionally.

Residual, deliberately not sealed: a receipt file's own owner can grant
itself DELETE and remove the receipt without altering the directory, which
leaves nothing observable to the checker. Inherited Modify grants held by a
domain administrators group will likewise strand cleanup rather than
authorize it. Both fail closed.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(uninstall): stop quoting wsl.exe control flags

Real VM proof on Windows 11 24H2 with WSL 2.7.14 showed every wsl.exe
call in the gateway cleanup failing with exit 127:

  wsl.exe --list --quiet exited 127.
  /bin/sh: --list: not found

wsl.exe matches its control flags against the raw command line and does
not strip quotes, so a quoted "--unregister" is not recognized as a flag
and is executed as a command inside the distro instead. The gateway
distro was therefore never unregistered, and uninstall reported
succeeded=false with exit 127.

This regressed in 6a8aede, which replaced Start-Process -ArgumentList
(an array, never quoted) with ProcessStartInfo (a single string) and
quoted every argument to build it. The migration-checker call site was
unaffected because it already passes bare flags and quotes only values.

Quote only values that need it. The escaping rules for values that do
need quoting are unchanged, including doubling trailing backslashes.

Reproduced independently against real WSL on a developer host:
  wsl.exe --list --quiet       -> exit 0, lists distros
  wsl.exe "--list" "--quiet"   -> exit 127, /bin/bash: --list: not found

Proof: real WSL2 gateway cleanup in a Hyper-V VM, before and after.
  before: exit 127, "Failed to unregister WSL distro", still registered
  after:  exit 0, "Local WSL gateway removed", unregistered,
          unrelated bystander distro preserved, second run idempotent

The new contract test executes the real function rather than asserting
on source text, matching the existing WSL-less-host test. Source-text
assertions cannot catch an argv-shape bug. Verified non-vacuous: the
previous implementation turns --list into "--list" and fails it.

Validation: build.ps1, Shared 4087 passed, Tray 3103 passed.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(migration): require package absence before authorizing gateway cleanup

The Inno uninstaller decided whether it could destroy the local WSL gateway
from a single signal: the migration completion receipt. Deleting that receipt
made a completed handoff indistinguishable from no migration, and the checker
returned the cleanup-authorizing exit 0. A cleanup utility sweeping stale
AppData, or an attacker, could therefore arrange for the uninstaller to delete
the gateway the Store app was actively using. Silent uninstall destroys on
exit 0 with no prompt at all.

Add a second, independent signal. Cleanup is now authorized only when the
receipt is absent AND the packaged-app registration is absent:

- Get-StorePackageState returns Present, Absent, or Indeterminate rather than
  a boolean, because the caller has to say something truthful to the user.
- New exit 11 means the Store app is registered without a valid receipt:
  preserve, and tell the user explicitly not to run wsl --unregister.
- An unreadable or empty Packages key is treated as tampering, not absence.
  That key is user-writable and every real profile has hundreds of subkeys,
  so an empty enumeration cannot be evidence that nothing is installed.

Exit 2 reaches the same preserve decision but previously told the user to run
wsl --unregister, which destroys exactly what was just preserved. That advice
is reachable on a machine that has already migrated, through an undecryptable
receipt after a DPAPI master key loss, a watchdog that cannot start or times
out, an Add-Type failure, an unavailable migration lock, or a missing
PowerShell. StoreAppRegistered in installer.iss now gates the message itself,
so every route to that single advice site is covered rather than the one
branch where the checker managed to report exit 11.

Destruction is still authorized only by exit 0. Package presence changes what
the user is told, never what is deleted.

Accepted residual, documented in the checker: a same-user attacker who deletes
only the OpenClawFoundation.OpenClaw_* subkey and leaves the rest can still
reach exit 0. Closing that needs a signal outside the user's write scope, and
%ProgramFiles%\WindowsApps cannot serve because an unelevated process may not
enumerate it.

Validation: build.ps1, Connection 1113, Shared 4087, Tray 3106, all green.
The new guard is mutation-checked: removing it fails both contract tests.
installer.iss compiles under ISCC. Runtime VM proof of the regression and the
security property is still outstanding and is tracked for this PR.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

* fix(installer): report an unreadable package registry as uncertain

The uninstall path collapsed three distinct states into one boolean, so an
unreadable or empty Appx package registry produced a dialog asserting that the
Store app is installed and is using the gateway. That claim is unknown, and it
contradicted scripts/Test-InnoMigration.ps1, which deliberately models
Present, Absent, and Indeterminate as separate results.

StoreAppRegistered is now StorePackagePresence, returning the same three
states. A new ReportStoreAppStateUnknown preserves the gateway, makes no
ownership claim, withholds the destructive wsl --unregister advice, and names
the distro and preserved path in its log.

Also addresses three review findings on that change:

- Destructive unregister advice was the unguarded fall-through, so any
  unexpected presence value routed to data-loss guidance. Preservation is now
  the default and only a positively observed Absent reaches that advice.
- Inserting the new procedure widened the slice of
  Installer_DoesNotAdviseUnregisteringWhenTheStoreAppOwnsTheGateway, which
  stopped isolating the ownership message. The slice now terminates at the new
  procedure.
- The unknown-state log omitted the distro name and path, leaving an
  incomplete silent-uninstall audit trail.

Validated: build.ps1, Shared 4087 passed, Tray 3107 passed,
InnoMigrationContractTests 43/43, and an ISCC compile of installer.iss
(mutation-verified that the compile actually rejects bad Pascal).

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a

---------

Co-authored-by: Copilot <[email protected]>
Copilot-Session: a91896be-e75b-4a88-932e-61b78125ab4a
Copilot-Session: d5c700f0-7fa2-46ed-bd1a-10a11521b63a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P2 Normal priority bug or improvement with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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