Skip to content

Resume local branch cleanup after merge removes the worktree #1116

Not planned

Description

@eowca

A merged task can lose its worktree and keep its local branch. loopzero start creates both in one step. Merge verifies the PR head, removes the worktree, then runs a separate branch deletion. An interruption or ref-lock failure in that gap leaves the branch behind. The existing regression test expects a manual deletion hint when an error is caught. If the process is interrupted, the hint can be lost too. Rerunning merge from the task path is impossible because merge discovers the task from the current checkout.

On miki, 16 local lz/* branches had no worktree and still pointed exactly at the head of a merged PR with the same branch name. Examples are #375 and #409. The snapshot confirms the residue that recovery needs to handle. It cannot distinguish interrupted merges from manual worktree removal.

Acceptance

  • Interrupt cleanup after worktree removal and before local ref deletion. Rerun the existing merge command from a surviving checkout of the same repository and finish the recorded cleanup without recreating the task worktree. A further retry is harmless.
  • Persist the existing merged PR and head proof in the owning Git metadata before removing the worktree. Retry only recorded cleanup. Preserve any branch that moved, is checked out, or lacks matching proof. Remove the recovery record when the retry reaches a terminal result.
  • Keep normal merge and dirty-worktree behavior. Use the existing merge command and add no flags or gates.

Paths

Activity

  1. eowca commented on Nov 26, 2026

    @eowca
    ContributorAuthor

    Lean178 scope ruling (26 Nov): the "persist proof in Git metadata / recovery record" acceptance conflicts with the owner rule to add no new state, so it is replaced.

    1. Close the gap by reordering, not by recording. In merge cleanup, detach the task worktree's HEAD, delete the local branch (still only when its tip equals the verified merged PR head), then remove the worktree. An interruption then leaves at most a detached, clean worktree. The next run or the existing cleanup removes it, and no branch survives without its worktree.
    2. Residue proof is derived, not stored. A local branch with no worktree whose tip equals the head of a merged PR with the same head ref can be deleted. This is checkable at any time via GitHub (commits/<sha>/pulls). Branches that moved, are checked out, or do not match keep the current behaviour (kept, with the manual hint).
    3. Keep normal merge and dirty-worktree behaviour; no flags, gates or state files.
    4. One-off: clean up the 16 existing lz/* residue branches on miki that match rule 2, and list them in the PR description.
  2. eowca commented on Nov 26, 2026

    @eowca
    ContributorAuthor

    #1192 was closed because the current main conflicts and both review rounds were used. This issue remains open for a fresh PR.

  3. eowca commented on Nov 26, 2026

    @eowca
    ContributorAuthor

    Not planned for now: its PR #1760 was closed on cost (#575 (comment)). Reopen with new evidence of a material, measured saving or failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions