ci: delete head branches of closed-unmerged pull requests on a schedule - #111
Conversation
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 645f43e379
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await github.rest.git.deleteRef({ | ||
| owner, | ||
| repo, | ||
| ref: `heads/${entry.branch}`, | ||
| }); |
There was a problem hiding this comment.
Make ref deletion conditional on the planned SHA
If an actor pushes to or recreates an eligible codex/* branch after listBranches captures its SHA but before this loop reaches it, git.deleteRef deletes the current ref unconditionally; the GitHub DELETE-ref endpoint does not compare the ref with the planned SHA, so such a move normally succeeds rather than producing the 422 anticipated below. This bypasses the MOVED_SINCE_CLOSE safeguard and can destroy newly pushed work. Perform the deletion through an atomic expected-SHA mechanism such as git push --force-with-lease=<ref>:<planned-sha> instead.
Useful? React with 👍 / 👎.
delete_branch_on_merge covers merged heads only, so closed-unmerged PR heads (superseded agent work, retargeted stacks) accumulate forever. Port the opencodex scheduled cleanup: a pure, unit-tested planner with keep rules for merged/open PR heads, stacked bases, fork heads, grace period, branch-moved-since-close, and unknown tips, driven by a schedule-only workflow with job-scoped contents:write. codexclaw adaptation: the disposable namespace is codex/ only. fix/, docs/ and other prefixes stay with human judgment even when a closed PR used them. Scheduled workflows run from the default branch, so the job starts when this change is promoted from dev to main. Reference: plugins/codexclaw/skills/dev-devops/references/branch-lifecycle.md
645f43e to
3534a2d
Compare
What
Ports opencodex's scheduled closed-PR branch cleanup (opencodex#2664) to codexclaw, per dev-devops branch-lifecycle.md §3.
.github/scripts/closed-pr-branch-cleanup.cjs— pure deletion planner with the full keep-rule set (protected lines, merged/open PR heads, base-of-open-PR, fork heads by repo id, missing closed_at, 14-day grace, disposable namespace, branch-moved-since-close, unknown tip)..github/scripts/closed-pr-branch-cleanup.test.cjs— 15 unit tests, wired into the rootnpm testscript..github/workflows/cleanup-closed-pr-branches.yml— schedule-only (daily 06:45 UTC), noworkflow_dispatch(a branch-selected dispatch would run that branch's body withcontents: write), workflowpermissions: {}, job-scopedcontents: write+pull-requests: read, SHA-pinned actions.codexclaw adaptations
codex/only (opencodex also hasingw/).fix/,docs/and other prefixes are persistent work here — a closed PR using them is not abandonment evidence.Why now
Live audit (2026-09-09): 38 remote branches, 70 PRs (63 merged / 5 open / 2 closed-unmerged).
delete_branch_on_mergeis off on this repo, so 30 merged-PR head branches have accumulated; this workflow covers the closed-unmerged row going forward (currently 1 eligible branch:docs/validate-skill-catalog, PR #5, closed 2026-08-14, tip unchanged). Enabling the setting and a one-time evidenced cleanup of the 30 merged heads are proposed separately — they are host settings/deletions, not this PR.Activation caveat
Scheduled workflows run only from the default branch (
main). This job starts when the change is promoted fromdevtomain.Verification
node --test .github/scripts/closed-pr-branch-cleanup.test.cjs— 15/15 pass.CODEXCLAW_SKIP_REPOMAP_SMOKE=1 npm test): 2764 tests, 0 fail; README badges and inventory updated viainventory.mjs --write --tests 2764.inventory.mjs --check --tests 2764OK;gate.mjsOK.