Repository navigation
Preserve checkout paths during merge cleanup - #1687
Conversation
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
…ce-worktree-cleanup # Conflicts: # src/loopzero/worktree.py
…ce-worktree-cleanup # Conflicts: # src/loopzero/worktree.py
There was a problem hiding this comment.
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_reviewreadsrev-parse --absolute-git-dirthrough_git(...), which still calls.strip().worktree.is_linked_checkoutandworktree._resumable_head(worktree.py:228-229and:188) also read Git paths with the defaultstrip(). 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.
|
|
||
| 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: |
There was a problem hiding this comment.
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.
| 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)) |
There was a problem hiding this comment.
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.
|
@Mergifyio queue |
✅ Merged into
|
|
No description provided. |
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
09b9974652c7uv run --group dev ruff check src tests: exit 0uv run --group dev tach check: exit 0uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0scripts/size_budget.sh: exit 0uv run --group dev pytest -q: exit 0Review
(filled by loopzero review)
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.