Skip to content

Read a job's CancelToken case-insensitively, and refuse keys that differ only in case - #126

Merged
HalRiveria merged 1 commit into
mainfrom
fix/case-sensitive-canceltoken
Dec 3, 2026
Merged

HalRiveria merged 1 commit into
mainfrom
fix/case-sensitive-canceltoken

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

What was wrong

Invoke-PkRunspaceBatch gives a worker that declares $CancelToken the run's own token, unless the job supplies one. It checked that with $job.ContainsKey('CancelToken'), which goes by the job hashtable's own comparer. A case-sensitive job ([hashtable]::new()) with a canceltoken key failed that check, and the kit's token then overwrote the caller's in the worker's case-insensitive copy, with no warning. Everything else there already reads job keys case-insensitively, as parameter binding does.

The same copy collapsed two keys that differ only in case (Id and id) into one, the later silently winning.

What changed

  • The CancelToken check reads the worker's case-insensitive copy of the job, so a case-sensitive job's canceltoken is its own token.
  • A job with two keys that differ only in case is refused, with a message naming both: up front for -JobParams ("Nothing was started"), and as it arrives for -NextJobProvider.

How it was tested

Four new assertions in harness section BC: a case-sensitive job's canceltoken reaches the worker, through -JobParams and through -NextJobProvider; and a job with Id and id is refused, through each.

Before the fix (main's ParallelKit.ps1 with the new harness), 5.1 and 7 alike:

  [FAIL] -JobParams: a case-sensitive job's 'canceltoken' reaches the worker, not the kit's token (got the caller's: False; )
  [FAIL] -NextJobProvider: the same (got the caller's: False; )
  [FAIL] -JobParams: a case-sensitive job with 'Id' and 'id' is refused before anything starts (; ran 2)
  [FAIL] -NextJobProvider: the same, refused as it arrives (; ran 0,2)
4 FAILED, 17 passed

After: section BC passes on both, and the full harness passes on Windows PowerShell 5.1 (797 assertions) and PowerShell 7 (797 assertions).

…fer only in case

A case-sensitive [hashtable]::new() job with 'canceltoken' got the kit's own token in its place, since the check used the job's own comparer and the worker's copy is case-insensitive. Two keys differing only in case collapsed into one, the later silently winning; such a job is now refused, up front for -JobParams and as it arrives for -NextJobProvider.
@HalRiveria
HalRiveria merged commit 20115f2 into main Dec 3, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the fix/case-sensitive-canceltoken branch December 3, 2026 14:55
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