From 0c46dec54ffe9fbbac1f155a57821984148cd5fe Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Wed, 29 Jul 2026 04:53:54 +0000 Subject: [PATCH 1/2] Fix New-RegenerateMatrix dropping packages from the matrix Split-Items computed the number of oversized groups as $itemCount % $itemsPerGroup instead of $itemCount % $JobCount. Since $itemsPerGroup is the group size and not the group count, the remainder is taken over the wrong quantity, and whenever $itemCount % $itemsPerGroup -lt $itemCount % $JobCount too few groups are widened. The generated groups then hold fewer items than were passed in, and the trailing items are silently omitted from the matrix. Nothing fails, so those packages simply never get regenerated. The azure-sdk-for-net mgmt regeneration pipeline hits this: 230 packages across 18 jobs produces groups summing to 218, dropping the last 12 packages including Azure.ResourceManager.AppService. This is visible in the emitted job keys, where the final key is se_st_17 (ending at "storagediscovery") rather than st_wo_17. The bug was easy to miss because the worked example in the comment above the function, 22 items into 5 jobs, happens to give the same answer under both formulas: 22 % 4 and 22 % 5 are both 2. Verified over all item counts 1..300 against job counts 1..30 (9000 combinations): before the fix 408 combinations lost items, after it none do, every input item appears exactly once, and group sizes still differ by at most one. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/common/scripts/New-RegenerateMatrix.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/New-RegenerateMatrix.ps1 b/eng/common/scripts/New-RegenerateMatrix.ps1 index 63d1f228e101..cbd29eeb4a1b 100644 --- a/eng/common/scripts/New-RegenerateMatrix.ps1 +++ b/eng/common/scripts/New-RegenerateMatrix.ps1 @@ -40,7 +40,11 @@ function Split-Items([array]$Items) { } $itemsPerGroup = [math]::Floor($itemCount / $JobCount) - $largeJobCount = $itemCount % $itemsPerGroup + # The remainder has to be taken over the number of groups, not the size of a group. + # Taking it over $itemsPerGroup produces too few large groups whenever + # $itemCount % $itemsPerGroup -lt $itemCount % $JobCount, and the trailing items are + # then silently dropped from the matrix. + $largeJobCount = $itemCount % $JobCount $groups = [object[]]::new($JobCount) $i = 0 From bace4a4d2070ea905cd0f06d8da5b6bf2fa8fc92 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Wed, 29 Jul 2026 04:59:56 +0000 Subject: [PATCH 2/2] Validate JobCount and MinimumPerJob are positive Both parameters are used as divisors when splitting items, so passing 0 or a negative value failed with "Attempted to divide by zero" or "Arithmetic operation resulted in an overflow" from inside Split-Items rather than with a message naming the bad parameter. Use ValidateRange so the failure happens at parameter binding, matching the declarative validation attributes already used across these scripts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- eng/common/scripts/New-RegenerateMatrix.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eng/common/scripts/New-RegenerateMatrix.ps1 b/eng/common/scripts/New-RegenerateMatrix.ps1 index cbd29eeb4a1b..c876ed1f64e2 100644 --- a/eng/common/scripts/New-RegenerateMatrix.ps1 +++ b/eng/common/scripts/New-RegenerateMatrix.ps1 @@ -6,11 +6,15 @@ param ( [Parameter()] [string]$OutputVariableName, + # Both counts are used as divisors when splitting the items, so reject zero and + # negative values here rather than failing later with a divide-by-zero. [Parameter()] + [ValidateRange(1, [int]::MaxValue)] [int]$JobCount = 8, # The minimum number of items per job. If the number of items is less than this, then the number of jobs will be reduced. [Parameter()] + [ValidateRange(1, [int]::MaxValue)] [int]$MinimumPerJob = 10, [Parameter()]