Add authorized cleanup path for reviewer scratch worktrees #534

Closed
opened 2026-07-08 04:10:36 -05:00 by jcwalker3 · 1 comment
Owner

Problem

During PR #512 cleanup, the reviewer scratch worktree remained present:

branches/review-pr512-submit, detached @ 3d11e1f

The merged-cleanup reconciler does not currently own reviewer scratch cleanup, and there is no authorized path for safely removing detached reviewer worktrees after a PR has merged.

Risk

Reviewer scratch worktrees will accumulate, or operators may remove them manually without lease/state validation.

Required behavior

  1. Add an explicit cleanup path for reviewer scratch worktrees.
  2. Only allow cleanup after the associated PR is merged/closed and no active reviewer lease requires the worktree.
  3. Verify the scratch worktree is clean before removal.
  4. Fail closed if the worktree has uncommitted changes, unknown ownership, active lease state, or ambiguous PR mapping.
  5. Include reviewer scratch cleanup in dry-run output separately from author worktree cleanup.

Acceptance criteria

  • Add tests for safe cleanup of clean detached review-pr<N>-submit worktrees after PR merge.
  • Add tests blocking cleanup when the reviewer scratch worktree is dirty.
  • Add tests blocking cleanup when an active reviewer lease exists.
  • Add tests proving reviewer scratch cleanup is never treated as an author worktree cleanup.
  • Update canonical cleanup reports to list reviewer scratch worktrees as separate cleanup targets.

Non-goals

  • Do not weaken reviewer lease checks.
  • Do not remove dirty worktrees.
  • Do not treat reviewer scratch worktrees as author worktrees.
  • Do not bypass root/worktree safety guards.

Related context

  • Observed after PR #512 cleanup.
  • Related cleanup/guard work: #401, #402, #404, #517, #528, #532.
  • This issue is specifically about an authorized cleanup path for detached reviewer scratch worktrees named review-pr<N>-submit; it is not general author worktree cleanup or merged issue-worktree alias discovery.
## Problem During PR #512 cleanup, the reviewer scratch worktree remained present: `branches/review-pr512-submit`, detached @ `3d11e1f` The merged-cleanup reconciler does not currently own reviewer scratch cleanup, and there is no authorized path for safely removing detached reviewer worktrees after a PR has merged. ## Risk Reviewer scratch worktrees will accumulate, or operators may remove them manually without lease/state validation. ## Required behavior 1. Add an explicit cleanup path for reviewer scratch worktrees. 2. Only allow cleanup after the associated PR is merged/closed and no active reviewer lease requires the worktree. 3. Verify the scratch worktree is clean before removal. 4. Fail closed if the worktree has uncommitted changes, unknown ownership, active lease state, or ambiguous PR mapping. 5. Include reviewer scratch cleanup in dry-run output separately from author worktree cleanup. ## Acceptance criteria - Add tests for safe cleanup of clean detached `review-pr<N>-submit` worktrees after PR merge. - Add tests blocking cleanup when the reviewer scratch worktree is dirty. - Add tests blocking cleanup when an active reviewer lease exists. - Add tests proving reviewer scratch cleanup is never treated as an author worktree cleanup. - Update canonical cleanup reports to list reviewer scratch worktrees as separate cleanup targets. ## Non-goals - Do not weaken reviewer lease checks. - Do not remove dirty worktrees. - Do not treat reviewer scratch worktrees as author worktrees. - Do not bypass root/worktree safety guards. ## Related context - Observed after PR #512 cleanup. - Related cleanup/guard work: #401, #402, #404, #517, #528, #532. - This issue is specifically about an authorized cleanup path for detached reviewer scratch worktrees named `review-pr<N>-submit`; it is not general author worktree cleanup or merged issue-worktree alias discovery.
jcwalker3 added the status:in-progress label 2026-07-08 22:13:44 -05:00
Author
Owner

Issue claim heartbeat

<!-- gitea-issue-claim-heartbeat:v1 --> **Issue claim heartbeat** - kind: claim - issue: #534 - branch: feat/issue-534-reviewer-scratch-cleanup - phase: claimed - profile: prgs-author - pr: none - blocker: none - next_action: create worktree and begin implementation
sysadmin removed the status:in-progress label 2026-07-08 22:20:51 -05:00
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#534