Merged PRs must trigger branch and worktree cleanup reconciliation #269

Closed
opened 2026-07-06 12:49:35 -05:00 by jcwalker3 · 2 comments
Owner

Merged PR branches and local worktrees under branches/ are not being cleaned consistently. Gitea-Tools has accumulated many remote branches, and stale local worktrees create queue confusion and safety risk.

Required behavior:
After a PR merge, the controller must report whether the remote branch and local worktree are safe to clean.

Acceptance criteria:

  1. Add a cleanup reconciliation report for merged PRs.
  2. For each merged PR, report PR number, issue number, head branch, merge commit, remote branch status, local worktree status, and issue state.
  3. Remote branch deletion is allowed only if:
    • PR is merged
    • branch is not protected
    • branch head is included in master or matches merged PR head
    • no open PR references the branch
    • no active heartbeat references the branch
    • exact delete capability is allowed
  4. Local worktree cleanup is allowed only if:
    • associated PR is merged or stale policy allows cleanup
    • worktree is clean
    • HEAD matches expected branch/commit
    • no active heartbeat references it
  5. Add dry-run mode.
  6. Add confirmation-gated execute mode.
  7. Reviewer final reports must include branch/worktree cleanup status after merge.
  8. Tests cover merged branch cleanup, open PR protection, protected branches, dirty worktrees, active heartbeat protection, and dry-run no-mutation behavior.
Merged PR branches and local worktrees under branches/ are not being cleaned consistently. Gitea-Tools has accumulated many remote branches, and stale local worktrees create queue confusion and safety risk. Required behavior: After a PR merge, the controller must report whether the remote branch and local worktree are safe to clean. Acceptance criteria: 1. Add a cleanup reconciliation report for merged PRs. 2. For each merged PR, report PR number, issue number, head branch, merge commit, remote branch status, local worktree status, and issue state. 3. Remote branch deletion is allowed only if: - PR is merged - branch is not protected - branch head is included in master or matches merged PR head - no open PR references the branch - no active heartbeat references the branch - exact delete capability is allowed 4. Local worktree cleanup is allowed only if: - associated PR is merged or stale policy allows cleanup - worktree is clean - HEAD matches expected branch/commit - no active heartbeat references it 5. Add dry-run mode. 6. Add confirmation-gated execute mode. 7. Reviewer final reports must include branch/worktree cleanup status after merge. 8. Tests cover merged branch cleanup, open PR protection, protected branches, dirty worktrees, active heartbeat protection, and dry-run no-mutation behavior.
jcwalker3 added the status:in-progress label 2026-07-06 23:15:27 -05:00
Author
Owner

Claimed. Branch: feat/issue-269-merged-pr-cleanup-reconcile. Worktree: branches/feat-issue-269-merged-pr-cleanup-reconcile.

Claimed. Branch: `feat/issue-269-merged-pr-cleanup-reconcile`. Worktree: `branches/feat-issue-269-merged-pr-cleanup-reconcile`.
sysadmin removed the status:in-progress label 2026-07-07 03:39:50 -05:00
Author
Owner

Evidence update — PR #393 / Issue #390 showed branch/worktree ownership and cleanup confusion.

The author handoff for Issue #390 reported a cross-session collision: a concurrent session co-built in the same worktree, committed 91c6793, opened PR #393, then the original session replaced/expanded tests and pushed a2bd23d as the final PR head.

This is a branch/worktree ownership and reconciliation risk:

  • two sessions wrote to the same issue worktree
  • one session opened the PR while another still had uncommitted/superset work
  • final head ownership became ambiguous
  • cleanup/reconciliation needs to know which worktree/session/branch is active before another session writes or cleans it

Expected cleanup/reconciliation behavior:

  • identify local worktrees tied to open PR branches
  • identify owner/session/heartbeat if available
  • prevent concurrent write access to the same worktree
  • classify worktrees with active PRs as owned, not generic cleanup candidates
  • after merge, verify remote branch and local worktree cleanup candidates with proof
Evidence update — PR #393 / Issue #390 showed branch/worktree ownership and cleanup confusion. The author handoff for Issue #390 reported a cross-session collision: a concurrent session co-built in the same worktree, committed `91c6793`, opened PR #393, then the original session replaced/expanded tests and pushed `a2bd23d` as the final PR head. This is a branch/worktree ownership and reconciliation risk: - two sessions wrote to the same issue worktree - one session opened the PR while another still had uncommitted/superset work - final head ownership became ambiguous - cleanup/reconciliation needs to know which worktree/session/branch is active before another session writes or cleans it Expected cleanup/reconciliation behavior: - identify local worktrees tied to open PR branches - identify owner/session/heartbeat if available - prevent concurrent write access to the same worktree - classify worktrees with active PRs as owned, not generic cleanup candidates - after merge, verify remote branch and local worktree cleanup candidates with proof
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Scaled-Tech-Consulting/Gitea-Tools#269