Skip to content

fix(installer): close only this user's copy of the app from this install folder, without tasklist or taskkill - #720

Merged
nubbymong merged 4 commits into
betafrom
fix/installer-app-check-toolhelp
Nov 18, 2026
Merged

nubbymong merged 4 commits into
betafrom
fix/installer-app-check-toolhelp

Conversation

@nubbymong

@nubbymong nubbymong commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

What and why

aicc_planning #319. customCheckAppRunning in build/installer.nsh found the app with tasklist and closed it with a bare taskkill /im. Over a non-interactive sign-in (SSH, a scheduled task) both answer "Access denied" (the VM measurement recorded at CccScanProcesses), so the check found and closed nothing there. As administrator, taskkill /im asked 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 of CccScanProcesses) takes one Toolhelp snapshot. It keeps a process only when all of these hold:

    • its image name is one of the app's three (${APP_EXECUTABLE_FILENAME}, Claude Command Center.exe, Claude Conductor.exe);
    • it runs as this copy's own user (CccProcessIsMine, with $R6 read the way CccEndUserHelpers reads it);
    • its full image path (QueryFullProcessImageNameW) is $INSTDIR\<name>, compared through CanonPathPair (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. CccProcessIsMine now answers 1 (this user's), 0 (another user's) or 2 (not known). No other image name is ever looked at, so aicc-helper.exe and the terminals it holds keep running (B2).

  • Ask. CccCloseAppCopies lists the top-level windows those pids own (FindWindowExW, GetWindowThreadProcessId) as window:pid. Before each WM_CLOSE it 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.

    • In a run someone can see (not silent), a copy that was asked to close and is still open is not ended, and nothing else is either. The app answers WM_CLOSE with 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 second WM_CLOSE closes the app at once.
    • Otherwise (a silent run, or no asked copy still open), for each first-found copy the last look still saw, it opens a handle (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 call TerminateProcess on that handle. Every outcome is logged. It then waits up to 2 s more.
    • Over SSH or a scheduled task the installer is on another desktop, so no window is reached and the copy is ended after the 5 s wait. The log then shows "No window of AI Code Conductor could be reached from here ..." and "Ended process N, which did not close within 5 seconds.". That is the expected result, not a failure.
  • 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 CccRestoreInstallLocation in 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.

  • KillIfRunning is gone. No tasklist, taskkill, WMI, PowerShell or nsExec is used anywhere in the check.

  • -WX in both passes. The new macros (CccScanAppCopies, CccCloseAppCopies, and the list reader CccNextPair) declare no Var and no Function. In both passes they use only CanonPathPair's scratch, which customHeader declares in both. The replaced install's record ($cccRecordUninstaller, through CccGetInQuotes) and CccRestoreInstallLocation are 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 (RemoveUserHelperFolder and its macros: every caller of CccProcessIsMine there 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)

  1. The replaced install's folder. The plan says that for a legacy name, the legacy install folder the installer already resolves counts. I take the folder the uninstall record in SHELL_CONTEXT names, read at the check. That is the record uninstallOldVersion runs next, or, for a legacy tree beside $INSTDIR, the one the commit point drops before the sweep removes that tree.
    • Not $cccLegacyUninstaller (the first push used it). customInit falls 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.
    • All three names, not only the two legacy ones. The nested legacy shape runs under the current name from that folder, and the sweep then removes it. In the ordinary upgrade this folder is $INSTDIR.
    • The uninstaller pass knows no such folder, so there it is $INSTDIR only.
    • Known limits (written in the hook's comment and the fragment): an all-users run that is already elevated also runs the HKCU record's uninstaller, and a copy in that per-user folder is left to that uninstaller's own check. A legacy-named copy running from one of the sibling folders the rename sweep removes (RemoveLegacyInstall, once proved) is not closed when no record in this hive names that folder; the sweep then cannot remove its files.
  2. Retry now re-runs the check. The old IDRETRY jumped past the re-check and carried on. Now it runs the whole check again.
  3. /SD IDCANCEL on 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).
  4. The no-tasklist test checks code lines only. The plan says "the file contains no tasklist and no taskkill", but comments name them to explain why they are gone. The lines red before the change (716, 720, 733) were all code lines.
  5. Not ending a copy that is asking (review finding). Section C3 says to wait 5 s and then 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 no WM_CLOSE reached, are still ended after the wait.
  6. A copy whose user cannot be read (review finding). It counts as still running only when the installer is not elevated. An elevated installer can read the user of every copy this user started, so there such a process is another user's, and VM route 2 (another user's copy keeps running) keeps working.
  7. A check that could not run (review finding) now stops a silent run and asks in a run someone can see. Before, it went on as if nothing were running.

Tests

  • tests/unit/main/installer-branding-guard.test.ts, run on the host through the locked runner:

    • This round, before: the new tests against the previous head's installer.nsh (a1af40d, rebased as 0ebcfea): 10 failed, 37 passed (47). The 10 failures are the 4 new tests (three-way CccProcessIsMine, 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, the WM_CLOSE order and count, the logged ends, the registers, the labels under -WX).
    • This round, after (83851fd, unchanged at 4085ff5, which only touches the behaviour test): 47 passed (47).
    • First round, before (the original installer.nsh from 29b2356): 8 failed, 35 passed (43). The no-tasklist test failed on exactly line 716 (tasklist), line 720 (taskkill /im) and line 733 (tasklist).
    • The static tests pin: no tasklist, taskkill, WMI or PowerShell on any code line; the hook's body, pass by pass, with both boxes, the stop and both labels; the three names; the held handle from the user check to the start time; the canonical compare against $INSTDIR\<name>; the three-way user answer and its older callers; each logged reason; WM_CLOSE only 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 before TerminateProcess, 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).

    • The new macros and customCheckAppRunning are in PROBE_MACROS. An apps mode of the installer probe runs the hook in the installer pass; an uninstaller-pass probe compiles with BUILD_UNINSTALLER and /WX.
    • The stand-ins are one small NSIS program, copied under each name: with a window that closes on 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.
    • The app's image names are rewritten to stand-in names, and the lift fails closed on any real one, so the probe can never reach a real copy of the app. The one silent-run gate is read from the probe's ini, so a silent probe can run it as a run someone can see; the lift fails closed if that gate is not there exactly once.
    • The cases:
      • In both passes: this install's copy with a window closes itself (no "Ended" line); this install's copy without a window is ended after the wait; the same name in another folder keeps running, gets no WM_CLOSE and is logged; an aicc-helper.exe in 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.
      • In both passes, a run someone can see: a copy that stays open when asked is not ended, nor is a windowless copy beside it; the log says why; the box stops the run with exit code 2; the installer pass puts the saved install location back.
      • Installer pass, silent: a copy that stays open is ended; a copy started after the first look stops the run, with exit code 2, the saved install location put back, and the log naming the pid still running.
      • Installer pass: an install that only customInit's capture names, with no record in this hive, keeps running.
      • Nothing waits when no copy of this install runs.
    • This round: CI run 44316846405 at 4085ff5, green. On windows-2025 part 2 the file ran 43 of 43, none skipped: the seen-run cases took 7.2 s (installer pass) and 7.0 s (uninstaller pass), the silent stop 8.8 s. The branding guard ran 47 of 47 on part 1. The new probe cases were not run against the previous code; on it, the lift fails closed (no silent-run gate) and the log lines they read do not exist.
    • Earlier rounds (previous heads): CI run 44302413445 at 3ba9f63 (39 of 39) and run 44306557358 at a1af40d (40 of 40) on windows-2025 part 2; the VM probe runs and mutants M1 to M7 below were at the a1af40d code.
  • Mutants at the a1af40d code (on the VM, against the 4 app-check cases of that head; each went red):

    Mutant Result Why it failed
    M1: no folder check 4 of 4 red other folders' copies were closed
    M2: no WM_CLOSE 2 red the windowed copy had no close marker
    M3: no TerminateProcess 2 red the copy stayed, the silent box cancelled, and the probe exited with an error
    M4: aicc-helper.exe added to the names 3 red the helper was ended
    M5: installer pass without the replaced folder 1 red the replaced install's copy kept running
    M6: no 5 s wait 2 red the run took about 0.75 s
    M7: customInit's cross-hive capture instead of this hive's record 1 red the other install's copy was ended

    No mutants were run this round.

  • Not covered by any runtime test:

    • Retry (it needs someone to click it) and the box's text on screen;
    • the installer pass compiled with -WX: the probe compiles that pass without /WX, so the first -WX compile of it is the release PR's package job;
    • the start-time checks and pid or window-handle reuse: they cannot be produced on demand, so the static tests pin them;
    • a check that could not run (answer 2), and the elevation rule for a copy whose user cannot be read: static tests only;
    • another user's copy, and this user's copy started as administrator: the VM routes at the release smoke.

Review

  • Copilot reviewed 3ba9f63 automatically when the PR opened; I did not request it. Its three threads were fixed in a1af40d, answered and resolved.
  • The independent review of a1af40d left 17 findings (1 major, 16 minor). All are handled in 83851fd and 4085ff5, or here:
    • Fixed in code: the save dialog cut off (major); the window owner checked last; the true reason in the log; the could-not-check paths; the unreadable copy of this folder; every end logged and the count line; the cancel logged with exit code 2; register comments.
    • Fixed in docs: the sibling-folder limit; the remote-sign-in result; the elevated-copy claim reworded.
    • Tests added: the stop, the Cancel restore and exit code, and the silent-run gate both ways.
    • The scope extras are listed under "Decisions" for the orchestrator to accept or reject.
    • The elevated inner instance of an all-users install skips the check (older behaviour): aicc_planning fix(tokenomics): file Codex subagent rollouts under their own session, not the parent (#307) #327.

VM

VM check owed at the release smoke, on the release PR's installer:

  1. A silent install over SSH while this user's app runs on the desktop: the install completes, the log shows "No window of AI Code Conductor could be reached from here ..." and "Ended process N, which did not close within 5 seconds.", and no "Access denied".
  2. A per-machine install, then an elevated silent uninstall over SSH while ccctest (started over its own SSH session through WMI) runs the app: ccctest's copy keeps running, and the log shows what happened to files it holds.
  3. An install while a held plain terminal (aicc-helper hold) runs: the terminal survives.
  4. This user's copy started as administrator, then a non-elevated silent install: record whether the log shows "Found ... but could not read its user" and the run stops with code 2 (the box), or whether the copy is not seen at all.

Owner test steps (for the release)

Notes

  • The plan does not mark C3 as owing an ADR-009 pass, so no "owed" line is here. If the orchestrator wants it on the aicc_planning feat(loop): add the LoopReady and StartLoop skills, premise-review policy, and loop label state machine (#319) #320 list, the pass should attack two things:
    • which processes an elevated installer or uninstaller ends: the name, user and folder match, and pid reuse between the scan and the end;
    • whether WM_CLOSE can reach a window that is not this install's.
  • Release surface for the release PR, as the plan says: one changelog fix line (the installer closes only your own copy of AI Code Conductor from the folder being installed, and works over a remote or scheduled sign-in). Over a remote sign-in the copy is ended after 5 s, not asked; the changelog line should not promise a graceful close there.

Plan: 2.1.3-beta.8 section C3

Orchestrator rulings (before merge)

All seven decisions above are accepted as written.

  • 1 (the replaced install's folder from the SHELL_CONTEXT record, all three names) and its known limits: accepted. The sibling-folder limit is recorded, not a blocker.
  • 2 (Retry re-runs the check), 3 (/SD IDCANCEL, exit code 2 on every stop) and 4 (the no-tasklist test reads code lines only): accepted.
  • 5 (a run someone can see does not end a copy that is still asking, so the app's own save dialog is never cut off): accepted. This goes beyond section C3's literal "wait 5 s then end it" on purpose, because ending the app under its save dialog would lose the user's choice. Silent runs and copies no window message reached still end after the wait.
  • 6 and 7 (an unreadable user blocks only a non-elevated run; a check that could not run stops or asks): accepted.
  • The pre-existing elevated inner-instance gap is tracked as aicc_planning#327 for a later beta.
  • VM routes 1 to 4 run at the 2.1.3-beta.8 release smoke on the release installer.

🤖 Generated with Claude Code

@nubbymong nubbymong added this to the 2.1.3-beta.8 milestone Nov 18, 2026
@nubbymong nubbymong added ci-run Run full CI matrix (Win+macOS) on this PR release-2.1 Targets the 2.1 release line labels Nov 18, 2026
Copilot AI balanced review requested due to automatic review settings November 18, 2026 12:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread build/installer.nsh Resolved
Comment thread build/installer.nsh Resolved
Comment thread build/installer.nsh Resolved
nubbymong and others added 3 commits November 18, 2026 13:19
…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
nubbymong force-pushed the fix/installer-app-check-toolhelp branch from a1af40d to 83851fd Compare November 18, 2026 13:42
…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
nubbymong merged commit f6ac253 into beta Nov 18, 2026
44 checks passed
@nubbymong
nubbymong deleted the fix/installer-app-check-toolhelp branch November 18, 2026 14:14
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-run Run full CI matrix (Win+macOS) on this PR release-2.1 Targets the 2.1 release line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants