Skip to content

ci: delete head branches of closed-unmerged pull requests on a schedule - #111

Merged
lidge-jun merged 1 commit into
devfrom
codex/closed-pr-branch-cleanup
Sep 9, 2026
Merged

ci: delete head branches of closed-unmerged pull requests on a schedule#111
lidge-jun merged 1 commit into
devfrom
codex/closed-pr-branch-cleanup

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

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 root npm test script.
  • .github/workflows/cleanup-closed-pr-branches.yml — schedule-only (daily 06:45 UTC), no workflow_dispatch (a branch-selected dispatch would run that branch's body with contents: write), workflow permissions: {}, job-scoped contents: write + pull-requests: read, SHA-pinned actions.

codexclaw adaptations

  • Disposable namespace is codex/ only (opencodex also has ingw/). fix/, docs/ and other prefixes are persistent work here — a closed PR using them is not abandonment evidence.
  • checkout pinned to the v7 SHA already used in this repo; github-script pinned to the v9 SHA enforce-pr-target.yml uses.

Why now

Live audit (2026-09-09): 38 remote branches, 70 PRs (63 merged / 5 open / 2 closed-unmerged). delete_branch_on_merge is 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 from dev to main.

Verification

  • node --test .github/scripts/closed-pr-branch-cleanup.test.cjs — 15/15 pass.
  • Full suite (CODEXCLAW_SKIP_REPOMAP_SMOKE=1 npm test): 2764 tests, 0 fail; README badges and inventory updated via inventory.mjs --write --tests 2764.
  • inventory.mjs --check --tests 2764 OK; gate.mjs OK.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 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-09-09T05:31:34.314070Z 645f43e 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +126 to +130
await github.rest.git.deleteRef({
owner,
repo,
ref: `heads/${entry.branch}`,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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
@lidge-jun
lidge-jun force-pushed the codex/closed-pr-branch-cleanup branch from 645f43e to 3534a2d Compare September 9, 2026 15:56
@lidge-jun
lidge-jun merged commit 1ca63c8 into dev Sep 9, 2026
10 checks passed
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.

1 participant