Skip to content

[Bug]: A new worktree fails with path_already_exists when its folder is left over from an earlier one #35108

Closed

Description

@only21mil

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

Copy this block into a shell in an empty folder on Linux and run it. It clones main at the commit below, starts a dev server from source with an empty data folder, and needs no provider account. Step 5 prints the failure.

# Run in an empty folder on Linux with git and vp (Vite+) installed.
# The bug needs a NAMED branch (--branch feature/foo) that does not exist yet.
# The web composer's "New worktree" never hits it: it always picks a random branch and folder name.
WORK=$PWD
export GIT_AUTHOR_NAME=Sample [email protected] GIT_COMMITTER_NAME=Sample [email protected]
SRC=${T3_SRC:-$WORK/t3code}
if [ ! -d "$SRC" ]; then
  git clone https://github.com/pingdotgg/t3code.git "$SRC"
  git -C "$SRC" checkout b68aedfdb71534bfdfbe55771ef2e686742faa8e
  (cd "$SRC" && vp i)
fi
HOME_DIR=$WORK/t3-home
t3() { (cd "$SRC/apps/server" && vp env exec --node 26.12.1 node src/bin.ts "$@" --base-dir "$HOME_DIR"); }

# 1. A repository with one commit.
git init -b main "$WORK/sample-app"
echo "# sample app" > "$WORK/sample-app/README.md"
git -C "$WORK/sample-app" add README.md
git -C "$WORK/sample-app" commit -m "Initial commit"

# 2. A dev server from source with an empty data folder (it includes the free "Replay (dev)" provider).
(cd "$SRC" && exec vp run dev --home-dir "$HOME_DIR" --no-seed) > "$WORK/server.log" 2>&1 &
until grep -q pairingUrl "$WORK/server.log"; do sleep 1; done

# 3. Add the project, then start a thread in a new worktree on the named branch feature/foo.
t3 project add "$WORK/sample-app"
t3 thread start "$WORK/sample-app" "First run" --worktree main --branch feature/foo --provider devReplay --model showcase --wait

# 4. Print the worktree folder, remove the worktree and its branch, and leave a file of mine in that folder.
dir=$(git -C "$WORK/sample-app" worktree list --porcelain | awk '/^worktree /{p=$2} /^branch refs\/heads\/feature\/foo$/{print p}')
echo "$dir"
git -C "$WORK/sample-app" worktree remove --force "$dir"
git -C "$WORK/sample-app" branch -D feature/foo
mkdir "$dir"
echo "my notes" > "$dir/notes.txt"

# 5. Start a thread for the same branch again, then show the result.
t3 thread start "$WORK/sample-app" "Second run" --worktree main --branch feature/foo --provider devReplay --model showcase --wait
git -C "$WORK/sample-app" worktree list
ls -A "$dir"

Expected behavior

The second thread gets a new worktree for feature/foo in a folder that is free, and my notes.txt is left alone.

Actual behavior

The second thread fails before the agent starts: "Workspace preparation failed during provision worktree: ... git worktree add failed (path_already_exists)". The web app shows the same error on the thread. Nothing tells me which folder is in the way or lets me choose another one. My notes.txt is untouched.

Impact

Minor bug or occasional failure

Version or commit

main, commit b68aedf

Environment

Linux, server from source (vp run dev) on Node 26.12.1, Git 2.53. I saw the same on a macOS 27 server with the web client in Chrome. Provider: Replay (dev). The failure happens while the worktree is prepared, before any provider turn.

Logs or stack traces

dir=$(git -C "$WORK/sample-app" worktree list --porcelain | awk '/^worktree /{p=$2} /^branch refs\/heads\/feature\/foo$/{print p}')
echo "$dir"
/tmp/repro/t3-home/worktrees/sample-app/feature-foo-8799fc65b79a025b
git -C "$WORK/sample-app" worktree remove --force "$dir"
git -C "$WORK/sample-app" branch -D feature/foo
Deleted branch feature/foo (was 46bd545).
mkdir "$dir"
echo "my notes" > "$dir/notes.txt"
# 5. Start a thread for the same branch again, then show the result.
t3 thread start "$WORK/sample-app" "Second run" --worktree main --branch feature/foo --provider devReplay --model showcase --wait
Thread mcp:11a18202-1da4-4675-a0d3-226750318000
Thread mcp:11a18202-1da4-4675-a0d3-226750318000 stopped with status failed: Workspace preparation failed during provision worktree: Git command failed in GitVcsDriver.createWorktree (/tmp/repro/sample-app): git worktree add failed (path_already_exists)
git -C "$WORK/sample-app" worktree list
/tmp/repro/sample-app 46bd545 [main]
ls -A "$dir"
notes.txt

Screenshots, recordings, or supporting files

main b68aedf: the second thread on feature/foo fails with "git worktree add failed (path_already_exists)"
main b68aedf: the second thread on feature/foo fails with "git worktree add failed (path_already_exists)"

Workaround

Move my files out of the leftover folder and delete it; the next launch for the same branch then works.

A fix is in #28944.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions