Repository navigation
upgrade: stop the background service before replacing the binary on Windows - #103
Merged
Merged
Conversation
…indows Windows won't replace an .exe a running process has open, so upgrading while the background service ran failed with EPERM, left the old version in place and still exited 0. The npm install and autter upgrade now stop the service first, swap the binary, restart the service if it was running, and exit non-zero with a clear message if the swap still fails. Pushed for CI without the full local test run (owner's request). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- binary_swap: a Windows-only unit test on the real file system renames a running exe (a copy of PING.EXE) aside, replaces it and removes the leftover once the process exits; a file held without delete sharing fails with the in-use message and stays in place. - windows-e2e.ps1: new `upgrade` section. The npm bootstrapper's swap runs over autter.exe while the background service runs it (service stopped, swapped, started again as a new process); over a running exe (renamed aside); over a held file (non-zero exit naming the cause and the fix, old file kept); and install.ps1 runs over the running service. - Messages suggest `autter bg restart`, the project's canonical command (fixes the lib test that forbids `autter bg start` in user-facing text). - CHANGELOG [Unreleased] entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A tester reported that on Windows the npm upgrade fails quietly while the background service runs: EPERM, the old version stays, and it exits 0. Running
autter bg shutdownfirst fixed it.Cause
Windows won't replace or delete an
.exethat a running process has open, and the background service runs~/.autter/bin/autter.exe. Each upgrade path handled that differently:npm/install.jspostinstall):renameSync(tmp, dest)failed with EPERM, the fallbackrmSync(dest)failed the same way, andmain()treated the error as transient. It printed a warning and returned, so npm exited 0 and the old binary stayed. The launcher (bin/autter.js) then tried again on every run, failed, and ran the old binary.autter upgrade(Windows): it stopped the service, startedinstall.ps1in a detached PowerShell and exited 0 straight away. The PowerShell wrapper also caught the installer's error and exited 0, so a failure only showed up in~/.autter/upgrade-logs. The service was not started again afterwards.install.ps1: it stopped the service, waited up to 300 s for the file (killing every autter/git process from that folder after 20 s), and then ranMove-Item. It failed loudly on timeout, but it did not start the service again unless the service had started the upgrade itself.What changes
All three paths now do the same thing on Windows:
autter bg shutdowndoes, and wait briefly for it to release the file..exeaside toautter.exe.old(Windows allows this;autter.exe.<pid>.oldif an older one is still running) and move the new binary in. If that fails, move the old one back..oldfiles that nothing runs any more. This happens straight away when possible, otherwise on the next install/upgrade or when the service next starts (run_daemon).If the swap still fails, the install exits non-zero. The message says the file is in use and gives the fix: run
autter bg shutdown, then try again. The previous version stays installed and working. If the new binary doesn't run (--versioncheck), the previous one is put back.npm/install.js:replaceBinary/finishInstall/installDownloadedBinary, with the fs and process calls injectable. ASwapErrornow fails the postinstall (exit 1) instead of being deferred to the launcher. Other download errors are still deferred, as before.src/commands/binary_swap.rs(new):run_installer_with_binary_asideover aSwapHosttrait. On Windows,autter upgradenow runsinstall.ps1attached (-File, no transcript wrapper), waits for it, exits with its result and refreshes agent hooks the way Unix already did. The service's own silent self-upgrade stays detached, but its wrapper now exits 1 on failure.install.ps1:Stop-ServiceForReplace,Install-ExecutableFile(rename-aside with rollback, also used for thegit.exeshim),Restore-PreviousExecutableandRemove-LeftoverExecutables.Start-DaemonIfRequestednow also runs when the installer stopped a running service. It no longer force-kills arbitrary autter/git processes, since rename-aside makes that unnecessary.Tests
binary_swap): the swap logic against a fake Windows file system. Covered: rename-aside then restart on the new binary; a service that wasn't running is not started; a file in use gives a non-zero error with the fix and leaves the old binary; a failed installer puts the old binary back; an installer that left no binary; a failure after the new binary is in place; a numbered aside name; leftover detection. A Windows-only test does the same on the real file system with a running copy ofPING.EXEand a file held without delete sharing.npm/install.test.js): the same cases for the npm swap. The postinstall rejects onSwapErrorand still defers network errors. A real-filesystemensureBinaryrun with a Windows-style EPERM injected.scripts/windows-e2e.ps1, newupgradesection on real Windows: the npm swap overautter.exewhile the service runs it (stopped, swapped, running again as a new process). A swap over a running exe (renamed aside, leftover removed after it exits). A swap over a held file (non-zero exit, names the cause and the fix, old file unchanged).install.ps1from the local build over the running service (stops it, installs, starts it again).tests/windows_install_script.rs(Windows-only, not run in CI): static checks updated.autter upgradeend to end, because it needs a published release and the API. Its Windows logic is covered by thebinary_swapunit tests, including the real-filesystem one.🤖 Generated with Claude Code