Skip to content

fix(worktrees): concurrent creates on one name pick different paths - #35380

Merged
Jinwoo-H merged 3 commits into
mainfrom
jinwoo/worktree-create-path-claim
Oct 28, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
jinwoo/worktree-create-path-claim

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​180 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​179
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​65 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59

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 -2 suffix, 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

  • Automated tests added/updated
  • Runtime create path (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 gets app-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.
  • Desktop create path (worktrees-local-create-path-claim.test.ts): the same two cases through the desktop create handler.
  • With the claim disabled, all four concurrency cases fail with both creates picking the same path.
  • Ran 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Concurrent worktree creates now reserve their chosen path. Another create sees that reservation and tries the next name.

  • Concurrent worktree creates choose different paths for the same 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.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Choose candidate name] --> B{Path exists or removal pending?}
  B -->|Yes| A
  B -->|No| C{Claim path}
  C -->|Already claimed| A
  C -->|Claimed| D[Create worktree]
  D --> E[Create succeeds or fails]
  E --> F[Release claim]
Loading

Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

@Jinwoo-H
Jinwoo-H changed the base branch from jinwoo/worker-start-default-name to main October 28, 2026 21:51
…e-path-claim

# Conflicts:
#	src/main/runtime/runtime-local-worktree-create.test.ts
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

Local worktree creation now claims a candidate path before starting the Git operation and releases the claim when the operation settles, including after failure. Candidate selection requires that the path does not exist, has no pending-removal conflict, and can be claimed. Tests cover concurrent requests for fixed and generated names, reuse after completion, and reuse after a failed create.

Priority: Normal

Merge Risk: Moderate · up to 22396

The claim-release regression test can time out rather than verify recovery after a failed create. Fix the test setup before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preventing concurrent worktree creates from selecting the same path.
Description check Passed The description is complete and explains the problem, user-visible behavior, implementation, rationale, testing, scope, and compatibility considerations. It identifies #35363 as the follow-up issue, a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and explains the problem, user-visible behavior, implementation, rationale, testing, scope, and compatibility considerations. It identifies #35363 as the follow-up issue, although the Linked Issue section says N/A instead of linking it directly.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 6 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
Commits

Reviewing files that changed from the base of the PR and between 93ff483 and 223969f.

Files selected for processing: 6
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktrees-local-create-path-claim.test.ts
  • src/main/runtime/runtime-local-worktree-create-candidate.ts
  • src/main/runtime/runtime-local-worktree-create.test.ts
  • src/main/runtime/runtime-local-worktree-create.ts
  • src/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'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Major · Stability & Availability · Quick win

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)

@Jinwoo-H
Jinwoo-H merged commit 5d3af83 into main Oct 28, 2026
41 checks passed
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.

1 participant