Skip to content

fix(pr-pipeline): rotate the branch-cleanup start across every branch - #11276

Merged
kyle-sexton merged 3 commits into
mainfrom
fix/8957-branch-cleanup-rotation
Oct 30, 2026
Merged

kyle-sexton merged 3 commits into
mainfrom
fix/8957-branch-cleanup-rotation

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Closes #11301

A review of the copy in pr-pipeline-sandbox#254 found this bug. That copy shipped with the fix, so this PR brings the source script in line with it and keeps the two identical.

Summary

When the branch count divided the branch-cleanup plan stage's stride, every run started at the same branch. Kept branches early in the listing that cost many reads then spent the evaluation share every run, and the branches after them were never evaluated.

Fix

plan() in .github/scripts/branch-cleanup/cleanup.mjs now moves the step up from stride % branches to the nearest value coprime with the branch count. Each run's start is run number × step mod the count, so successive runs start at every branch in turn. When the count and the stride were already coprime, the start does not change.

Verification

  • New test, "118 branches when the count divides the stride: successive runs evaluate every branch". It uses a 600-call budget, so the stride is 118. The first 100 branches link four closed issues and one open issue, at six reads each. Across 118 runs, it checks that every branch is evaluated at least once.
    • Before the fix it fails: 94 of 118 branches are evaluated.
    • After the fix it passes.
  • node --test cleanup.test.mjs workflow.test.mjs: 29 pass, 0 fail.
  • scripts/check-affected.sh --tests: 9 checks pass, 7 skipped; nothing fails.

Related

🤖 Generated with Claude Code

When the branch count divided the stride, every run started at the same
branch, and costly kept branches early in the listing hid the later ones
from every run. The step is now the stride moved up to the nearest value
coprime with the branch count.

Refs: #8957

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T14:15:01.563810Z 67f613e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review needs no new review of bb81126fa05b498e310d7a5d89ebcc598b22318e: no file of this pull request changed since the review of 57317a8.

No security issues found.

The change only alters which branch plan() in .github/scripts/branch-cleanup/cleanup.mjs evaluates first. It moves the rotation step up to the nearest value coprime with the branch count. It does not change how any branch is judged deletable, so a different starting branch cannot delete anything that would otherwise be kept.

  • The new while loop is bounded. step starts below the branch count and increments until coprime, and branches.length - 1 is always coprime. Empty, single-branch and no-limit (stride 0) cases leave the start at 0, as before.
  • GITHUB_RUN_NUMBER was already parsed and defaulted to 0 before this change. It still only feeds arithmetic and never reaches a path, command or API argument.
  • The new test runs plan() with DRY_RUN set against a stubbed fetch, so it makes no real network or credential calls.
  • The diff touches no trusted path, trust control, token scope, kill switch, merge hold or plugin manifest.
  • The PR description contains no embedded instructions.

critical-findings: 0

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

claude-review needs no new review of bb81126fa05b498e310d7a5d89ebcc598b22318e: no file of this pull request changed since the review of 57317a8.

No findings. I read the full diff and the PR context, and checked the change against plan() in .github/scripts/branch-cleanup/cleanup.mjs. I did not run the tests, and I did not check deleteBudget(cap), so I did not confirm the claim that a 600-call budget gives a stride of 118. The test results in the PR body are author-claimed and unverified by me.

Correctness of the step fix (cleanup.mjs:209-215)

  • step starts at stride % n and increases until gcd(step, n) === 1. It always stops before reaching n, because n-1 is coprime with n.
  • A stride that is a multiple of n gives step = 0, then 1. That is the case the PR fixes.
  • When gcd(stride, n) === 1 already, gcd(stride % n, n) is also 1. step stays stride % n, so the start is unchanged, as the PR says.
  • An empty listing gives step = 0. n === 1 skips the loop and start is 0. An unbounded evaluation share (stride === 0) skips the loop and start is 0. These match the old behaviour.
  • With step coprime to n, run × step mod n covers every residue across n consecutive run numbers. That is the property the fix needs.

Test (cleanup.test.mjs)

  • The new test covers the failing case: a branch count equal to the stride, with expensive kept branches early in the listing. It checks that all 118 branches are evaluated across 118 consecutive runs. It would fail if the step stayed at stride % n.

Closing issue

  • The PR context lists no closing issue sections, only Refs: #8957, so there are no acceptance criteria to check.

Other checks

  • Manifests: not touched.
  • Embedded instructions: none in the PR context.
  • Security and cost: no hold applies. The change only alters which branch each run starts at, and it spends no billed resource.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

The pr-verify verifier failed head 57317a8325643ee380973f0b0bdbf3b4285c2079. What it wrote, as data:

What it wrote (21 lines)
Summary: The PR is linked to #8957 with `Refs:`. That makes it a partial delivery, and the body must
  name the work still left for later. It doesn't: it says "Nothing in #8957 remains after this
  merges, and #8957 can then close." That breaks the partial-delivery rule. Both of #8957's
  done-when items are for pr-pipeline-sandbox and were delivered by sandbox#254. This PR only fixes
  the start-rotation bug in claude-code-plugins' own cleanup script, which #8957 doesn't ask for.
  The code fix itself looks correct and is tested.
- PR body: it uses `Refs: #8957` but says nothing in #8957 remains. A `Refs` PR must name its
  delivered part and the work left for later. Fix the link: either file a separate issue for the
  source-script rotation bug and link this PR to it with Closes, or rewrite the body to name the
  part of #8957 delivered here and the work that remains. Don't claim the whole issue is done.
- PR body: #8957 asks for branch cleanup in pr-pipeline-sandbox (a workflow, a script copy and a
  config leaf there). This PR doesn't deliver any of that. It changes claude-code-plugins' own
  `.github/scripts/branch-cleanup/cleanup.mjs`, which the issue doesn't ask for, so a separate issue
  is the better spec for it.
- .github/scripts/branch-cleanup/cleanup.mjs:212: the logic looks correct. When the stride is 0 or
  there is at most one branch, behaviour is unchanged. When the branch count divides the stride, the
  step goes from 0 to 1. The loop always stops below the branch count, because count-1 is coprime
  with it. When the stride and count were already coprime, the start is the same as before.
- .github/scripts/branch-cleanup/cleanup.test.mjs:332: the new test covers the case where the count
  divides the stride. It checks that all 118 branches are evaluated across 118 runs. The PR says
  this test fails without the fix (94 of 118 evaluated), so it is a real regression test.

This pull request leaves the merge queue, and ci-status holds it out while it carries pr-verify-failed. A pr-verify pass at a new commit removes the label.

@github-actions github-actions Bot added the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Oct 30, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 30, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 30, 2026
@github-actions github-actions Bot removed the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Oct 30, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 3bde16f Oct 30, 2026
42 checks passed
@kyle-sexton
kyle-sexton deleted the fix/8957-branch-cleanup-rotation branch October 30, 2026 16:14
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.

fix(pr-pipeline): branch-cleanup starts every run at the same branch when the count divides the stride

1 participant