Repository navigation
fix(pr-pipeline): split branch cleanup into plan and delete jobs with an atomic delete - #10290
Conversation
… an atomic delete The plan job reads branches, issues and pull requests with a token that writes nothing and hands at most max-deletes-per-run candidates to the delete job as an artifact. The delete job alone holds contents: write, reads no issue or pull request text, and refuses a list for another repository, over the cap, or with an entry outside the rule's shape. Each delete is one GraphQL updateRefs with beforeOid set to the listed tip, so a push that lands after the delete-time re-read makes GitHub refuse the delete; the branch is reported as skipped. Closes #8958 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-cleanup-hardening
…-cleanup-hardening
…-cleanup-hardening
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
claude-review reviewed No blocking findings. I read the whole diff and checked the changed Closing issue #8958, acceptance criteria
Checks
Not verified: GitHub's refusal of a stale Cost: none. The change adds no paid resource and no permission, and it adds one extra job run per day that spends only GitHub Actions minutes already in use. |
|
claude-security-review reviewed No security issues found in this change. critical-findings: 0 I read the whole diff and the PR context, plus What I checked:
Not verified: the live Spend: none beyond ordinary Actions minutes. This adds a second job in the existing workflow, with no billed resource or plan change. |
The write-ahead ledger line said deleted even when GitHub refused the delete because the tip moved. A second line with notDeletedAt and the reason now records that the branch still stands. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-cleanup-hardening
…-cleanup-hardening
…header The workflow header still said a deleted branch is restored from its ledger SHA, without the second line a refused delete writes. It now says a branch with a notDeletedAt line still stands and is not restored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-cleanup-hardening
…re-run The delete job runs npm ci, so it names npm-fetch.npmrc as npm's global config, as the plan job does. The plan job outputs the artifact name it uploaded under, and the delete job downloads that name: re-running only a failed delete job keeps the plan job's outputs from the attempt that uploaded the list, where the delete job's own run_attempt named an artifact no attempt uploaded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closes #8958
Summary
The branch-cleanup job held
contents: writewhile it read issue and pull request text, and its delete could not say which tip it expected, so a push landing between the re-read and the delete was removed. This splits the job and makes the delete check the tip on GitHub's side, per the decision record on #8958. Item 3 (stopped-run branches of closed issues) is already done on main and is closed there with that evidence; the test "a stopped lane run's branch is deleted once its issue closes" still passes.Fix
.github/workflows/maintenance-delete-stale-branches.yml: two jobs.plan(contents,issues,pull-requestsread) evaluates every branch and uploads at mostmax-deletes-per-runcandidates asbranch-cleanup-candidates-<run>-<attempt>.delete(contents: write,pull-requests: read) runs only when the plan listed something and the run is not a dry-run. It checks the kill switch again, downloads that list, re-reads each tip and its open pull requests, and deletes. It reads no issue or pull request text.persist-credentials: false. No permission is added: the write grant moves to the job that reads no untrusted text, andissues: readleaves that job..github/scripts/branch-cleanup/cleanup.mjs:STAGE=plan|delete. The plan stage's client refuses every request butGET, dry-run or not.updateRefsper branch, withbeforeOidset to the listed tip andafterOidall zeros, in place ofDELETE git/refs/heads/<branch>. One branch per call, because GitHub applies a list atomically and one refused update would refuse them all.errorslist returned with HTTP 200. A refused delete re-reads the tip: a moved tip is reported as skipped, and anything else as a failed delete.CALL_BUDGET(600).docs/conventions/pr-pipeline/README.md, "Branch cleanup": describes the two jobs and the atomic delete, and drops the "the API takes no expected SHA" text..changes/pr-pipeline/fix-8958-branch-cleanup-split-5c2e7a19.md: patch fragment.Sources:
updateRefs: "RefUpdate.beforeOid specifies that the given reference needs to point to the given value before performing any updates"; "A value of 0000000000000000000000000000000000000000 can be used to delete a reference"; "All updates are performed atomically".actions: read.Verification
node --test .github/scripts/branch-cleanup/*.test.mjs: 27 pass, 0 fail. New tests:updateRefsper branch, withbeforeOidequal to the listed tip;beforeOidwith HTTP 200 and an errors list, as GitHub does);workflow.test.mjs.actionlintandzizmor --offlineon the workflow: no findings. Runner policy passed.node --test .github/actions/resolve-config/callers.test.mjs .github/actions/log-api-budget/*.test.mjs: 273 pass.scripts/workflow-self-paths.test.sh: 35 pass.scripts/check-app-key-references.sh --checkandscripts/check-changelog-fragments.sh --checkare clean.updateRefsdelete against GitHub. Its refusal of a stalebeforeOidrests on the docs quoted above.Checks a person runs:
dry-run: falseon a disposable branch, to confirm the live delete and the ledger.Related
🤖 Generated with Claude Code