Skip to content

test(snapshots): kill vp before its children in env_install_interrupt - #2299

Merged
fengmk2 merged 1 commit into
fix-vitest-browser-mode-flakyfrom
fix-env-install-interrupt-kill-order
Aug 3, 2026
Merged

test(snapshots): kill vp before its children in env_install_interrupt#2299
fengmk2 merged 1 commit into
fix-vitest-browser-mode-flakyfrom
fix-env-install-interrupt-kill-order

Conversation

@fengmk2

@fengmk2 fengmk2 commented Aug 3, 2026

Copy link
Copy Markdown
Member

The env_install_interrupt PTY snapshot fails intermittently on Windows:

+**Exit code:** 1
-interrupted stale package exists
+interrupted stale package removed

Example failure: https://github.com/voidzero-dev/vite-plus/actions/runs/30777846280/job/91576844864?pr=2297

taskkill /T /F terminates the process tree in unspecified order. When the postinstall child dies before vp.exe, vp observes the failed npm child and runs cleanup_failed_install, removing the partial install dir before taskkill reaches vp itself, so no stale dir is left for the check-stale step. Reproduced the mechanism on macOS by killing the postinstall child first and letting vp react: same diff as the CI failure.

Fix: enumerate vp's direct children while the tree is parked in the postinstall sleep, kill vp.exe first so it cannot react, then taskkill /T each orphaned child (killing vp alone would leave the installer children running). The Unix path and the recorded snapshot are unchanged.

Stacked on #2297.

@fengmk2 fengmk2 self-assigned this Aug 3, 2026
@fengmk2
fengmk2 force-pushed the fix-env-install-interrupt-kill-order branch from 02ec41b to a7fb978 Compare August 3, 2026 02:49
@fengmk2
fengmk2 marked this pull request as ready for review August 3, 2026 02:49
@fengmk2
fengmk2 requested review from cpojer and wan9chi August 3, 2026 02:49
@fengmk2
fengmk2 force-pushed the fix-env-install-interrupt-kill-order branch from a7fb978 to 764dec7 Compare August 3, 2026 03:57
taskkill /T terminates the process tree in unspecified order. When the
postinstall child dies before vp.exe, vp treats the reinstall as failed
and removes the partial install dir, so no stale dir is left for the
check-stale step and the case fails with "interrupted stale package
removed". Kill vp.exe first so it cannot react to the dying child, then
sweep the orphaned installer children.

Claude-Session: https://claude.ai/code/session_01Q33nALG7fPwXJ3Ltp5DYku
@fengmk2
fengmk2 force-pushed the fix-env-install-interrupt-kill-order branch from 764dec7 to e0ca486 Compare August 3, 2026 05:00
@fengmk2
fengmk2 merged commit 876ae92 into main Aug 3, 2026
40 checks passed
@fengmk2
fengmk2 deleted the fix-env-install-interrupt-kill-order branch August 3, 2026 06:28
fengmk2 added a commit that referenced this pull request Aug 4, 2026
On Windows, `vp` on PATH is the trampoline in VP_HOME/bin, which runs
current/bin/vp.exe as a child and waits. The interrupt driver's child.pid
was the trampoline, so the kill order from #2299 killed the wrong process
first: the real vp.exe was torn down by `taskkill /T`, which kills the
tree in unspecified order. Whenever the npm subtree died before vp.exe,
the still-alive vp treated the reinstall as failed and removed the
partial install dir that the check-stale step asserts on. When child
enumeration returned nothing, only the trampoline died and the real vp
survived as an orphan, matching the observed zero-output timeout mode.
Unix never flaked because bin/vp is a symlink, so the killed child is
the installer.

Spawn VP_HOME/current/bin/vp directly so child.pid is the process that
runs the install on every platform, and kill the postinstall subtree via
a PID handshake in the ready file instead of PowerShell/CIM enumeration.
Stage markers and a 45s watchdog make any future failure name the stage
that hung instead of leaving a blank PTY screen.
fengmk2 added a commit that referenced this pull request Aug 4, 2026
On Windows, `vp` on PATH is the trampoline in VP_HOME/bin, which runs
current/bin/vp.exe as a child and waits. The interrupt driver's child.pid
was the trampoline, so the kill order from #2299 killed the wrong process
first: the real vp.exe was torn down by `taskkill /T`, which kills the
tree in unspecified order. Whenever the npm subtree died before vp.exe,
the still-alive vp treated the reinstall as failed and removed the
partial install dir that the check-stale step asserts on. When child
enumeration returned nothing, only the trampoline died and the real vp
survived as an orphan, matching the observed zero-output timeout mode.
Unix never flaked because bin/vp is a symlink, so the killed child is
the installer.

Spawn VP_HOME/current/bin/vp directly so child.pid is the process that
runs the install on every platform, and kill the postinstall subtree via
a PID handshake in the ready file instead of PowerShell/CIM enumeration.
Stage markers and a 45s watchdog make any future failure name the stage
that hung instead of leaving a blank PTY screen.
fengmk2 added a commit that referenced this pull request Aug 4, 2026
…2316)

The Windows `env_install_interrupt` case kept flaking after #2283 and
#2299, in two modes: the check-stale step reported "interrupted stale
package removed" instead of "exists", and a 60s zero-output step
timeout.

Root cause: on Windows, `vp` on PATH is the trampoline in `VP_HOME/bin`,
which runs `current/bin/vp.exe` as a child and waits. The interrupt
driver's `child.pid` was the trampoline, so #2299 killed the wrong
process first. The real vp.exe was then torn down by `taskkill /T`,
which kills the tree in unspecified order; whenever the npm subtree died
before vp.exe, the still-alive vp treated the reinstall as failed and
removed the partial install dir the test asserts on. When child
enumeration returned nothing, only the trampoline died and the real vp
survived as an orphan, matching the zero-output mode. Unix never flaked
because `bin/vp` is a symlink, so the killed child is the installer.

Fix, all inside the fixture:

- Spawn `VP_HOME/current/bin/vp[.exe]` directly so `child.pid` is the
process that runs the install on every platform; killing it first now
prevents the cleanup reaction.
- Kill the postinstall subtree via a PID handshake: postinstall writes
its PID into the ready file (write-then-rename), so the driver needs no
PowerShell/CIM enumeration. The npm layers in between exit on their own
once the script dies, and with vp already dead nobody reacts.
- Add stage markers and a 45s watchdog so a future failure names the
stage that hung instead of showing a blank PTY screen.

Verified on macOS with `cargo test -p vite_cli_snapshots --
env_install_interrupt`; the Windows race itself can only be exercised by
this PR's Windows CLI snapshot leg.
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.

2 participants