@devries-cameron20 / t3code-1 / commits / df15bd4f7b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): parallel worktree launches no longer leave all but one branch on its t3/ name (#31662)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

MarcoDotIO committed Nov 14, 2026 at 21:59 UTC df15bd4f7bfcb5c41282e46d9de1092c01043b00
2 files changed +58 -14
apps/server/src/vcs/GitVcsDriverCore.test.ts
+38
@@ -6650,6 +6650,44 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
6650 }),
6651 );
6652
6653 + it.effect("gives parallel renames to one generated name distinct branches", () =>
6654 + Effect.gen(function* () {
6655 + const cwd = yield* makeTmpDir();
6656 + const { initialBranch } = yield* initRepoWithCommit(cwd);
6657 + const path = yield* Path.Path;
6658 + const worktrees = yield* makeTmpDir("git-worktrees-");
6659 + const driver = yield* GitVcsDriver.GitVcsDriver;
6660 + // A multi-model send launches one worktree per model with the same message, so their
6661 + // generated names often match and the renames can land together.
6662 + const temporaryBranches = ["t3/aaaa1111", "t3/bbbb2222", "t3/cccc3333"];
6663 + yield* Effect.forEach(temporaryBranches, (branch) =>
6664 + driver.createWorktree({
6665 + cwd,
6666 + path: path.join(worktrees, branch.replace("/", "-")),
6667 + refName: initialBranch,
6668 + newRefName: branch,
6669 + }),
6670 + );
6671 +
6672 + const renamed = yield* Effect.forEach(
6673 + temporaryBranches,
6674 + (branch) =>
6675 + driver.renameBranch({
6676 + cwd: path.join(worktrees, branch.replace("/", "-")),
6677 + oldBranch: branch,
6678 + newBranch: "feat/add-search",
6679 + }),
6680 + { concurrency: "unbounded" },
6681 + );
6682 +
6683 + assert.deepStrictEqual(renamed.map((result) => result.branch).toSorted(), [
6684 + "feat/add-search",
6685 + "feat/add-search-1",
6686 + "feat/add-search-2",
6687 + ]);
6688 + }),
6689 + );
6690 +
6691 it.effect.each(["release/v2", "refs/heads/release/v2", "deadbeef"])(
6692 "records the branch name when creating a worktree from %s",
6693 (baseRef) =>
apps/server/src/vcs/GitVcsDriverCore.ts
+20 -14
@@ -5782,22 +5782,28 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
5782 if (input.oldBranch === input.newBranch) {
5783 return { branch: input.newBranch };
5784 }
5785 - const targetBranch = input.exactName
5786 - ? input.newBranch
5787 - : yield* resolveAvailableBranchName(input.cwd, input.newBranch);
5788 -
5789 - yield* executeGit(
5790 - "GitVcsDriver.renameBranch",
5785 + // Parallel launches often generate the same name; picking it under the lock that serializes
5786 + // the renames keeps a second launch from choosing a name the first is about to take.
5787 + return yield* withSharedConfigLock(
5788 input.cwd,
5792 - ["branch", "-m", "--", input.oldBranch, targetBranch],
5793 - {
5794 - timeoutMs: 10_000,
5795 - fallbackErrorDetail: "git branch rename failed",
5796 - writesSharedConfig: true,
5797 - },
5798 - );
5789 + Effect.gen(function* () {
5790 + const targetBranch = input.exactName
5791 + ? input.newBranch
5792 + : yield* resolveAvailableBranchName(input.cwd, input.newBranch);
5793
5800 - return { branch: targetBranch };
5794 + yield* executeGit(
5795 + "GitVcsDriver.renameBranch",
5796 + input.cwd,
5797 + ["branch", "-m", "--", input.oldBranch, targetBranch],
5798 + {
5799 + timeoutMs: 10_000,
5800 + fallbackErrorDetail: "git branch rename failed",
5801 + },
5802 + );
5803 +
5804 + return { branch: targetBranch };
5805 + }),
5806 + );
5807 });
5808
5809 const switchRef: GitVcsDriver.GitVcsDriver["Service"]["switchRef"] = Effect.fn("switchRef")(