Skip to content

Warn when the Job Object can't be set up on first use, or a running program can't be added to it - #83

Merged
HalRiveria merged 3 commits into
mainfrom
fix/job-object-warnings
Nov 24, 2026
Merged

HalRiveria merged 3 commits into
mainfrom
fix/job-object-warnings

Conversation

@HalRiveria-Bot

@HalRiveria-Bot HalRiveria-Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

  1. A program's start sets up the kit's Job Object when nothing set it up first (no Initialize-ParallelKit or Invoke-PkRun before it), and it dropped the result. When Windows refused, there was no warning, though the README says the kit warns: programs ran with no cleanup if PowerShell was killed.
  2. Where the kit starts a program and adds it to the Job Object just after (StartMode AddedToJob), a refused assignment was ignored, so that program ran on unprotected with no word.

What changed

  • The setup a start does now goes through Initialize-PkChildProcessJob, warning once a session (it retries on each start after a failure, so it would otherwise warn on every one). The warning goes through Write-PkMessage, since a start can be in a worker; the function joins the worker-safe list.
  • A refused assignment warns once, naming the process, the program and Windows' error, but only for a program still running: Windows also refuses one that has already exited (error 5), which quick programs often have by then.
  • Test-only hooks: TestFailInit, TestFailAssign, and TestNoStartLock (as if .NET's start lock weren't found, the case a future .NET would bring), plus TestResetJobWarnings. C# changed, so TypesVersion goes to 12.
  • README: the cleanup-limitations bullets say when each warning shows.

How it was tested

  • New harness section BG: a failed setup on a program's start warns once over two starts (in a fresh PowerShell), a refused running program warns once with error 5, and without the start lock StartMode is AddedToJob and the fallback warns once. Programs still run and return their exit codes in each case.
  • Against a copy of this branch's kit with only the two PowerShell-side changes reverted (hooks kept), the first two cases give 0 warnings on 5.1 and 7.6; with the fix, 1 each. The start-lock case is new coverage of an existing warning, so it passes either way.
  • Full harness on Windows PowerShell 5.1 and PowerShell 7.6, one after the other: ALL PASSED on both.

Review follow-up: the warning first read the shared static LastError, which a start on another thread could change before it was read, and Assign's exception path never set it. A new Assign(process, out reason) overload returns the reason for that one call ("Win32 error N", or the exception's message), and BG checks the exception case with a disposed Process. Full harness rerun on both: ALL PASSED (605 assertions).

🤖 Generated with Claude Code

HalRiveria and others added 3 commits November 23, 2026 20:21
…rogram can't be added to it

A program's start sets the Job Object up when nothing set it up first,
and it dropped the result: a script that never called
Initialize-ParallelKit or Invoke-PkRun got no warning when Windows
refused, so its programs ran with no cleanup if PowerShell was killed.
That setup now goes through the same warning, shown once a session.

On the Process.Start path a refused assignment was ignored too. It now
warns once, naming the process and Windows' error, but only for a program
still running: Windows also refuses one that has already exited.

Harness section BG forces both failures, and a missing .NET start lock,
through new test hooks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The warning read the shared static LastError, which a start on another
thread could change first, and Assign's exception path never set it. A
new Assign overload returns the reason for that call: "Win32 error N",
or the exception's message when the process can't be read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria
HalRiveria merged commit 7082305 into main Nov 24, 2026
2 checks passed
@HalRiveria
HalRiveria deleted the fix/job-object-warnings branch November 24, 2026 01:39
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