The best way to control Claude Code, Codex and more from any computer or phone
fix(server): allow slow worktree base fetches to finish (#24604)
Julius Marminge committed
Nov 14, 2026 at 00:30 UTC
8b30961465bd7f8db261de7a719d0e3e8c90e87b
2 files changed
+51
apps/server/src/vcs/GitVcsDriverCore.test.ts
+47
@@ -1879,6 +1879,53 @@ it.effect("cancels a slow submodule checkout without reporting best-effort succe
1879
),
1880
);
1881
1882
+// regression: #18537 the fetch before creating a worktree outgrew the 30s default
1883
+it.effect.each(["healthy", "hung"] as const)("bounds a %s remote fetch at five minutes", (fetch) =>
1884
+ Effect.gen(function* () {
1885
+ const started = yield* Deferred.make<void>();
1886
+ const finished = yield* Deferred.make<void>();
1887
+ const spawner = ChildProcessSpawner.make((command) =>
1888
+ Effect.succeed(
1889
+ ChildProcess.isStandardCommand(command) && command.args[0] === "fetch"
1890
+ ? ChildProcessSpawner.makeHandle({
1891
+ ...makeSuccessfulHandle(""),
1892
+ exitCode: Deferred.succeed(started, undefined).pipe(
1893
+ Effect.andThen(Deferred.await(finished)),
1894
+ Effect.as(ChildProcessSpawner.ExitCode(0)),
1895
+ ),
1896
+ })
1897
+ : makeNonRepositoryHandle(),
1898
+ ),
1899
+ );
1900
+ const driver = yield* makeGitVcsDriverCore().pipe(
1901
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
1902
+ );
1903
+ const fetching = yield* driver
1904
+ .fetchRemote({ cwd: yield* makeTmpDir(), remoteName: "origin" })
1905
+ .pipe(Effect.result, Effect.forkChild({ startImmediately: true }));
1906
+ yield* Deferred.await(started);
1907
+ yield* TestClock.adjust("31 seconds");
1908
+ if (fetch === "healthy") yield* Deferred.succeed(finished, undefined);
1909
+ else {
1910
+ yield* TestClock.adjust("268 seconds");
1911
+ assert.isUndefined(fetching.pollUnsafe());
1912
+ yield* TestClock.adjust("1 second");
1913
+ }
1914
+
1915
+ const result = yield* Fiber.join(fetching);
1916
+ assert.equal(
1917
+ Result.isFailure(result) ? result.failure.detail : "fetched",
1918
+ fetch === "healthy" ? "fetched" : "Git command timed out.",
1919
+ );
1920
+ }).pipe(
1921
+ Effect.provide(
1922
+ layerServerConfig.pipe(
1923
+ Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1924
+ ),
1925
+ ),
1926
+ ),
1927
+);
1928
+
1929
describe("rejected git refs", () => {
1930
const remoteUrl = "https://user:token-123@git.example.invalid/org/secret-repo.git";
1931
const failedPush = `error: failed to push some refs to '${remoteUrl}'`;
apps/server/src/vcs/GitVcsDriverCore.ts
+4
@@ -69,6 +69,9 @@ const branchBaseConfigKey = (branch: string) => `branch.${branch}.t3-merge-base`
69
const legacyBranchBaseConfigKey = (branch: string) => `branch.${branch}.gh-merge-base`;
70
const gitProcesses = Semaphore.makeUnsafe(8);
71
const backgroundGitProcesses = Semaphore.makeUnsafe(2);
72
+// The fetch before `git worktree add` downloads everything the remote gained since
73
+// the last fetch; on busy repositories that alone outlasts the 30s default.
74
+const FETCH_REMOTE_TIMEOUT_MS = Duration.toMillis(Duration.minutes(5));
75
const WORKTREE_INDEX_REFRESH_TIMEOUT_MS = Duration.toMillis(Duration.minutes(5));
76
const WORKTREE_REMOVE_TIMEOUT_MS = Duration.toMillis(Duration.minutes(5));
77
const DEFAULT_MAX_OUTPUT_BYTES = 1_000_000;
@@ -4940,6 +4943,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
4943
const options = {
4944
env: STATUS_UPSTREAM_REFRESH_ENV,
4945
fallbackErrorDetail: `git fetch ${input.remoteName} failed`,
4946
+ timeoutMs: FETCH_REMOTE_TIMEOUT_MS,
4947
};
4948
// Another fetch in the same repository, such as the background status
4949
// poll, can win the race for a remote-tracking ref. The loser fails, but