Skip to content

fix(cli): make nodespace uninstall stop the daemon and drop the autorun entry on Windows - #4248

Merged
mstomar125 merged 2 commits into
mainfrom
issue-4050-uninstall
Nov 5, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-4050-uninstall

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4050

What changed

  • nodespace uninstall on Windows no longer refuses; it now does the work: removes the HKCU\...\Run NodeSpaceDaemon value (reg.exe, presence checked first so "not present" is not an error), then stops the nodespaced.exe processes whose executable path is under this install's bin/bin-dev directories (PowerShell Get-CimInstance Win32_Process, Stop-Process, Wait-Process; names and directories are passed in environment variables so quoting cannot change the match), in packages/cli/src/commands/uninstall_windows.rs.
  • The user-home removal now returns the steps that failed; they fail the command (non-zero, no "NodeSpace uninstalled." line) together with any path that could not be removed (incomplete_message).
  • On Windows the bin directories are removed file by file (remove_tree_collecting), because remove_dir_all stops at the first locked file (for example the running nodespace.exe); only the files in use remain and each is named.
  • The autorun key/value names move to nodespace_proto::socket so the app and the CLI share one definition.
  • macOS and Linux behaviour is unchanged (their stop_daemon returns no problems).

Verification on the real Windows 11 PC

The CLI crate cannot build there (it depends on the daemon, which pulls the NLP engine and needs libclang), so a standalone harness compiled the real uninstall_windows.rs byte for byte and the real uninstall(), remove_bin_dir, remove_tree_collecting and stop_daemon text extracted from this branch, with a throwaway Run value (NodeSpaceVerifyTest) and a throwaway daemon image (nsverify-daemon.exe), plus a decoy of the same image name outside bin and a second process in bin standing in for the running nodespace.exe.

  • Before (old stub + remove_dir_all + unconditional success line): the daemon kept running, the Run value stayed, bin was not removed, the command printed "NodeSpace uninstalled." and exited 0.
  • After, with the second process locking a file in bin: stopped 1 daemon (the decoy outside bin and the other process were untouched), the Run value was removed, the daemon exe was removed, bin kept only the locked file, the command returned Err naming that file ("Access is denied. (os error 5)") and exited 1 with no success line.
  • After, nothing locked: stopped 1, Run value gone, bin gone, database preserved, success line printed, exit 0.
  • The PC scratch directories were removed and the real NodeSpaceDaemon value was never touched (none existed).

Tests (Mac)

  • cargo test -p nodespace-cli --lib commands::uninstall: 28 passed. New: uninstall_fails_and_names_a_step_that_could_not_complete, incomplete_message_lists_steps_and_paths, remove_tree_collecting_keeps_going_past_a_file_it_cannot_remove, remove_tree_collecting_removes_a_whole_tree_and_ignores_a_missing_one. The old Windows refusal test is removed with the refusal.
  • Mutation checks: dropping the steps from the message fails 2 tests; ignoring the steps in uninstall fails 1; breaking out after the first undeletable file fails the keep-going test.
  • cargo fmt --check and cargo clippy -p nodespace-cli -p nodespace-proto --all-targets -D warnings clean.
  • The Windows-only cargo check of nodespace-app-lib (which uses the moved constants) passed on the PC with the gnu toolchain.

What only a full Windows app run could prove

That nodespace.exe built from this branch, run from ~\.nodespace\bin against a real installed nodespaced.exe and the app's real autorun entry, behaves as the harness did (the real nodespaced.exe could not be built or run on the PC: no libclang). When the running nodespace.exe itself sits in bin it cannot delete itself; the command reports that file and the user removes it after the command exits.

Follow-up commit: the running executable

The usual Windows uninstall runs the staged nodespace.exe, which cannot be deleted while it runs. When that file is the ONLY path that could not be removed and no step failed, the command now hands it (and the bin directories) to a hidden helper (powershell.exe, CREATE_NO_WINDOW, own process group) that waits for the parent pid, deletes the file with retries, then the empty directories; it prints " is in use by this command and will be removed when it exits." and exits 0. Any other leftover, or a failed step, still exits 1 and names every path, the running file included. Also: reg.exe/powershell.exe are started from %SystemRoot%\System32; a reg query failure other than a missing value is reported (key must query OK, then value query exit 1 = absent); names and directories are passed newline-separated.

PC evidence (real Windows 11, the running image is the harness exe copied to bin and executed from there; the real uninstall_deferring, only_the_running_image_remains, remove_tree_collecting, uninstall_windows.rs text):

  • Running image only: child exit 0, message names the path, bin and the exe gone right after the child exited and still gone 4 s later, Run value removed, database kept, daemon stopped, decoy untouched.
  • Running image plus a second locked exe: exit 1, both paths named "Access is denied", nothing deferred, both files still there 4 s later.
  • remove_autorun: absent value gives Ok(false); a missing key gives an error carrying reg's message.

Tests (Mac): commands::uninstall 33 passed. New: only_the_running_image_remains_classifies_the_leftovers, uninstall_defers_the_running_image_when_it_is_all_that_is_left, uninstall_still_fails_when_something_else_is_left_beside_the_image, uninstall_does_not_defer_when_a_step_failed, uninstall_fails_when_the_deferred_removal_cannot_be_scheduled. Mutations caught: classification always true (2 fail), any single failure counts (1), extra failures allowed (2), defer despite a failed step (1). fmt and clippy -D warnings clean.

🤖 Generated with Claude Code

mstomar125 and others added 2 commits November 5, 2026 12:07
…orun entry on Windows

Replace the Windows refusal with a real uninstall: remove the HKCU Run
entry, stop the nodespaced.exe running from this install's bin/bin-dev
directories (matched by full executable path, then waited on), and remove
the install tree file by file so a locked executable is reported by name
instead of aborting the rest. Steps that fail are returned from the
user-home removal and fail the command with a non-zero exit and no success
line, together with any path that could not be removed.

The autorun key and value names move to nodespace-proto so the app and the
CLI share one definition. Non-Windows behaviour is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…table is left

The usual Windows uninstall runs the staged nodespace.exe, which Windows will
not delete while it runs, so the command always failed. When that file is the
only path that could not be removed and no step failed, hand it (and the bin
directories) to a hidden helper that waits for this process to exit and then
removes them, say so, and succeed. Any other leftover, or a failed step, still
fails the command, the running file included.

Also start reg.exe and powershell.exe from the system directory, report a
`reg query` failure other than a missing value instead of treating it as
absent, and pass image names and directories separated by newlines.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-4050-uninstall branch from 222bc7e to 4c81548 Compare November 5, 2026 11:07
@mstomar125
mstomar125 merged commit 46d3120 into main Nov 5, 2026
@mstomar125
mstomar125 deleted the issue-4050-uninstall branch November 5, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows nodespace uninstall leaves the daemon and HKCU Run autorun entry, then prints success

1 participant