Skip to content

Mark a force-stopped job done before releasing its shared slot - #55

Merged
HalRiveria merged 2 commits into
mainfrom
fix/force-stop-slot-order
Nov 17, 2026
Merged

HalRiveria merged 2 commits into
mainfrom
fix/force-stop-slot-order

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

What was wrong. When the dispatcher force-stops jobs after an abort, it released each job's shared SemaphoreSlim slot first and marked the job done after. If a stop landed between those two statements (a third Ctrl+C hands the stop to PowerShell), the teardown in finally saw the job as still running and released its slot a second time. The shared budget then stayed one above the limit you set for the rest of the script. Or, if the semaphore has a maximum, the extra release threw and was swallowed. The finalize passes already mark the job first.

What changed. The force-stop loop now marks the job done before releasing, like the finalize passes. The finally teardown does the same, so the two blocks stay in step; nothing can stop a finally, so that copy couldn't misfire. Either order leaves a one-statement window. Marking first can leak one slot instead, which is the failure the finalize passes already chose.

How it was tested. The window is one statement wide, too narrow to hit from a test. New harness section AL reads the dispatcher's code instead. It checks that the statement right before each if ($pkIsSharedBudget) { ...Release() } marks the job done. On main it fails (4 of 6), and with this change it passes (6 of 6). The full harness passes on Windows PowerShell 5.1 and PowerShell 7.6 (469 assertions each).

🤖 Generated with Claude Code

HalRiveria and others added 2 commits November 17, 2026 09:16
The force-stop loop released a shared SemaphoreSlim slot before setting
SlotReleased. A stop landing between the two had the teardown release the
slot again, leaving the shared budget one above its limit. The finalize
passes already mark first; the force-stop loop and the teardown now do too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The harness check now requires the statement right before each shared-budget
release to be the job's mark, not any mark earlier in the loop. The teardown
comment no longer says a marked job's slot is always released already.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria
HalRiveria merged commit 4484c7e into main Nov 17, 2026
2 checks passed
@HalRiveria
HalRiveria deleted the fix/force-stop-slot-order branch November 17, 2026 14: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