Repository navigation
[3687 by Claude Opus 5.5] Follow-up fix fails with "a branch named … already exists" when creating the worktree - #3708
Conversation
…xists" when an earlier run left the PR's local branch behind. One acceptance criterion is handled differently than written (unpushed commits, below), so please check that before merging. What was going wrong. The worker already had a path for reusing an existing local branch. The four failures on #3644 came through it (the "Cannot create worktree:" prefix only comes from there), so its existence check said "no such branch" while git still saw one. The check worked by listing branches (`git show-ref --heads`), but `git worktree add -b` reads the branch ref itself. When the two disagree, the code fell through to `-b` and failed on every later run. I couldn't reproduce that disagreement in this container (git 2.39; the worker image is Alpine with a newer git), so this is the most likely cause, not a confirmed one. Changes in `packages/core/src/git/worktreeCreation.ts`: - Existence check: it now looks the ref up directly, the same way `git worktree add -b` does. If the branch exists but its tip commit is missing from the clone, the run fails with a message naming the branch and changes nothing. - Fallback: if `git worktree add -b` still says the branch already exists, the worker reuses the existing branch the same safe way. If the branch can't be read, the run fails with a message naming it. Runs that need a brand-new branch still refuse an existing one. How each stale state is handled now: - Same as remote: reused as is. - Behind remote: moved forward to the fetched remote head. - Diverged from a force-pushed remote: restarted from the remote head, with the local-only commits saved under `refs/propr/superseded/…`. This was already the behaviour. - Held by a worktree whose folder is gone: the branch is released and reused. A leftover registration for the same worktree path is cleared, but only when nothing in it would be lost. I didn't add a blanket `git worktree prune`: the worker turns pruning off on purpose so that work isn't lost. Unpushed commits. The issue asks for the run to fail when the stale branch has commits that aren't on the remote. I kept the current behaviour instead: the follow-up continues on top of those commits, and nothing is deleted. Existing tests require this, and goal continuation and replacement attempts rely on it. Changing it to fail would be a small edit in `realignDivergedLocalBranch` if you want the stricter rule. Tests. I added `test/followupStaleLocalBranch.integration.test.ts`, which uses real temporary git repos with a bare remote and runs without `SSH_ASKPASS`. It covers branch equal to remote, behind, unpushed commits kept, diverged with a backup ref, a worktree whose folder is gone (both the different-path and same-path cases), a missing tip commit, and the fallback. A missing tip commit is actually refused earlier, at fetch, with an error naming the branch. The new suite and four existing worktree suites all pass (8, 83, 3, 9 and 9 tests). Lint and typecheck for `packages/core` are clean. There's nothing visual to preview.
|
/ultrafix goal=8 max=3 |
|
🔄 Ultrafix loop started (goal: 8/10, max cycles: 3) First action:
|
|
✅ AI Code Review Complete requested by @propr-ultrafix Posted 1 review: |
🔍 AI Code Review — codex:gpt-6-astraOverall EvaluationMerge-ready within the reviewed scope, conditional on the four pending test shards passing. The change adds direct branch-ref validation and a bounded fallback while preserving existing branch-reuse safeguards. ✅ Controlled fallback — Recovery requires both ✅ Preserved recovery safeguards — Both reuse paths call the existing realignment logic, retaining its backup refs, occupied-branch checks, and compare-and-swap updates. ✅ Focused integration coverage — The new tests cover stale branches, missing worktree directories, missing tip objects, and the fallback using real Git repositories. This review used the supplied diff and context; no commands or tests were run. Merge blockersNo merge blockers. SuggestionsThese are optional follow-ups and are not sent to S1: 🟢 Reproduce the worker-specific mismatchThe fallback test deliberately makes the initial lookup miss an existing branch. This verifies recovery, but does not establish why the original lookup failed in production. A reproduction using the worker’s Git version would help confirm the diagnosis. This is optional because the fallback addresses the reported error without depending on that diagnosis. S2: 🟢 Clarify the unpushed-commit contractThe summary describes a discrepancy with the issue’s requested treatment of unpushed commits, while the supplied existing tests explicitly require preserving and continuing from them. Reconcile that documentation with the intended caller behavior. The PR retains the existing contract, so this is not a demonstrated regression. ScoreThe implementation is focused and has relevant regression coverage, with no verified merge blockers. Current checks report no failures; four test shards remain pending. Score: 9/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
AI Implementation Summary
Closes #3687
Branch:
3687/claude-opus-5-5-follow-up-fix-fails-with--20261118-1159-u20Commits: ✅ Changes committed (91ccf4d)
AI Processing Completed
Execution Details:
Summary:
Follow-up runs should no longer fail with "a branch named … already exists" when an earlier run left the PR's local branch behind. One acceptance criterion is handled differently than written (unpushed commits, below), so please check that before merging.
What was going wrong. The worker already had a path for reusing an existing local branch. The four failures on #3644 came through it (the "Cannot create worktree:" prefix only comes from there), so its existence check said "no such branch" while git still saw one. The check worked by listing branches (
git show-ref --heads), butgit worktree add -breads the branch ref itself. When the two disagree, the code fell through to-band failed on every later run. I couldn't reproduce that disagreement in this container (git 2.39; the worker image is Alpine with a newer git), so this is the most likely cause, not a confirmed one.Changes in
packages/core/src/git/worktreeCreation.ts:git worktree add -bdoes. If the branch exists but its tip commit is missing from the clone, the run fails with a message naming the branch and changes nothing.git worktree add -bstill says the branch already exists, the worker reuses the existing branch the same safe way. If the branch can't be read, the run fails with a message naming it. Runs that need a brand-new branch still refuse an existing one.How each stale state is handled now:
refs/propr/superseded/…. This was already the behaviour.git worktree prune: the worker turns pruning off on purpose so that work isn't lost.Unpushed commits. The issue asks for the run to fail when the stale branch has commits that aren't on the remote. I kept the current behaviour instead: the follow-up continues on top of those commits, and nothing is deleted. Existing tests require this, and goal continuation and replacement attempts rely on it. Changing it to fail would be a small edit in
realignDivergedLocalBranchif you want the stricter rule.Tests. I added
test/followupStaleLocalBranch.integration.test.ts, which uses real temporary git repos with a bare remote and runs withoutSSH_ASKPASS. It covers branch equal to remote, behind, unpushed commits kept, diverged with a backup ref, a worktree whose folder is gone (both the different-path and same-path cases), a missing tip commit, and the fallback. A missing tip commit is actually refused earlier, at fetch, with an error naming the branch. The new suite and four existing worktree suites all pass (8, 83, 3, 9 and 9 tests). Lint and typecheck forpackages/coreare clean.There's nothing visual to preview.
Review digest
Risk-tiered paths
packages/core/src/git/worktreeCreation.ts(+35/−19)test/followupStaleLocalBranch.integration.test.ts(added, +195/−0)Diff size: 2 files changed, +230/−19 lines
View task for the run's logs and conversation.
This PR was created automatically by ProPR after processing issue #3687.
💡 Need changes?
Comment on this PR to request refinements — the AI agent monitors comments and will update the implementation based on your feedback. Keep iterating until you're satisfied!