Repository navigation
Add a per-job time limit to the dispatcher - #32
Merged
Merged
Conversation
Invoke-PkProcessDispatch had no time limit, so a hung program held its slot until the run was aborted. The README's -JobPollCompleted workaround broke with a custom starter that set no Stopwatch, and gave no way to tell a timed-out job from a failed one. The dispatcher now takes -TimeoutSeconds, and a job's TimeoutSeconds key overrides it (0 opts out). An overrunning program is killed with everything it started, and its job goes through -JobFinalize with TimedOut set. Invoke-PkProcessBatch uses the same code in place of its own poll closure and gains a per-command key; a bad value there gives that command a StartError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… run -TimeoutSeconds was an int, so 0.4 bound as 0 and meant no limit. A process the time check couldn't read threw and ended the whole dispatch; it's now just not timed. The last check before an abort's force-stop no longer kills jobs one at a time, since whatever is still running is force-stopped together right after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PowerShell returns nothing for HasExited on a Process it can't read rather than throwing, so the time check needs no catch of its own. A never-started Process reaches the "couldn't be stopped" path, which makes it testable: one warning, not a taskkill on every pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong:
Invoke-PkProcessDispatchhad no time limit, so a hung program held its slot until the run was aborted. The README's-JobPollCompletedworkaround broke with a custom starter that set noStopwatch(under StrictMode it threw and ended the run; otherwise the limit silently never fired), and a killed job looked like any other non-zero exit.What changed:
-TimeoutSeconds(default 0, no limit). A job'sTimeoutSecondskey overrides it, and 0 opts the job out.-JobFinalizewith$job['TimedOut'] = $true, and other jobs carry on.Stopwatchis still timed. A job whose.Procisn't a process isn't timed.Invoke-PkProcessBatchuses the same code instead of its own poll closure, and gains a per-commandTimeoutSecondskey. A bad value gives that command aStartError, so every command still gets a result.-TimeoutSecondsis now a[double]on both, so0.4no longer rounds to 0 and silently means no limit.Behavior users can notice:
TimeoutSecondsnow sets the kit's limit, and a value that isn't a number fails that job's start.TimeLimitandTimedOutare new reserved job keys.Tested: the harness passes on 5.1 and 7 (322 assertions, none skipped), with a new section AC. 16 of its assertions failed on
mainbefore the feature. The fractional tests fail on an[int]parameter, and the warning test fails without the one-try rule (12 warnings instead of 1). A plain callback that reads the caller's own$TimeoutSecondsstill sees the caller's value, on the main thread and in a worker.Not covered: if taskkill reports failure on a single program but the program did die (a child it couldn't kill, say), the job may show
TimedOut = $false. That's existing behavior inStop-PkProcessTree, and reproducing it needs an elevated child process.🤖 Generated with Claude Code