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 22, 12:00 UTC
fix(server): let slow worktree checkouts finish (#23802)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 29, 2026 at 23:04 UTC
fa4e4677c0ecc437aece2dcea39f76ef31414152
2 files changed
+51
-2
apps/server/src/vcs/GitVcsDriverCore.test.ts
+48
@@ -920,6 +920,54 @@ it.effect("retries a fetch that lost a ref update to another Git process", () =>
920
}).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
921
);
922
923
+it.effect("lets a worktree checkout that is still working run past five minutes", () =>
924
+ Effect.gen(function* () {
925
+ const checkoutStarted = yield* Deferred.make<void>();
926
+ const checkoutFinished = yield* Deferred.make<void>();
927
+ const spawner = ChildProcessSpawner.make((command) =>
928
+ Effect.gen(function* () {
929
+ if (!ChildProcess.isStandardCommand(command))
930
+ return yield* Effect.die("expected Git command");
931
+ if (!command.args.includes("worktree")) return makeSuccessfulHandle("");
932
+ yield* Deferred.succeed(checkoutStarted, undefined);
933
+ return ChildProcessSpawner.makeHandle({
934
+ ...makeSuccessfulHandle(""),
935
+ exitCode: Deferred.await(checkoutFinished).pipe(
936
+ Effect.as(ChildProcessSpawner.ExitCode(0)),
937
+ ),
938
+ stderr: Stream.encodeText(
939
+ Stream.concat(
940
+ Stream.make("Updating files: 40% (49052/122629)\n"),
941
+ Stream.fromEffect(
942
+ Deferred.await(checkoutFinished).pipe(
943
+ Effect.as("Updating files: 100% (122629/122629), done.\n"),
944
+ ),
945
+ ),
946
+ ),
947
+ ),
948
+ });
949
+ }),
950
+ );
951
+ const driver = yield* makeGitVcsDriverCore().pipe(
952
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
953
+ );
954
+ const path = yield* Path.Path;
955
+ const cwd = yield* makeTmpDir();
956
+ const worktreePath = path.join(cwd, "worktree");
957
+
958
+ const creation = yield* driver
959
+ .createWorktree({ cwd, refName: "main", newRefName: "t3/slow-checkout", path: worktreePath })
960
+ .pipe(Effect.forkChild);
961
+ yield* Deferred.await(checkoutStarted);
962
+ yield* TestClock.adjust("6 minutes");
963
+ yield* Deferred.succeed(checkoutFinished, undefined);
964
+
965
+ const result = yield* Fiber.join(creation);
966
+ assert.equal(result.worktree.path, worktreePath);
967
+ assert.equal(result.worktree.refName, "t3/slow-checkout");
968
+ }).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
969
+);
970
+
971
describe("rejected git refs", () => {
972
const remoteUrl = "https://user:token-123@git.example.invalid/org/secret-repo.git";
973
const failedPush = `error: failed to push some refs to '${remoteUrl}'`;
apps/server/src/vcs/GitVcsDriverCore.ts
+3
-2
@@ -62,7 +62,6 @@ const branchBaseConfigKey = (branch: string) => `branch.${branch}.t3-merge-base`
62
*/
63
const legacyBranchBaseConfigKey = (branch: string) => `branch.${branch}.gh-merge-base`;
64
const gitProcesses = Semaphore.makeUnsafe(8);
65
-const WORKTREE_ADD_TIMEOUT_MS = 300_000;
65
const WORKTREE_REMOVE_TIMEOUT_MS = Duration.toMillis(Duration.minutes(5));
66
const DEFAULT_MAX_OUTPUT_BYTES = 1_000_000;
67
const OUTPUT_TRUNCATED_MARKER = "\n\n[truncated]";
@@ -3877,7 +3876,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3876
["-c", `checkout.workers=${checkoutWorkers}`, ...args],
3877
{
3878
fallbackErrorDetail: "git worktree add failed",
3880
- timeoutMs: WORKTREE_ADD_TIMEOUT_MS,
3879
+ // Large checkouts and post-checkout hooks can legitimately run for many
3880
+ // minutes; a fixed deadline kills them and leaves an orphaned worktree.
3881
+ timeoutMs: null,
3882
...(onCheckoutProgress
3883
? {
3884
// Git only prints checkout progress when stderr is a tty or the