From 73aa71c9ec35ce117df3ec42a324db5bc1a76e43 Mon Sep 17 00:00:00 2001 From: miga-heygen Date: Mon, 31 Aug 2026 21:15:39 +0000 Subject: [PATCH] fix(cli): guard PowerShell process queries against exited PIDs (#3571) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary `processIdentity` and `processParentPid` call `Get-CimInstance Win32_Process` to look up process metadata on Windows. When the target process has already exited, `Get-CimInstance` returns null and calling `.CreationDate.ToFileTimeUtc()` or `.ParentProcessId` on it throws `InvokeMethodOnNull`. The try/catch handles it, but PowerShell writes the error to stderr, which pollutes the test runner's output and causes spurious exit code 1 on Windows CI. Two fixes per call site: - Null-check the CimInstance before accessing properties (`$p = ...; if ($p) { $p.Property }`) - `-ErrorAction SilentlyContinue` + `stdio: ["pipe", "pipe", "ignore"]` to suppress any residual stderr Fixes the recurring `Tests on windows-latest` flake on main. ## Test plan - [x] All 196 CLI test files pass locally - [ ] Windows CI should no longer exit 1 from PowerShell stderr noise — Miga --- packages/cli/src/utils/orphanCleanup.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/utils/orphanCleanup.ts b/packages/cli/src/utils/orphanCleanup.ts index 146dd75ee..a9ad82c04 100644 --- a/packages/cli/src/utils/orphanCleanup.ts +++ b/packages/cli/src/utils/orphanCleanup.ts @@ -101,9 +101,9 @@ export function processIdentity(pid: number): string | null { "-NoProfile", "-NonInteractive", "-Command", - `(Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}').CreationDate.ToFileTimeUtc()`, + `$p = Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}' -ErrorAction SilentlyContinue; if ($p) { $p.CreationDate.ToFileTimeUtc() }`, ], - { encoding: "utf8", timeout: 2000 }, + { encoding: "utf8", timeout: 2000, stdio: ["pipe", "pipe", "ignore"] }, ).trim(); return created ? `windows:${created}` : null; } @@ -140,9 +140,9 @@ function processParentPid(pid: number): number | null { "-NoProfile", "-NonInteractive", "-Command", - `(Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}').ParentProcessId`, + `$p = Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}' -ErrorAction SilentlyContinue; if ($p) { $p.ParentProcessId }`, ], - { encoding: "utf8", timeout: 2000 }, + { encoding: "utf8", timeout: 2000, stdio: ["pipe", "pipe", "ignore"] }, ) : execFileSync("ps", ["-o", "ppid=", "-p", String(pid)], { encoding: "utf8",