Repository navigation
Description
Summary
On Windows PowerShell 5.1, a script run that times out can end with a terminating error instead of a result whose run state is TimedOut. Invoke-IslProcess ends the timed-out process tree with & taskkill.exe /PID <id> /T /F 2>&1 | Out-Null. When taskkill writes to its error stream, which it does for a process that is already gone, Windows PowerShell 5.1 turns the redirected line into an error record, and with $ErrorActionPreference = 'Stop' in a scope the function sees that record is terminating. PowerShell 7 does not do this.
The preference is Stop in every pwsh and powershell step of GitHub Actions and in any script that follows ERR-01 and is started with -File. Windows PowerShell 5.1 is the host the harness exists for.
Findings
| Where | What |
|---|---|
Private/Invoke-IslProcess.ps1:241 |
The scheduled-task path (-Context System, and -Credential). After Stop-ScheduledTask it lists every process whose command line carries the run id and calls taskkill for each. Stop-ScheduledTask has usually ended some of them already, and /T ends the children of the first, so a later id in the list is often gone: taskkill answers ERROR: The process "<id>" not found. with exit code 128. |
Private/Invoke-IslProcess.ps1:101 |
The direct path has the same statement. The process is normally still there when it times out, so taskkill succeeds, but anything it writes to its error stream has the same effect. |
| both | The exit code of taskkill is never read (ERR-23), so a process tree that could not be ended is not reported either. |
Evidence
-
quality-gates.ymlrun 45145190738, jobWindows PowerShell 5.1, on the branch of test: decide the skip conditions of four tests during discovery #85, which is the first change that lets the SYSTEM-context integration tests run:SYSTEM context.times out and cleans up the taskfailed withRemoteException: ERROR: The process "2020" not found.atInvoke-IslProcess.ps1:241. The same test passed in run 45140123789 on the same branch one commit earlier, and on a lab device where the preference wasContinue, so the failure depends on timing and on the preference. -
On Windows 11, in a script started with
-File:Host $ErrorActionPreference& taskkill.exe /PID 999999 /T /F 2>&1 | Out-NullWindows PowerShell 5.1.26100 Stopterminating RemoteException: ERROR: The process "999999" not found.Windows PowerShell 5.1.26100 Continueno error, exit code 128 PowerShell 7.6.10 Stopno error, exit code 128 PowerShell 7.6.10 Continueno error, exit code 128
Proposed change
- End a process tree in one private function that starts
taskkill.exeas a process with its streams redirected by .NET, so that nothing it writes becomes a PowerShell error record on either version. - Treat a process that is already gone as the outcome the cleanup wants, and warn only when the process is still running afterwards.
- Test the function on Windows PowerShell 5.1 with the preference set to
Stopand an id that does not exist, which is the failing case made deterministic.
Risk
Low. The cleanup runs only after a timeout. The change has to be run on a lab device as SYSTEM, where the scheduled-task path runs, and in CI under Windows PowerShell 5.1 with #85 in place.
Discovered and written up with Claude Code.
Activity
fix(harness): end a timed-out run whatever the WhatIf preference