Skip to content

Preserve checkout paths during merge cleanup - #1687

Merged
mergify[bot] merged 4 commits into
mainfrom
lean178/1532-whitespace-worktree-cleanup
Nov 26, 2026
Merged

mergify[bot] merged 4 commits into
mainfrom
lean178/1532-whitespace-worktree-cleanup

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

A checkout path ending in whitespace could select a neighboring checkout’s PR and delete that checkout. Preserve Git paths through PR selection and local cleanup.

Closes #1532

Supersedes #1640 after #1635 changed the cleanup guard and caused a merge queue conflict. This patch uses the new guard and preserves checkout path bytes when Git returns them.

Validation

Recorded for 09b9974652c7

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0
  • Reproduced the wrong checkout deletion before the fix using two real linked worktrees with different branches at the same head.
  • The superseded head passed the full repository check and received independent approval. The resolved head is undergoing a full check and a fresh review.

Review

(filled by loopzero review)


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

  • primary, claude, 09b9974, approve

eowca and others added 4 commits November 26, 2026 07:57
Architecture-Review: unchanged; merge still verifies the PR and removes the invoking task worktree; Git path reads now retain the invoking path exactly.
Co-Authored-By: Codex <noreply@openai.com>
…ce-worktree-cleanup

# Conflicts:
#	src/loopzero/worktree.py
…ce-worktree-cleanup

# Conflicts:
#	src/loopzero/worktree.py

@loopzero-feder-positronics loopzero-feder-positronics 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.

loopzero primary review by claude on 09b9974652c77e9c02d22b9da1c0aaef44210a6c, 42.8s: approve (0 critical, 0 important, 3 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Findings without a file location:

  • suggestion: Other Git path reads still strip whitespace — _lock_review reads rev-parse --absolute-git-dir through _git(...), which still calls .strip(). worktree.is_linked_checkout and worktree._resumable_head (worktree.py:228-229 and :188) also read Git paths with the default strip(). These lines are not in the diff and fall outside the merge-cleanup scope. Today they only compare paths or lock a directory, so I found no wrong deletion through them. They are the same class of defect, though: an admin directory or checkout path with trailing whitespace becomes a different path. Consider using the path-preserving mode for these reads as well.

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/cli.py

def _git(cwd: Path, *args: str, timeout: float = GIT_TIMEOUT) -> str:
done = _proc.run(["git", *args], cwd=cwd, env_allowlist=worktree.GIT_ENV, timeout=timeout)
def _git(cwd: Path, *args: str, timeout: float = GIT_TIMEOUT, paths: bool = False) -> str:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: cli._git(paths=True) copies the existing whitespace-preserving mode in worktree._git

worktree._git(..., preserve_whitespace=True) already decodes with the filesystem encoding and surrogateescape, and removes only the final newline. The new paths=True flag in cli._git repeats that decoding. It then makes each caller strip the newline itself: _toplevel and the --git-common-dir call both use .removesuffix("\n"). This leaves two policies to keep in sync, and a future caller that forgets removesuffix gets a path ending in a newline. Smallest fix: make paths=True return done.stdout.removesuffix("\n"), the same as preserve_whitespace, and drop the per-caller removesuffix. The -z porcelain call isn't affected because it splits on NUL. Or route these calls through the shared worktree helper.

Comment thread tests/test_cli.py
monkeypatch.chdir(wt)
for branch, number in (("lz/t1", 7), ("lz/other", 8)):
arm_pr(gh, head_of(wt), branch=branch, number=number, state="MERGED", isDraft=False)
gh.append(f"api repos/{REPO}/pulls/{number}", merge_json(state='MERGED', head='f' * 40 if changed else head_of(wt), sha='e' * 40))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Rewritten test drops checks that no merge or deletion is attempted

The old test asserted that no pr merge call was made for an already-merged PR. For the head-changed case, it also asserted that no api -X call was made. The rewrite drops both checks and the gh.respond("api -X", "") fixture. The test still checks that the checkouts exist. However, a regression that calls gh pr merge on an already-merged PR, or starts remote branch deletion before refusing a moved head, would now pass. Consider restoring assert all(c["argv"][:2] != ["pr", "merge"] for c in gh.calls). Also consider asserting that no remote-ref deletion call happens when changed is true.

@eowca
eowca marked this pull request as ready for review November 26, 2026 08:25
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Merged into main as 6a467ca at 08:30 UTC

5 min in the queue, 3 min of it CI.

So far

  • ✅ Entered the queue Thu 26 Nov, 08:25 · rule main · triggered by @eowca with the @mergifyio queue command
  • ✅ Passed · draft #1708
  • ✅ Merged 08:30 · 6a467ca · squash
3 merge conditions met
  • github-review-approved · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = checks
    • check-neutral = checks
    • check-skipped = checks
  • any of · required by GitHub repository ruleset rule main: PR only, Mergify queue, existing checks required:
    • check-success = Loop-zero Eligibility
    • check-neutral = Loop-zero Eligibility
    • check-skipped = Loop-zero Eligibility

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 26, 2026
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

No description provided.

@mergify
mergify Bot merged commit 6a467ca into main Nov 26, 2026
18 checks passed
@mergify mergify Bot removed the queued label Nov 26, 2026
@eowca
eowca deleted the lean178/1532-whitespace-worktree-cleanup branch November 26, 2026 08:31
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.

Merge can remove a different checkout when the path ends in whitespace

1 participant