Skip to content

Count a tree kill as done when taskkill reports a partial failure - #41

Merged
HalRiveria-Bot merged 2 commits into
mainfrom
fix/tree-kill-reporting
Nov 16, 2026
Merged

HalRiveria-Bot merged 2 commits into
mainfrom
fix/tree-kill-reporting

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

What was wrong

taskkill /T exits non-zero if any process in the tree couldn't be killed, even when it killed the program itself. With one program, Stop-PkProcessTree took that at face value and returned $false, so a job killed for its time limit could come back with TimedOut = $false.

The most common trigger is a cmd /c wrapper. Taskkill kills the children first, cmd ends on its own as soon as its child dies, and taskkill then reports it as "no running instance". The harness's existing batch-timeout test hit this intermittently: on main it failed 4 times in 8 on Windows PowerShell 5.1 and 2 in 8 on PowerShell 7. A child that refuses termination triggers it every time.

What changed

Stop-PkProcessTree already counted a partial taskkill failure as a kill when one of several listed processes was gone afterwards. It now does the same for a single program. A program that happened to exit on its own in the instant before taskkill also counts as killed. Of the kit's callers, only the time limit reads the result, and it only kills a program that's already past its limit.

How it was tested

New harness section AJ makes a cmd /c ping tree's ping child refuse PROCESS_TERMINATE, through its DACL, and then checks two things:

  • Stop-PkProcessTree returns $true for the killed parent.
  • A dispatcher job killed for its time limit has TimedOut = $true.

Both failed before the fix on 5.1 and 7. If taskkill runs elevated, it may ignore the DACL. The checks still hold then, but they don't exercise the failure path, and the test message says so. Separately, the batch-timeout case run 15 times now sets TimedOut every time on both runtimes. The harness passes on 5.1 and 7 (438 assertions each).

🤖 Generated with Claude Code

HalRiveria and others added 2 commits November 16, 2026 14:19
taskkill /T exits non-zero if any process in the tree couldn't be killed, even when it killed the program itself. For a single program, Stop-PkProcessTree then returned $false, so a job killed for its time limit could show TimedOut = $false. It happened most often with `cmd /c`: taskkill kills the children first, cmd ends on its own as soon as its child dies, and taskkill then finds it already gone. It also happens when a child can't be killed.

The "any listed process is now gone" check, which already covered several programs, now covers one too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit ff90d82 into main Nov 16, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the fix/tree-kill-reporting branch November 16, 2026 19:28
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