Repository navigation
fix(worktrees): concurrent creates on one name pick different paths - #35380
Conversation
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryConcurrent worktree creates now reserve their chosen path. Another create sees that reservation and tries the next name.
The previous and current commits have different merge bases with the target commit, so this review covered the full PR diff. No new actionable issues were found. Tests were inspected, not run.
|
…e-path-claim # Conflicts: # src/main/runtime/runtime-local-worktree-create.test.ts
Walkthrough
Priority: Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
a82ec221-4a9f-49a8-82b8-d61abb8f2bce
Files selected for processing: 6-
src/main/ipc/worktree-remote.tssrc/main/ipc/worktrees-local-create-path-claim.test.tssrc/main/runtime/runtime-local-worktree-create-candidate.tssrc/main/runtime/runtime-local-worktree-create.test.tssrc/main/runtime/runtime-local-worktree-create.tssrc/main/worktree-create-in-flight.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
-
| }) | ||
|
|
||
| it('releases the claim when the create fails', async () => { | ||
| mocks.add.mockRejectedValueOnce(new Error('add failed')) |
There was a problem hiding this comment.
Remove the two-call gate from the failure test.
mockRejectedValueOnce bypasses the gated implementation for the first create. The second create enters that implementation alone and waits for a second call that never occurs. The failure test times out instead of verifying claim release. Give this test its own mock setup without the two-call gate. (raw.githubusercontent.com)
ELI5
If two new workspaces are created at the same moment with the same name, both used to think the folder was free, and one of them failed. Now the first one reserves the folder while it is being created, so the second one picks the next name instead.
What Changed
Before: a create checks that its workspace folder does not exist yet, then spends a while in Git making it. Two creates on the same name that overlapped in that window both passed the check. The second then failed in Git because the folder or branch was already taken. This can happen with two quick creates in the app, a phone and the desktop creating at once, or a coordinating agent starting several workers that each pick a generated name (#35363).
After: the check that a folder is free now also claims that path for the create, in the same synchronous step. If another create on the same host already holds the claim, the path counts as taken. The existing fallback loop then moves on: a generated name goes to its next tier and a typed name gets a
-2suffix, exactly as if the folder already existed. The claim is released when the create settles, whether it succeeded or failed. By then the folder is either on disk, where the existing check sees it, or gone.The claim lives in the main process that runs Git for the create: the desktop for local projects, and the remote Orca server for SSH and paired-server projects. The desktop's own create path and the runtime create path share the claim table, so a desktop create and a runtime create on the same path also see each other's claims.
Why
The fix sits where the path is chosen, which every client already goes through (desktop composer, mobile, CLI, connectors, orchestration workers). A client-side retry would be needed in every caller and would still fail first. A lock held for the whole create would serialize unrelated creates. The claim is a small addition to the module that already tracks in-flight creates for the sidebar listing.
Linked Issue
N/A (maintainer change; follow-up to #35363)
Visual Proof
N/A: no UI change. The race is covered by tests.
Testing
runtime-local-worktree-create.test.ts): two creates on one name are held inside Git's add at the same time. For a typed name the second getsapp-2, and for a generated name the second gets a next-tier creature name. A third create afterward gets the original name back, which shows the claims were released. A failed create also releases its claim.worktrees-local-create-path-claim.test.ts): the same two cases through the desktop create handler.pnpm tc,typecheck:ci, oxlint (type-aware + anti-slop),check:code-quality:changed, the pr.yml static check scripts, and the existing worktree create suites locally (macOS).Review
Agent skill upstream boundary
Notes
Only the folder path is claimed. Branch names follow the folder name's suffix, so a moved-on path also moves the branch. Two creates that ask for the same exact branch override still rely on Git's own branch check, as before.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)