Skip to content

Keep continue and break in a callback inside the callback - #39

Merged
HalRiveria-Bot merged 2 commits into
mainfrom
fix/callback-continue-break
Nov 16, 2026
Merged

HalRiveria-Bot merged 2 commits into
mainfrom
fix/callback-continue-break

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

What was wrong

PowerShell sends continue and break to the nearest loop on the call stack, even across a module boundary. In a callback, that loop is one of the kit's own. For example, a continue in -OnComplete skipped that job's dispose, slot release and group count, so the dispatcher looped forever after every program had finished. A break dropped running jobs from tracking, or the rest of a worker's results in -ResultHandler. The same applied to every other callback and to the message handler. It's easy to hit, because continue is the usual way to skip an item in a loop.

What changed

  • Every call to a user callback goes through a new private Invoke-PkCallback. It runs the callback inside a do { } while ($false) of its own, so either keyword only ends the callback, as return would. The kit carries on and warns once per callback per call, naming the callback. It hands back exactly what the callback returned, so a collection returned whole (return ,$list) stays one value. This covers all the dispatcher, batch and runspace-engine callbacks: -OnComplete, -JobFinalize, -JobStarter, -JobPollCompleted, -JobAbortCleanup, -GroupCompleteCallback, -GroupReleaseCheck, -AbortPollCallback, -GroupProvider, -JobBuilder, -ResultHandler, -PollCallback, -NextJobProvider and -JobCrashedHandler.
  • The message handler gets the same wrap inside Invoke-PkMessageHandler. Its warning goes to the console, once per handler, since a warning is itself a message.
  • A labeled break aimed at the caller's own loop still leaves the call. The call stops there and kills its programs.
  • The README says to use return, and what the kit does with each keyword.

How it was tested

New harness section AH runs each keyword in each callback in its own [PowerShell] with a 20 s limit, so a hang fails instead of stalling the suite. Each case checks that the run finishes with the right results and exactly one warning. All 30 cases failed before the change: most hung, and the rest lost results or gave no warning. There are also checks that a group returned whole as a one-element array stays an array, and that a labeled break out of -OnComplete leaves the call with no programs left running. The harness passes on Windows PowerShell 5.1 and PowerShell 7 (431 assertions each).

🤖 Generated with Claude Code

HalRiveria and others added 2 commits November 16, 2026 13:39
PowerShell sends continue and break to the nearest loop on the call stack, across the module boundary, so one in a callback landed in one of the kit's own loops. A continue in -OnComplete skipped that job's dispose, slot release and group count and the dispatcher looped forever; a break dropped running jobs from tracking or the rest of a worker's results. The same went for every other callback and for the message handler.

Every call to a user callback now goes through Invoke-PkCallback, which runs it inside a do/while of its own, so either keyword only ends the callback, as return would, and the kit warns once per callback per call, naming it. The message handler gets the same wrap, with its warning on the console. The README says to use return, and what a labeled break to the caller's own loop does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Invoke-PkCallback now hands back exactly what the callback returned, so a collection returned whole stays one value. A message handler that uses continue or break counts as having returned, with one console warning per handler instead of one per message. Adds harness checks for both and for a labeled break out of a callback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit 26708f4 into main Nov 16, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the fix/callback-continue-break branch November 16, 2026 18:50
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