@devries-cameron20 / t3code Mirror · read-only / commits / f15fbdef2e
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 22:15 UTC

fix(server): branch switch no longer kills a slow git checkout (#23539)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 11, 2026 at 11:58 UTC f15fbdef2e388f60ffc03b0b389c2de415455e9d
2 files changed +79 -8
apps/server/src/vcs/GitVcsDriverCore.test.ts
+48
@@ -2022,6 +2022,54 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
2022 }),
2023 );
2024
2025 + it.effect("lets a slow remote branch checkout finish without blocking config writes", () =>
2026 + Effect.gen(function* () {
2027 + const cwd = yield* makeTmpDir();
2028 + yield* initRepoWithCommit(cwd);
2029 + const remote = yield* makeTmpDir("git-remote-");
2030 + yield* git(remote, ["init", "--bare"]);
2031 + yield* git(cwd, ["remote", "add", "origin", remote]);
2032 + yield* git(cwd, ["push", "origin", "HEAD:refs/heads/feature"]);
2033 + yield* git(cwd, ["fetch", "origin"]);
2034 + const checkoutStarted = yield* Deferred.make<void>();
2035 + const releaseCheckout = yield* Deferred.make<void>();
2036 + const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
2037 + // Holds the real checkout open like a slow LFS smudge filter would.
2038 + const spawner = ChildProcessSpawner.make((command) =>
2039 + Effect.gen(function* () {
2040 + const handle = yield* delegate.spawn(command);
2041 + if (!ChildProcess.isStandardCommand(command) || command.args[0] !== "checkout") {
2042 + return handle;
2043 + }
2044 + yield* Deferred.succeed(checkoutStarted, undefined);
2045 + return ChildProcessSpawner.makeHandle({
2046 + ...handle,
2047 + exitCode: Deferred.await(releaseCheckout).pipe(Effect.andThen(handle.exitCode)),
2048 + });
2049 + }),
2050 + );
2051 + const driver = yield* makeGitVcsDriverCore().pipe(
2052 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
2053 + Effect.provide(layerServerConfig),
2054 + );
2055 +
2056 + const switching = yield* driver
2057 + .switchRef({ cwd, refName: "origin/feature" })
2058 + .pipe(Effect.forkChild({ startImmediately: true }));
2059 + yield* Deferred.await(checkoutStarted);
2060 + yield* TestClock.adjust("60 seconds");
2061 + yield* driver.createRef({ cwd, refName: "other" });
2062 + yield* Deferred.succeed(releaseCheckout, undefined);
2063 +
2064 + const result = yield* Fiber.join(switching);
2065 + assert.equal(result.refName, "feature");
2066 + assert.equal(
2067 + yield* git(cwd, ["rev-parse", "--abbrev-ref", "feature@{upstream}"]),
2068 + "origin/feature",
2069 + );
2070 + }),
2071 + );
2072 +
2073 it.effect.each([
2074 // Git cannot tell a missing revision from a missing file in these.
2075 { label: "an argument that may be a path", args: ["log", "-1", "missing"] },
apps/server/src/vcs/GitVcsDriverCore.ts
+31 -8
@@ -5036,28 +5036,51 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
5036 ).pipe(Effect.map((result) => result.exitCode === 0))
5037 : false;
5038
5039 + const newTrackingBranch =
5040 + !localInputExists && remoteExists && !localTrackingBranch && !localTrackedBranchTargetExists
5041 + ? localTrackedBranchCandidate
5042 + : null;
5043 +
5044 const checkoutArgs = localInputExists
5045 ? ["checkout", input.refName]
5046 : remoteExists && !localTrackingBranch && localTrackedBranchTargetExists
5047 ? ["checkout", input.refName]
5043 - : remoteExists && !localTrackingBranch
5044 - ? ["checkout", "--track", input.refName]
5045 - : remoteExists && localTrackingBranch
5046 - ? ["checkout", localTrackingBranch]
5047 - : ["checkout", input.refName];
5048 + : newTrackingBranch
5049 + ? ["checkout", newTrackingBranch]
5050 + : remoteExists && !localTrackingBranch
5051 + ? ["checkout", "--track", input.refName]
5052 + : remoteExists && localTrackingBranch
5053 + ? ["checkout", localTrackingBranch]
5054 + : ["checkout", input.refName];
5055
5056 yield* refuseOptionLikeRefName("GitVcsDriver.switchRef", input.cwd, checkoutArgs.at(-1));
5057
5058 + // Created before the checkout so the shared-config lock is not held while files are written.
5059 + // Not rolled back on failure: Git may already have switched HEAD to it (post-checkout hooks).
5060 + if (newTrackingBranch) {
5061 + yield* executeGit(
5062 + "GitVcsDriver.switchRef.createTrackingBranch",
5063 + input.cwd,
5064 + ["branch", "--track", "--", newTrackingBranch, input.refName],
5065 + {
5066 + timeoutMs: 10_000,
5067 + fallbackErrorDetail: "git branch create failed",
5068 + writesSharedConfig: true,
5069 + },
5070 + );
5071 + }
5072 +
5073 // A stale ref must not turn into a path checkout that discards local edits.
5074 yield* executeGitWithStableDiagnostics(
5075 "GitVcsDriver.switchRef.checkout",
5076 input.cwd,
5077 [...checkoutArgs, "--"],
5078 {
5057 - timeoutMs: 10_000,
5079 + // Killing a checkout midway (large or LFS repos) leaves a half-updated working tree.
5080 + timeoutMs: null,
5081 fallbackErrorDetail: "git checkout failed",
5059 - // Checking out a remote branch creates a local one that tracks it.
5060 - writesSharedConfig: !localInputExists,
5082 + // Creating a branch writes its upstream; Git also guesses a remote branch for a missing name.
5083 + writesSharedConfig: checkoutArgs[1] === "--track" || (!localInputExists && !remoteExists),
5084 },
5085 );
5086