Repository navigation
fix(installer): close only this user's copy of the app from this install folder, without tasklist or taskkill - #720
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved process-identity and window-ownership races can terminate or close unrelated applications, and per-user installs can also close a machine-wide copy they do not replace.
3 open issues
What changed in this PR
This PR replaces shell-based process checks in the Windows installer and uninstaller with Windows API calls, aiming to close only the current user’s app copies from the relevant install folders while preserving session helpers.
Changes:
- Adds process scanning, window-close requests and bounded waits before forced termination.
- Makes Retry repeat the check and silent runs cancel when a matching copy remains.
- Adds static guards and Windows behavioral probes for both installer passes.
| File | Description |
|---|---|
tests/unit/main/installer-nsis-behaviour.test.ts |
Adds sandboxed app stand-ins and probes for closing and preserving processes. |
tests/unit/main/installer-branding-guard.test.ts |
Adds static checks for process filtering, shutdown sequencing and register preservation. |
CONTEXT.d/2026-11-18-installer-app-check-toolhelp.md |
Documents the implementation, test coverage and remaining release checks. |
build/installer.nsh |
Replaces tasklist/taskkill with scoped process scanning and shutdown logic. |
Review effort: Balanced
…all folder, without tasklist or taskkill customCheckAppRunning, which electron-builder inserts in both passes, no longer runs tasklist and a bare taskkill /im. Over a non-interactive sign-in both answer "Access denied", so the check found and closed nothing there, and an elevated run asked every signed-in user's copy to close. A Toolhelp scan (CccScanAppCopies) keeps only processes with one of the app's own image names that run as this copy's user and whose program file is in $INSTDIR, or, in the installer pass, in the folder of the install this run replaces. CccCloseAppCopies posts WM_CLOSE to their top-level windows, waits up to 5 s looking every 250 ms, then ends the ones still running through a handle held across a same-user, same-start-time check. aicc-helper.exe is never looked at, so held terminals live through an install. The Retry and Cancel box stays: Retry runs the whole check again, Cancel still restores the install location, and a silent run cancels instead of waiting on a box. Tests: installer-branding-guard.test.ts pins the rules statically (no tasklist, taskkill, WMI or PowerShell; red before at :716, :720, :733). installer-nsis-behaviour.test.ts runs the real macros in both passes (the uninstaller pass with /WX) against running stand-ins on CI. Plan: 2.1.3-beta.8 section C3 (aicc_planning #319). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ke the replaced folder from this hive's record Answers the three review threads on the app-running check: - The scan holds one handle to each candidate from before its user check until its start time is read, and reads the program file through that handle, so the user, the file and the start time are one process's. - WM_CLOSE: the windows are listed as "window:pid", and just before each post the window must still be that pid's and the pid, held open, must still have the start time the first look recorded. A pid or a window handle that passed to another program gets nothing. CccNextPair reads these lists (and the "pid:start" one for the ends). - The replaced install's folder comes from its uninstall record in SHELL_CONTEXT, the record uninstallOldVersion runs next, not from customInit's capture, which falls back to the other hives and so can name an all-users install that a per-user run never touches. Tests: the static guards follow the new code; the probe gains a case where only another hive records an install (its copy keeps running), and both macro lists take CccNextPair. On the VM all 40 probe cases pass and seven mutants each go red, the cross-hive capture among them. Plan: 2.1.3-beta.8 section C3 (aicc_planning #319). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…stop a run that cannot check Review findings on PR #720 (plan 2.1.3-beta.8 section C3, #319). - In a run someone can see, a copy that was asked to close and is still open after 5 s is not ended: the app shows its save dialog on WM_CLOSE, and ending it then lost the answer and the app's teardown. The box asks the user to answer it and Retry. Silent runs still end it. - Each WM_CLOSE now re-checks the window's owner last, after the pid and start time. The posts are counted, or the log says no window could be reached (a remote or scheduled sign-in). - CccProcessIsMine answers 1, 0 or 2 (not known). The log gives the true reason a process is left alone. Every older caller tests for 1, so the helper clean-up is unchanged. - When the installer is not elevated, a copy from this folder whose user cannot be read counts as still running and is never ended. - Every end is logged, success or not, and a last look writes what is still running. The answer is 0, 1 or 2: a check that could not run (own user or snapshot unreadable) no longer reads as "none running"; an OK and Cancel box asks, and a silent run stops. - A run that stops logs why, restores the install location (installer pass) and exits with code 2. The box names no single image name. - Comments: register rules for CccNextPair and CccScanAppCopies; the sibling-folder limit; the elevated-copy claim reworded. - Tests: static pins for all of the above; probe cases for a copy that stays open (seen and silent), and a copy that starts after the first look, which stops the run, restores the location and exits 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nubbymong
force-pushed
the
fix/installer-app-check-toolhelp
branch
from
November 18, 2026 13:42
a1af40d to
83851fd
Compare
…before reading it The pid file can exist before its number is in it; reading it then gave pid 0, which the clean-up would try to end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nubbymong
added a commit
that referenced
this pull request
Nov 18, 2026
…'s app check (#720) C3 (#720) merged after this PR was built; beta is merged in. What's New gains one fix line: the installer closes only your own copy from the folder being installed, leaves other users' copies and the session helper alone, waits while the app shows its save dialog, and a silent install no longer waits on a box nobody can see. It promises no graceful close over a remote sign-in, where the copy is ended after the wait. The Feature Guide's installer paragraph gains the matching sentence (answer the dialog, then Retry). Both are pinned. CHANGELOG.md regenerated. 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.


What and why
aicc_planning #319.
customCheckAppRunninginbuild/installer.nshfound the app withtasklistand closed it with a baretaskkill /im. Over a non-interactive sign-in (SSH, a scheduled task) both answer "Access denied" (the VM measurement recorded atCccScanProcesses), so the check found and closed nothing there. As administrator,taskkill /imasked every signed-in user's copy to close.Now, in both passes (electron-builder inserts the hook at the top of the install section and in the uninstaller's
un.checkAppRunning):Find.
CccScanAppCopies(a sibling ofCccScanProcesses) takes one Toolhelp snapshot. It keeps a process only when all of these hold:${APP_EXECUTABLE_FILENAME},Claude Command Center.exe,Claude Conductor.exe);CccProcessIsMine, with$R6read the wayCccEndUserHelpersreads it);QueryFullProcessImageNameW) is$INSTDIR\<name>, compared throughCanonPathPair(case, slashes and 8.3 names make no difference). In the installer pass,<folder of the replaced install>\<name>also counts (see "Decisions").Each candidate is held open (
PROCESS_QUERY_LIMITED_INFORMATION) from before its user check until its start time is read, and its image path is read through that same handle, so the user, the path and the start time all belong to one process. Any other process with the same name is left running, and the details log gives the true reason: it could not be opened, it is another user's, its program file could not be read, or it runs from another folder.CccProcessIsMinenow answers 1 (this user's), 0 (another user's) or 2 (not known). No other image name is ever looked at, soaicc-helper.exeand the terminals it holds keep running (B2).Ask.
CccCloseAppCopieslists the top-level windows those pids own (FindWindowExW,GetWindowThreadProcessId) aswindow:pid. Before eachWM_CLOSEit checks that the pid, held open, still has the start time the first look recorded, and then, as the last step before the post, that the window is still that pid's. The log says how many windows were asked, or that none could be reached.Wait. Up to 5 s, scanning every 250 ms.
End, or not.
WM_CLOSEwith its own save dialog when sessions are open (window-close-coordinator.ts,App.tsx), and ending it 5 s later lost that answer and the app's teardown. The box asks the user to answer the dialog and Retry; the secondWM_CLOSEcloses the app at once.PROCESS_TERMINATE | PROCESS_QUERY_LIMITED_INFORMATION) and, while holding it, re-checks that the process is this user's and has the same start time. Only then does it callTerminateProcesson that handle. Every outcome is logged. It then waits up to 2 s more.Last look. It logs what is still running and answers in
$R0: 0 none, 1 still running, 2 could not be checked. When the installer is not elevated, a process from this folder whose user cannot be read (most likely this user's copy started as administrator) also counts as still running, and is never asked to close or ended. Every other register is saved and restored.The boxes. 1: the Retry and Cancel box ("If it is asking whether to save your sessions, answer it first. Otherwise close it yourself."), with no single image name in it. Retry runs the whole check again. Cancel still calls
CccRestoreInstallLocationin the installer pass. 2: an OK and Cancel box ("Could not check whether AI Code Conductor is running ..."); before, the run went on as if nothing were running. A silent run answers Cancel to both. A run that stops logs why ("... so nothing was installed" or "removed") and exits with code 2. "No copy ... is running ... Proceeding." is written only after a check that ran. The commit point is unchanged and still follows.KillIfRunningis gone. No tasklist, taskkill, WMI, PowerShell ornsExecis used anywhere in the check.-WX in both passes. The new macros (
CccScanAppCopies,CccCloseAppCopies, and the list readerCccNextPair) declare noVarand noFunction. In both passes they use onlyCanonPathPair's scratch, whichcustomHeaderdeclares in both. The replaced install's record ($cccRecordUninstaller, throughCccGetInQuotes) andCccRestoreInstallLocationare used only inside!ifndef BUILD_UNINSTALLER. Both hook labels are jumped to in both passes. The uninstaller-pass probe compiles with/WX.Unchanged: the helper clean-up (
RemoveUserHelperFolderand its macros: every caller ofCccProcessIsMinethere tests for 1, so its new answer 2 acts as 0 did, and a static test pins that), the pages, the branding, the install folder logic and the commit point.Decisions (please check)
SHELL_CONTEXTnames, read at the check. That is the recorduninstallOldVersionruns next, or, for a legacy tree beside$INSTDIR, the one the commit point drops before the sweep removes that tree.$cccLegacyUninstaller(the first push used it).customInitfalls back to the other hives for that variable, as the sweep's proof of ownership, so on a per-user run it could name an all-users install that this run never touches. Copilot's review point; fixed in the second commit.$INSTDIR.$INSTDIRonly.RemoveLegacyInstall, once proved) is not closed when no record in this hive names that folder; the sweep then cannot remove its files.IDRETRYjumped past the re-check and carried on. Now it runs the whole check again./SD IDCANCELon the boxes. A silent run now cancels instead of showing a box nobody can answer. Over SSH or from a scheduled task, that box held the install forever. electron-builder's own check uses the same default. The cancel is now logged and exits with code 2 (SetErrorLevel 2, in every run, not only silent ones: a cancelled run installed nothing).TerminateProcess. In a run someone can see, a copy that was asked and is still open is now left for the user and the box; silent runs, and copies noWM_CLOSEreached, are still ended after the wait.Tests
tests/unit/main/installer-branding-guard.test.ts, run on the host through the locked runner:installer.nsh(a1af40d, rebased as 0ebcfea): 10 failed, 37 passed (47). The 10 failures are the 4 new tests (three-wayCccProcessIsMine, the true reasons in the log, the silent-run gate, the last look and its answer) and 6 updated ones (the hook body, the scan, theWM_CLOSEorder and count, the logged ends, the registers, the labels under -WX).installer.nshfrom 29b2356): 8 failed, 35 passed (43). The no-tasklist test failed on exactly line 716 (tasklist), line 720 (taskkill /im) and line 733 (tasklist).$INSTDIR\<name>; the three-way user answer and its older callers; each logged reason;WM_CLOSEonly to listed windows, the window owner re-checked last; the count line; the one silent-run gate before any end; the handle-held user and start-time check beforeTerminateProcess, and a log line for each outcome; the bounded waits; the last look and its elevation rule; the answer 0, 1 or 2; register saving; and the -WX rules.tests/unit/main/installer-nsis-behaviour.test.ts(HOST QUARANTINE: runs on CI's Windows parts and the VM, never on the owner's PC).customCheckAppRunningare inPROBE_MACROS. Anappsmode of the installer probe runs the hook in the installer pass; an uninstaller-pass probe compiles withBUILD_UNINSTALLERand/WX.WM_CLOSE, with a window that stays open (as the app does while it asks whether to save), with a window that starts a fresh copy of itself and then closes, or with no window.WM_CLOSEand is logged; anaicc-helper.exein the install folder keeps running and is never mentioned; the replaced install's copy is ended in the installer pass and left running in the uninstaller pass; the run passes with exit code 0.customInit's capture names, with no record in this hive, keeps running.Mutants at the a1af40d code (on the VM, against the 4 app-check cases of that head; each went red):
WM_CLOSETerminateProcessaicc-helper.exeadded to the namescustomInit's cross-hive capture instead of this hive's recordNo mutants were run this round.
Not covered by any runtime test:
/WX, so the first -WX compile of it is the release PR's package job;Review
VM
VM check owed at the release smoke, on the release PR's installer:
aicc-helper hold) runs: the terminal survives.Owner test steps (for the release)
Notes
WM_CLOSEcan reach a window that is not this install's.Plan: 2.1.3-beta.8 section C3
Orchestrator rulings (before merge)
All seven decisions above are accepted as written.
SHELL_CONTEXTrecord, all three names) and its known limits: accepted. The sibling-folder limit is recorded, not a blocker./SD IDCANCEL, exit code 2 on every stop) and 4 (the no-tasklist test reads code lines only): accepted.🤖 Generated with Claude Code