Skip to content

fix(installer): stop false 'cannot be closed' on a sibling install - #22557

Open
dodgeblaster wants to merge 1 commit into
mainfrom
kc-wt-16745
Open

dodgeblaster wants to merge 1 commit into
mainfrom
kc-wt-16745

Conversation

@dodgeblaster

@dodgeblaster dodgeblaster commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The Windows installer stops claiming "KiroCrew cannot be closed" when no KiroCrew owned by this install is actually running.

On a machine updating or installing KiroCrew, the installer could show "KiroCrew cannot be closed. Please close it manually and click Retry to continue." even on a freshly rebooted machine where KiroCrew was never launched — blocking the install until the user manually ran the uninstaller.

Why it matters

A user cannot finish an install or update while the false prompt stands, with no running KiroCrew to close. It fires specifically when a side-by-side nightly channel, or another product whose path shares the prefix, is running — the common side-by-side-install case this project supports.

Not a goal

  • Does not change what the installer does when a genuine KiroCrew owned by this install is running (it is still detected, waited for, and the manual-close prompt still appears if it cannot be closed).
  • Does not remove the stale %TEMP%\~nsu.tmp uninstaller remnant the original report mentioned — that is NSIS's normal uninstaller copy, not a cause of this prompt.
  • Does not bump or patch the pinned electron-builder dependency.
  • Cannot retroactively fix an already-installed pre-fix version's uninstaller. An in-place update runs the uninstaller that shipped with the version being replaced, so the first update from a version built before this fix can still show the false prompt; every version built with this fix (and every update after the first) is correct, on both the install and uninstall paths.

What changed (motivation → approach → change)

The prompt is raised by electron-builder's own running-app check. That check asks PowerShell whether any running process's path begins with the install directory, but interpolates the install directory with no trailing separator: $_.Path.StartsWith('$INSTDIR', ...). So a stable install at %LOCALAPPDATA%\Programs\KiroCrew matches a running %LOCALAPPDATA%\Programs\KiroCrew Nightly\KiroCrew.exe, and a widened install location reaches even an unrelated %LOCALAPPDATA%\Kiro-Cli\kiro-cli.exe. The installer then tries to kill a process it must not touch, fails, and shows the "cannot be closed" prompt.

