Repository navigation
Pin local merge cleanup to the verified PR head - #1635
Conversation
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
loopzero primary review by claude on 0cb5d94001ae34f193cd108ee815118aa244b93c, 69.7s: 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)
Native Claude output is retained in the restricted local review receipt.
| argv = ("git", "update-ref", "--stdin") | ||
| with subprocess.Popen( | ||
| argv, cwd=wt, env=build_env(GIT_ENV), stdin=subprocess.PIPE, | ||
| stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8", errors="surrogateescape", |
There was a problem hiding this comment.
suggestion: Merging stderr into the transaction's stdout turns any Git warning into a refusal
Stderr is merged into stdout, and the code only accepts the first line if it is exactly prepare: ok\n. If Git prints anything first, such as a config or deprecation warning, response will not match and cleanup is refused. That fails safe, but cleanup can never succeed in that environment, and the error shows only the warning line. Also, if Git exits without output, readline() returns "" and the error message has no detail. Smallest fix: send stderr to a separate pipe and read stdout until prepare: ok. On failure, include the stderr output in GitError.
| gd = Path(_git(wt, *_ABSOLUTE_COMMON_DIR, preserve_whitespace=True)) | ||
| ref = f"refs/heads/{name}" | ||
| with _lock_verified_ref(wt, ref, expected_head): | ||
| if branch(wt) != name: |
There was a problem hiding this comment.
suggestion: The ref lock does not stop HEAD being detached or switched before removal
The verify lock only prevents updates to refs/heads/<name>. It does not prevent changes to the worktree's HEAD symref. The branch(wt) != name check runs once, before is_dirty, the ignored-file scan and worktree remove. If someone runs git checkout --detach and commits on the detached HEAD in that window, git worktree remove still succeeds and that commit becomes unreachable. The window is narrow and outside this task's acceptance criterion, which covers commits on the branch. A cheap way to narrow it further: re-read head(wt) and branch(wt) right before worktree remove.
| raise WorktreeError(f"worktree is dirty, refusing to remove: {wt}") | ||
| _require_no_ignored_user_files(wt) | ||
| _git(gd, f"--git-dir={gd}", "worktree", "remove", str(wt)) # never the primary checkout | ||
| worktrees = _git(gd, f"--git-dir={gd}", "worktree", "list", "--porcelain", "-z") |
There was a problem hiding this comment.
suggestion: The check that the branch is checked out elsewhere can race with branch deletion
Before this change, branch -D refused atomically when the branch was checked out in another worktree. update-ref -d does not refuse in that case, so the code now runs a separate worktree list check first. Someone could run git worktree add <path> lz/<slug> between that check and update-ref -d. The new worktree's HEAD would then point to a deleted ref. The old SHA guard keeps the commits safe, but that worktree ends up on an unborn branch. The risk is low. A comment noting this trade-off would be enough.
|
@Mergifyio queue |
✅ Merged into
|
|
No description provided. |
Pin local merge cleanup to the verified PR head
Context and goal
Closes #1537
Acceptance
Base
main @ 2a11772
Base: 2a11772
Notes
This draft supersedes #1588 and preserves the ignored-file guard landed in #1556.
Validation
Recorded for
0cb5d94001aeuv 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 0Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Review