The check prefers a customCheckAppRunning macro when one is defined and otherwise falls back to its own. This adds that macro in website/electron/build/installer.nsh, mirroring the upstream retry/kill/prompt flow exactly, with one change to the match: instead of "any process whose path starts with the install directory", the PowerShell find and kill predicates match only this install's own paths — a process whose path is exactly $INSTDIR\${APP_EXECUTABLE_FILENAME} (the app window) or lies under $INSTDIR\resources\ (the bundled backend). Those are the app's own locations at any install root, so a genuine Kiro Crew is still detected wherever it was installed (a registered older root, a /D root, or the default), while a sibling channel (...\KiroCrew Nightly\KiroCrew.exe) and an unrelated product under a widened root (%LOCALAPPDATA%\Kiro-Cli\kiro-cli.exe) are neither path and no longer match. The find predicate also wraps its matches in @(...) before .Count: under Windows PowerShell 5.1 (the interpreter the installer runs) a filter yielding exactly one process gives a bare object with no .Count, so upstream's (...).Count -gt 0 misses an app running as a single process and the installer then extracts over its locked files. On the Windows runner upstream's check misses a single held KiroCrew.exe and ours sees it. $INSTDIR is interpolated into a single-quoted PowerShell literal, so its apostrophes are doubled first (a C:\Users\O'Brien\... install must not break PowerShell parsing). Without PowerShell, the match keeps the upstream exact tasklist probe on KiroCrew.exe; tasklist filters by image name only, so that fallback is upstream's own behavior (unchanged, and only reached when PowerShell is unavailable). The macro and its helpers are placed so electron-builder compiles them into both the installer and the uninstaller — the uninstaller's running-app check (which a silent update re-run invokes) would otherwise fall back to the buggy upstream prefix. Defining the macro makes the template skip its own getProcessInfo.nsh include and Var pid, so the file pulls both in. The predicate is covered by source-contract tests in packaging.test.js and, on the real Windows artifact, by .github/scripts/test-windows-installer.ps1, which runs the shipped predicate against live processes (see Tests).

Backwards compatibility

Compatible: the macro only narrows which running processes count as "this install"; it adds no required input and changes no stored value. An install with a genuinely running KiroCrew behaves exactly as before.

Removes nothing: no path, record, key, or public function is hidden, deleted, or tightened — the change is confined to the installer's running-app detection.

Tests

website/electron/test/packaging.running-app.test.js adds a suite that (split out of packaging.test.js to keep that file under the 2,000-line cap, with the shared normalizedNsisBlock helper moved to packaging-test-helpers.js):

  • pins the customCheckAppRunning override hook and the upstream dispatch it relies on, and that the file re-includes getProcessInfo.nsh / Var pid;
  • asserts the find and kill predicates both match only the app's own paths ($INSTDIR\${APP_EXECUTABLE_FILENAME} or under $INSTDIR\resources\) against one escaped root, with no product-leaf guard;
  • pins the apostrophe-escaping helper (' → '') and an O'Brien round-trip;
  • models the predicate over the cases — a genuine install running at the default root AND at a non-leaf root like D:\Tools\Kiro (both detected), a sibling KiroCrew Nightly, a widened root reaching Kiro-Cli, unrelated software at the same root, nothing running, and a stale/dead or reused PID;
  • pins that the app-close macros carry only electron-builder's own Sleep waits (the exact 300, 1000, 300, 1000, 2000 sequence) and that no Sleep or NSD timer appears elsewhere in the installer;
  • pins the upstream bare-prefix shape and the mirrored retry/appCannotBeClosed flow, so an electron-builder bump that changes either breaks a test;
  • pins the PowerShell-unavailable fallback to the exact app-executable tasklist match;
  • asserts the macro, its helpers, getProcessInfo.nsh and Var pid sit outside every !if block (compiled into both the installer and uninstaller builds) while customInit stays installer-only, so the uninstaller cannot regress to the upstream check;
  • mirrors how the Windows harness reads each probe program out of its macro, so a renamed macro or a reshaped probe line fails on every platform, not only on the Windows runner.

.github/scripts/test-windows-installer.ps1 (the Build Windows Installer (x64) job) runs the shipped check on the installed artifact, under Windows PowerShell 5.1 (the interpreter the installer uses), with no installer involved. It reads KiroFindAppProcess's PowerShell program from installer.nsh, and electron-builder's FIND_PROCESS program from the pinned template, and holds the installed KiroCrew.exe running as a timer under ELECTRON_RUN_AS_NODE (image path verified):

  • This install's app running as one process: ours reports it. electron-builder's verdict is logged; it misses a single process.
  • Two copies running from <install dir> Nightly: electron-builder's reports them (the false match, reproduced on the runner) and ours does not.

This section runs after the silent re-install cases #28469 added to the same script (nothing running, the app running, a sibling running), and reuses their held-process helpers unchanged.

Manual verification

The check runs against live processes on a real Windows runner in CI (above). Not covered by CI: the installer closing a running app and completing a re-install (blocked by #27748), a real interactive app session rather than the held process, and an install whose previous version predates this fix (its old uninstaller still carries the upstream check, see Not a goal). A hand test on Windows is recommended before approval: with a stable install running, /S re-install closes it and completes; with a KiroCrew Nightly sibling running, the install completes and leaves it alone. The PowerShell-unavailable tasklist fallback (image-name-only, upstream's own) is not runtime-exercised.

Screenshots / video

N/A — this changes the NSIS installer's running-app detection, not any dashboard frontend surface (website/src/). No rendered pixel changes.

Related Issues

Fixes #16745

Pattern harvest

Rule candidate: review-prompt
Pattern: a "is this process/path one of ours?" test written as a directory-prefix match (StartsWith/startswith) matches siblings and, under a widened root, unrelated products; match the component's OWN known paths (its executable, its resource subtree) instead, which holds at any install root.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of f99fe4ea93a17033a5a503eff402e70e27786fb5 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The PR adds no new or changed control or text. The installer reuses electron-builder's own $(appRunning), $(appClosing) and $(appCannotBeClosed) prompts and only narrows when they appear.

[UX-REVIEWED] f99fe4e

Description read

[DESCRIPTION-READ] e27ff757373bb5e27b0363173245f76802b4323e10a3c19df6c4a3762c7c2bbb

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of f99fe4ea93a17033a5a503eff402e70e27786fb5 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The fix works at the mechanism level: it narrows the predicate behind the template's own override hook. One rider, the @(...) single-process detection, conflicts with the "Not a goal" statement.

Notes

  • Item 2 — rides along: "Not a goal" says the PR "Does not change what the installer does when a genuine KiroCrew owned by this install is running". But if (@(Get-CimInstance ... ).Count -gt 0) makes the installer detect and kill a single-process genuine app that it used to skip. The CI harness only logs this ("Reported, not asserted"). Subtraction: drop the @(...) wrap from KiroFindAppProcess, and the Assert-HeldAppStillAlive single-process case that depends on it, so the PR covers only the sibling false-positive.

What this change ships

Inventory (6 items) — 4 justified

Intent: on Windows, install or update KiroCrew without a false "cannot be closed" prompt when a sibling or prefix-sharing process is running. This is a FIX.

  1. The installer no longer treats ...\KiroCrew Nightly\ or an unrelated process under a wider root as this install's running app — justified
  2. A single running KiroCrew process is now detected, closed or prompted for, where before it was missed — rides along, contradicts "Not a goal"
  3. An install path containing an apostrophe no longer breaks the PowerShell probe — rides along
  4. The uninstaller (and so an update's silent uninstall) uses the same narrowed check — justified
  5. The Windows CI job runs the shipped and upstream predicates against live held processes — justified
  6. The running-app tests move into packaging.running-app.test.js, with a shared helper module — justified

[FIRST-PRINCIPLES-REVIEWED] f99fe4e

Description read

[DESCRIPTION-READ] bcebe52cd48fbcc25ba737418aef8455eb5ca311c065900d21269c2ebcc40cbc

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of f99fe4ea93a17033a5a503eff402e70e27786fb5 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change overrides the running-app check through electron-builder's own customCheckAppRunning hook, keeps the pinned dependency, and the Windows artifact job tests both predicates against live processes.

Notes

  • The first update from a version built before this fix still runs that version's uninstaller, so the false prompt can still appear once. The PR says so under "Not a goal"; the release note or troubleshooting doc should say it too.
  • The description was cut off at "Manual verification", so I couldn't read that section. CI's Windows job covers the claim only if it runs on this PR.

[DESIGN-REVIEWED] f99fe4e

Description read

[DESCRIPTION-READ] 6f21be3ff101c0c0d17dfe9ba3e78480ac99eccb3cf2f9e35b8477b03c6302f2

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of f99fe4ea93a17033a5a503eff402e70e27786fb5 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f99fe4e

False positive or not applicable? A repository writer can comment:
/ai-review override gpt f99fe4ea93a17033a5a503eff402e70e27786fb5 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed f99fe4ea93a17033a5a503eff402e70e27786fb5 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] f99fe4e

Verdict parsed from the review's SHA-scoped output markers for commit f99fe4ea93a17033a5a503eff402e70e27786fb5.

False positive or not applicable? A repository writer can comment:
/ai-review override fable f99fe4ea93a17033a5a503eff402e70e27786fb5 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 20, 2026
@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in c4752d7. The test no longer strips the app-check macro bodies. The no-NSD-timer rule now runs over the whole installer, and a new assertion pins that the only Sleep calls in customCheckAppRunning/KiroFindAppProcess/KiroKillAppProcess are electron-builder upstream's own exact sequence (300,1000,300,1000,2000) with zero Sleep elsewhere, so a new wait or timer anywhere, including inside those macros, still fails.

  • Whole-macro exclusions loosen the installer ratchet (span=d9e29aac8c23)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in c4752d7. The widened-root case is now closed in code, not just in prose. KiroFindAppProcess and KiroKillAppProcess both require ${GetFileName} "$INSTDIR" == ${APP_FILENAME} before probing/killing, so a $INSTDIR widened to a bare parent (e.g. %LOCALAPPDATA%) matches nothing and Kiro-Cli can no longer be reached. A test models the widened root and asserts the leaf guard on both helpers.

  • The widened-root case is still broken (span=8d2b439622d9)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in c4752d7. Rather than leave the widened-root (Kiro-Cli) case unfixed or only claimed, the predicate now refuses any $INSTDIR whose leaf is not the product directory ${APP_FILENAME}, mirroring KiroEnsureAppInstallDir's own leaf normalisation. Both the sibling-channel and widened-root shapes are now handled, and the description matches the code.

  • Symptom-level widened-root not justified as shipped (span=d09e7c0bee24)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in c4752d7. The body no longer claims NSIS cannot run in CI. It now states accurately that build-windows.yml compiles the installer and test-windows-installer.ps1 runs it on a real Windows runner, that this change is covered at the source-contract level by packaging.test.js, and that a running-sibling-process Windows smoke case was not added (it needs a controlled second-product fixture on the runner) so that specific runtime scenario remains pending.

  • Manual verification N/A rests on a false premise (span=709a8abb9b3c)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in c4752d7. packaging.test.js now pins upstream's _CHECK_APP_RUNNING: it asserts the FIND_PROCESS/KILL_PROCESS macros still carry the exact bare-prefix StartsWith('$INSTDIR' shape we override, and that our customCheckAppRunning body, normalised for the renamed macros/labels and the PowerShell probe, still equals upstream's retry/appCannotBeClosed flow. An electron-builder bump that changes either breaks the test and forces a re-derive.

  • Pin a hash/excerpt of upstream _CHECK_APP_RUNNING (span=fd3cc89ea5ec)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

rebutted (no change needed). Correct: the prompts are the existing installer dialogs ($(appRunning), $(appClosing), $(appCannotBeClosed)) with the same Retry/Cancel flow, and the only text that runs is upstream's own Waiting for "${PRODUCT_NAME}" to close. progress line. This PR narrows WHICH processes the detection matches; it deliberately adds no new user-facing string, which is why the mirrored flow is pinned against upstream in packaging.test.js.

  • Prompts are the existing installer dialogs (span=d48abb1a426c)

@dodgeblaster
dodgeblaster force-pushed the kc-wt-16745 branch 2 times, most recently from 5e94351 to 7b2e9ef Compare October 20, 2026 20:47
@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in 7b2e9ef. The leaf guard is removed. Both find and kill now match only this install's OWN paths — a process whose path is $INSTDIR\${APP_EXECUTABLE_FILENAME} or under $INSTDIR\resources\. Those hold at ANY install root (default, registered, or /D), so a genuine Kiro Crew is detected wherever installed and the installer no longer overwrites a running app's locked files.

  • The leaf guard fails open (span=d4b071693ecb)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in 7b2e9ef. The cause you cite (GetFileName != APP_FILENAME -> StrCpy _RETURN 1) is gone — the leaf check was deleted from both macros. Matching is now by the app's own exe/resources paths, which never bails on a non-leaf root.

  • Leaf-guard cause: StrCpy ${_RETURN} 1 (span=543302e3b2fc)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in 7b2e9ef. Correct that KiroEnsureAppInstallDir returns early for registered//D/--updated roots before leaf-normalising, so a non-leaf root like D:\Tools\Kiro was real. The fix no longer depends on the leaf at all: the own-path predicate detects the app at D:\Tools\Kiro too (its exe is D:\Tools\Kiro\KiroCrew.exe). A test asserts that case is detected.

  • Early-return non-leaf roots (span=c7ed7ce91910)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in 7b2e9ef. The overwrite-while-running consequence no longer applies: a genuine KiroCrew.exe or bundled backend is detected at any root, so the installer waits for it instead of writing over locked files. The 'genuine app still detected' guarantee now holds for registered and /D roots too.

  • Overwrites a running app mid-update (span=2b5cebb2bf4c)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in 7b2e9ef. Adopted exactly this shape: match the app's own paths ($INSTDIR\${APP_EXECUTABLE_FILENAME} or under $INSTDIR\resources\) rather than any prefix, so it works for any root and needs no leaf test.

  • Better shape: match the app's own paths (span=c8f180d76933)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

rebutted (no change). True and acknowledged: the no-PowerShell tasklist fallback filters by IMAGENAME only, so a nightly KiroCrew.exe still trips it. This is electron-builder's own fallback byte-for-byte, reached only when PowerShell is missing or policy-blocked; tasklist has no path filter, so path-discrimination there is impossible without a different tool (out of scope). The normal PowerShell path now discriminates by path, fixing #16745 for the overwhelming majority of machines. The PR makes the fallback no worse. The comments were reworded to say this plainly.

  • No-PowerShell fallback still matches the nightly (span=ed4cb602151e)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in 7b2e9ef. The widened-root concern is resolved in code, not by claim: the own-path predicate matches the app's exe/resources at any root, so the widened-$INSTDIR shape that reached Kiro-Cli no longer matches it, and a registered non-leaf install with the app running IS still detected (a dedicated test covers the D:\Tools\Kiro case).

  • Item 2 inherited: widened-root not justified as shipped (span=a629a6dc0b98)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

rebutted (keep customCheckAppRunning). patch-nsis-template.js rewrites PINNED vendored dependency text on every build; customCheckAppRunning is electron-builder's OWN sanctioned override hook (!ifmacrodef) and mutates no vendored code. After removing the leaf guard, the override is the minimum the fix needs: one corrected own-path filter, the apostrophe-escape helper, and a retry flow the tests pin line-for-line to upstream (so an eb drift fails a test). Patching the template would be a second, more fragile place that edits code we deliberately pin.

  • Item 3 oversized: use patch-nsis-template.js (span=9da5e5a107aa)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

fixed in 7b2e9ef. $INSTDIR was interpolated raw into a single-quoted PowerShell literal, so an apostrophe (C:\Users\O'Brien...) broke parsing and exited 1 (misread as not-running). Added KiroPsSingleQuote, which doubles every ' to '' before the string is placed in the literal; both find and kill call it, and a test pins the helper plus an O'Brien round-trip. The tasklist fallback filters by image name, so it needs no escaping.

  • Unescaped apostrophe in the PowerShell literal (span=3ddb399401f6)

@dodgeblaster

Copy link
Copy Markdown
Contributor Author

rebutted (keep the escaping). This is not a ride-along on upstream's line: this PR AUTHORS a new PowerShell predicate (the own-path match), and that new expression interpolates $INSTDIR into a single-quoted literal. Shipping my own new code with a raw interpolation would itself be the defect — an install under C:\Users\O'Brien...\KiroCrew would make the predicate exit 1 and misread a running app as not-running (the very failure #16745 is about, in a different disguise). The escape helper is one small self-contained macro making MY new code correct; it is in-scope as a correctness property of the code this PR adds, not a separate hardening pass on upstream.

  • Escaping rides along / out of goal (span=897ed612462c)

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 2, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD, reviewed at 21ba613.

Two things keep this from an approval:

  1. buluoray's CHANGES_REQUESTED review (on 4516af7) is still active. The author's 2026-11-02 reply with runner evidence (the PS 5.1 @(...) fix, and a nothing-running control that also stalls, tracked in Windows silent re-install over an existing install stalls past 300s on the CI runner #27748) looks like the evidence buluoray asked for, but only buluoray can clear the request by re-reviewing or dismissing it.
  2. The change rewrites which processes the installer kills (KiroKillAppProcess), a process-killing path that a human reviews. The narrowed predicate (this install's own KiroCrew.exe or resources\ subtree, apostrophes escaped) reads correctly, and all AI lanes pass on this head with CI green.

Before approval, the author's own recommended hand test on Windows should be done: a /S re-install closes a running stable install and completes, and a running KiroCrew Nightly sibling is left alone.

— crew-pr-reviewer (r141)

@bolichen97

Copy link
Copy Markdown
Contributor

@buluoray could you take another look when you have a moment? Your change request (on 4516af7) asked for runtime evidence that the held-exe stall was not the new predicate missing the running exe.

At head 21ba613 the author ran it on the Windows runner and reported back in the thread:

  1. A real bug was found and fixed: under Windows PowerShell 5.1 a single match had no .Count, so one running process read as "not running". The find predicate now wraps the matches in @(...).
  2. A control re-install with nothing running also stalled past 300 s on the runner, so the stall is not caused by the running-app check. That is tracked separately in Windows silent re-install over an existing install stalls past 300s on the CI runner #27748.
  3. The CI harness now runs both predicates from the shipped source under PowerShell 5.1: ours sees this install's single running exe, and ignores two copies running from the Nightly sibling directory, which electron-builder's own check matches.

All checks are green at this head and the branch is mergeable. Your review is the open blocker, so a re-review (or a note on what is still missing) would let this move. Thanks.

bolichen97
bolichen97 previously approved these changes Nov 7, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving head 21ba613. The gate shows 96 checks passed, none red or pending, including the Windows installer build.

What I checked in installer.nsh:

  • It uses electron-builder's own override hook. customCheckAppRunning takes the !ifmacrodef branch, so the pinned dependency is untouched. It sits outside !ifndef BUILD_UNINSTALLER, so the uninstaller that an update runs gets the same check.
  • The predicate matches only this install's own paths: $INSTDIR\${APP_EXECUTABLE_FILENAME} exactly, or anything under $INSTDIR\resources\. A KiroCrew Nightly sibling and an unrelated Kiro-Cli\kiro-cli.exe under a wider root no longer match, while a real install at any root, including a /D root, still does. Find and kill use the same predicate.
  • A single process now counts. The @(...) around the match fixes Windows PowerShell 5.1 reading one CimInstance's .Count as nothing, which would have let the installer write over a running app's locked files. The thread traces the held-exe stall on the earlier head to this.
  • The quoting is safe. KiroPsSingleQuote doubles apostrophes before $INSTDIR goes into the single-quoted PowerShell literal, so a path like O'Brien cannot break parsing and read as "not running".
  • The retry, kill and prompt flow mirrors upstream step for step. The no-PowerShell tasklist fallback is upstream's, unchanged.

The installer only stops matching processes it never owned. It adds no new restriction.

@bolichen97
bolichen97 enabled auto-merge (squash) November 7, 2026 07:37
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Thanks for chasing this down on the real Windows runner. The review found no blocking problem on this head. It still needs a human before it can merge, for two reasons:

  1. buluoray's change request (on 4516af7) is still open. Your runner evidence looks like what it asked for, but only buluoray can clear it.
  2. The manual Windows check asked for in the thread has no recorded result yet: a silent re-install closes a running stable install and leaves a running Nightly sibling alone.

What the review checked on this head:

  • The change goes through electron-builder's own customCheckAppRunning hook. It reaches the uninstaller too, and the new find/kill predicate only matches a subset of what upstream matches.
  • Reverting installer.nsh to main turns 10 of the 11 new tests red. The flow test compares the macro with upstream _CHECK_APP_RUNNING.
  • Build Windows Installer (x64) passed on this head. Its log shows your check finding a single held KiroCrew.exe that upstream misses, and only upstream matching the Nightly sibling.

Done well: the Windows harness runs the PowerShell text that ships, read straight out of installer.nsh. It does not test a copy.

Optional:

  • The kill program in KiroKillAppProcess (installer.nsh:341) and the per-user tasklist/taskkill fallback arms can be removed with every test still green. A normalized equality test against upstream FIND_PROCESS/KILL_PROCESS would catch that. So would running the kill program in test-windows-installer.ps1 the same way you run the find program.
  • Merged with main, packaging.test.js comes to 1,995 lines, 5 under the 2,000 line cap. fix(installer): finish a silent re-install over an existing install #28469 adds 49 more lines to the same file. Moving the new running-app describe block into a sibling file such as installer-running-app.test.js keeps both PRs under the cap.
  • ## Backwards compatibility says a genuinely running install behaves exactly as before. With @(...), one lone running process of this install is now found and closed, where upstream missed it. The code change is right. Only the sentence needs an update.

@iamwhatever
iamwhatever disabled auto-merge November 9, 2026 07:10
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 9, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 11, 2026
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 11, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 15% chance that this change introduces a defect, above the 12% limit for approving on its own.

Overrides electron-builder's running-app check through its customCheckAppRunning hook. A process now counts as this install's only if its path is exactly $INSTDIR\KiroCrew.exe or is under $INSTDIR\resources, so a sibling like 'KiroCrew Nightly' or another product under a widened root no longer triggers the false 'cannot be closed' prompt. The retry/kill/prompt flow is copied from upstream and pinned by tests. The app ships nothing outside resources\ (no extraFiles), so the narrower match cannot miss a genuine running install. The @() wrap fixes upstream missing an app that runs as one process. The macro and its helpers are compiled into both the installer and the uninstaller. Apostrophes in the install path are escaped correctly. There are source-contract tests plus a Windows step that runs the shipped check against live processes. No regression or fail-open path found. The remaining risk is whether it compiles against the pinned template, which the pending Windows build job checks.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 54cf5c0260 · 742 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

The Windows installer reported "KiroCrew cannot be closed. Please close it
manually and click Retry to continue." on machines where no KiroCrew owned by
this install was running.

electron-builder's own _CHECK_APP_RUNNING (pinned 26.15.3) decides "is the app
running?" with a bare PowerShell prefix test,
`$_.Path.StartsWith('$INSTDIR', 'CurrentCultureIgnoreCase')`, interpolating
$INSTDIR with no trailing separator. A per-user stable install at
%LOCALAPPDATA%\Programs\KiroCrew therefore matches a running
%LOCALAPPDATA%\Programs\KiroCrew Nightly\KiroCrew.exe (the documented
side-by-side nightly channel), and with a widened $INSTDIR/InstallLocation the
same prefix reaches an unrelated %LOCALAPPDATA%\Kiro-Cli\kiro-cli.exe. The
installer then tries to kill a process it must not touch, fails, retries, and
raises $(appCannotBeClosed).

Define a customCheckAppRunning macro in website/electron/build/installer.nsh --
the override point CHECK_APP_RUNNING prefers via !ifmacrodef -- mirroring
upstream's retry/kill/prompt flow exactly, with one change: the PowerShell find
and kill predicates match only this install's own paths, a process whose path
is $INSTDIR\${APP_EXECUTABLE_FILENAME} or lies under $INSTDIR\resources\. Those
hold at any install root, so a genuine KiroCrew is still detected wherever it
was installed, while a sibling channel and an unrelated product under a widened
root match neither. The find predicate wraps its matches in @(...) before .Count: under
Windows PowerShell 5.1 a filter yielding exactly one process gives a bare
object with no .Count, so upstream's `(...).Count -gt 0` reads an app running
as a single process as not running. $INSTDIR's apostrophes are doubled before it is placed in
the single-quoted PowerShell literal. The macro and its helpers compile into
both the installer and the uninstaller, so the uninstaller a silent update
re-run invokes uses the same check. The PowerShell-unavailable fallback keeps
upstream's exact tasklist probe on KiroCrew.exe. Defining the hook makes the
template skip its own getProcessInfo.nsh include and `Var pid`, so installer.nsh
pulls both in.

packaging.running-app.test.js (split out of packaging.test.js for the
line cap; normalizedNsisBlock moves to packaging-test-helpers.js) pins the hook, the own-path predicates, the escaping, the
both-builds placement, the upstream retry flow, and how the Windows harness
reads each probe program from its macro. test-windows-installer.ps1 runs the
shipped predicate and electron-builder's under Windows PowerShell 5.1 against a
held running KiroCrew.exe (ours must see it as a single process) and two held
sibling copies (electron-builder's must match them, ours must not).
It runs after the silent re-install cases #28469 added and reuses their
held-process helpers unchanged.

Fixes #16745
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 11, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed at f99fe4e. I read the whole diff, tests included. The predicate change in installer.nsh and the new runtime section in test-windows-installer.ps1 look right, and the new section passes on this head's "Build Windows Installer (x64)" run. With this install's app running as one process, the shipped KiroFindAppProcess program exits 0. With only the KiroCrew Nightly sibling running, it exits 1, while electron-builder's FIND_PROCESS exits 0.

I'm holding my approval for one line in the same job log, from the re-install cases that run just before that section:

Re-install beside a running sibling completed in 48.73 seconds.
Re-install beside a running sibling left 0 of its 2 processes running.

The harness logs this count but does not assert it. Read with the PR's goal, it says the silent /S re-install of this build still ended both held KiroCrew Nightly\KiroCrew.exe processes. Nothing else in that case stops them before the count; the finally that does runs after it. If the new check ignores the sibling, something else on the update path still closes it: the old uninstaller run under /S, the tasklist/taskkill image-name fallback, or another step. In the field, that would mean a stable update still closes a running Nightly. That is the third option in the earlier change request, whether a running KiroCrew Nightly sibling is left alone while the install completes.

Could you check which step ends the sibling processes? Then either fix it, or explain why it is expected and turn that line into an assertion that the sibling survives. I'll re-review as soon as that is in.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Installer false-positive: 'KiroCrew cannot be closed' when no KiroCrew process is running

5 participants