@devries-cameron20 / t3code Mirror · read-only / commits / 81955304c1
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 22, 08:15 UTC

fix(server): let slow worktree submodule checkouts finish (#28482)

Dmitry Farafonov committed Nov 1, 2026 at 22:53 UTC 81955304c15323313b6edd69e89670f6a250b2eb
2 files changed +157 -21
apps/server/src/vcs/GitVcsDriverCore.test.ts
+146 -14
@@ -1381,6 +1381,61 @@ it.effect("lets a worktree checkout that is still working run past five minutes"
1381 }).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
1382 );
1383
1384 +it.effect("cancels a slow submodule checkout without reporting best-effort success", () =>
1385 + Effect.gen(function* () {
1386 + const updateStarted = yield* Deferred.make<void>();
1387 + const updateStopped = yield* Deferred.make<void>();
1388 + const finished = yield* Ref.make<ReadonlyArray<{ ok: boolean; detail: string | null }>>([]);
1389 + const claimed = yield* Ref.make<string | null>(null);
1390 + const spawner = ChildProcessSpawner.make((command) => {
1391 + if (
1392 + ChildProcess.isStandardCommand(command) &&
1393 + command.args[0] === "submodule" &&
1394 + command.args[1] === "update"
1395 + ) {
1396 + return Effect.acquireRelease(
1397 + Effect.succeed(
1398 + ChildProcessSpawner.makeHandle({
1399 + ...makeSuccessfulHandle(""),
1400 + exitCode: Deferred.succeed(updateStarted, undefined).pipe(
1401 + Effect.andThen(Effect.never),
1402 + ),
1403 + }),
1404 + ),
1405 + () => Deferred.succeed(updateStopped, undefined),
1406 + );
1407 + }
1408 + return Effect.succeed(makeSuccessfulHandle(""));
1409 + });
1410 + const driver = yield* makeGitVcsDriverCore().pipe(
1411 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
1412 + );
1413 + const cwd = yield* makeTmpDir();
1414 + const path = yield* Path.Path;
1415 + const worktreePath = path.join(cwd, "worktree");
1416 + yield* writeTextFile(worktreePath, ".gitmodules", "");
1417 + const creation = yield* driver
1418 + .createWorktree(
1419 + { cwd, refName: "main", newRefName: "bugfix/cancel-submodules", path: worktreePath },
1420 + {
1421 + progress: {
1422 + onWorktreeClaimed: (value) => Ref.set(claimed, value),
1423 + onSubmodulesFinished: (result) => Ref.update(finished, (items) => [...items, result]),
1424 + },
1425 + },
1426 + )
1427 + .pipe(Effect.forkChild);
1428 + yield* Deferred.await(updateStarted);
1429 + yield* TestClock.adjust("6 minutes");
1430 + yield* Fiber.interrupt(creation);
1431 + const exit = yield* Fiber.await(creation);
1432 + assert.isTrue(Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause));
1433 + assert.isTrue(yield* Deferred.isDone(updateStopped));
1434 + assert.equal(yield* Ref.get(claimed), worktreePath);
1435 + assert.isEmpty(yield* Ref.get(finished));
1436 + }).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
1437 +);
1438 +
1439 describe("rejected git refs", () => {
1440 const remoteUrl = "https://user:token-123@git.example.invalid/org/secret-repo.git";
1441 const failedPush = `error: failed to push some refs to '${remoteUrl}'`;
@@ -4145,7 +4200,12 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4200 }),
4201 );
4202
4148 - it.effect("checks out submodules in a new worktree", () =>
4203 + it.effect.each([
4204 + ["recursive", false],
4205 + ["recursive", true],
4206 + ["top-level", false],
4207 + ["top-level", true],
4208 + ] as const)("finishes a slow submodule checkout (%s, progress: %s)", ([submodules, progress]) =>
4209 Effect.gen(function* () {
4210 const fileSystem = yield* FileSystem.FileSystem;
4211 const pathService = yield* Path.Path;
@@ -4165,6 +4225,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4225
4226 const submoduleRepo = yield* makeTmpDir("git-submodule-");
4227 yield* initRepoWithCommit(submoduleRepo);
4228 + yield* writeTextFile(submoduleRepo, ".gitattributes", "* text eol=lf\n");
4229 yield* writeTextFile(submoduleRepo, "SHARED.md", "# shared\n");
4230 yield* git(submoduleRepo, ["add", "."]);
4231 yield* git(submoduleRepo, ["commit", "-m", "shared"]);
@@ -4173,23 +4234,80 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4234 const { initialBranch } = yield* initRepoWithCommit(cwd);
4235 yield* git(cwd, ["submodule", "add", submoduleRepo, "shared"]);
4236 yield* git(cwd, ["commit", "-m", "add submodule"]);
4237 + const recordedHead = yield* git(submoduleRepo, ["rev-parse", "HEAD"]);
4238 + yield* writeTextFile(submoduleRepo, "SHARED.md", "# newer remote default\n");
4239 + yield* git(submoduleRepo, ["commit", "-am", "advance remote default"]);
4240 +
4241 + const updateStarted = yield* Deferred.make<void>();
4242 + const releaseUpdate = yield* Deferred.make<void>();
4243 + const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
4244 + const spawner = ChildProcessSpawner.make((command) =>
4245 + Effect.gen(function* () {
4246 + if (
4247 + ChildProcess.isStandardCommand(command) &&
4248 + command.args[0] === "submodule" &&
4249 + command.args[1] === "update"
4250 + ) {
4251 + yield* Deferred.succeed(updateStarted, undefined);
4252 + yield* Deferred.await(releaseUpdate);
4253 + }
4254 + return yield* delegate.spawn(command);
4255 + }),
4256 + );
4257 + const driver = yield* makeGitVcsDriverCore().pipe(
4258 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
4259 + Effect.provide(layerServerConfig),
4260 + );
4261 + const finished = yield* Ref.make<ReadonlyArray<{ ok: boolean; detail: string | null }>>([]);
4262 + const lines = yield* Ref.make<ReadonlyArray<string>>([]);
4263
4264 const worktreePath = pathService.join(
4265 yield* makeTmpDir("git-worktrees-"),
4266 "submodule-worktree",
4267 );
4181 - const driver = yield* GitVcsDriver.GitVcsDriver;
4182 - yield* driver.createWorktree({
4183 - cwd,
4184 - path: worktreePath,
4185 - refName: initialBranch,
4186 - newRefName: "feature/submodules",
4187 - });
4268 + const creation = yield* driver
4269 + .createWorktree(
4270 + {
4271 + cwd,
4272 + path: worktreePath,
4273 + refName: initialBranch,
4274 + newRefName: "feature/submodules",
4275 + },
4276 + {
4277 + submodules,
4278 + progress: {
4279 + onSubmodulesFinished: (result) =>
4280 + Ref.update(finished, (items) => [...items, result]),
4281 + ...(progress
4282 + ? {
4283 + onSubmoduleLine: (line: string) =>
4284 + Ref.update(lines, (items) => [...items, line]),
4285 + }
4286 + : {}),
4287 + },
4288 + },
4289 + )
4290 + .pipe(Effect.forkChild);
4291 + yield* Deferred.await(updateStarted);
4292 + yield* TestClock.adjust("6 minutes");
4293 + yield* Deferred.succeed(releaseUpdate, undefined);
4294 + yield* Fiber.join(creation);
4295
4296 + assert.deepEqual(yield* Ref.get(finished), [{ ok: true, detail: null }]);
4297 assert.equal(
4298 yield* fileSystem.exists(pathService.join(worktreePath, "shared", "SHARED.md")),
4299 true,
4300 );
4301 + assert.equal(
4302 + yield* git(pathService.join(worktreePath, "shared"), ["rev-parse", "HEAD"]),
4303 + recordedHead,
4304 + );
4305 + assert.equal(yield* git(worktreePath, ["status", "--porcelain"]), "");
4306 + assert.equal(
4307 + yield* git(pathService.join(worktreePath, "shared"), ["status", "--porcelain"]),
4308 + "",
4309 + );
4310 + if (progress) assert.isNotEmpty(yield* Ref.get(lines));
4311 }),
4312 );
4313
@@ -4206,6 +4324,8 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4324 '[submodule "missing"]\n\tpath = missing\n\turl = /nonexistent/repo.git\n',
4325 );
4326 yield* git(cwd, ["add", "."]);
4327 + const gitlink = yield* git(cwd, ["rev-parse", "HEAD"]);
4328 + yield* git(cwd, ["update-index", "--add", "--cacheinfo", `160000,${gitlink},missing`]);
4329 yield* git(cwd, ["commit", "-m", "add unreachable submodule"]);
4330
4331 const worktreePath = pathService.join(
@@ -4213,15 +4333,27 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4333 "broken-submodule-worktree",
4334 );
4335 const driver = yield* GitVcsDriver.GitVcsDriver;
4216 - const created = yield* driver.createWorktree({
4217 - cwd,
4218 - path: worktreePath,
4219 - refName: initialBranch,
4220 - newRefName: "feature/broken-submodules",
4221 - });
4336 + const finished = yield* Ref.make<ReadonlyArray<{ ok: boolean; detail: string | null }>>([]);
4337 + const created = yield* driver.createWorktree(
4338 + {
4339 + cwd,
4340 + path: worktreePath,
4341 + refName: initialBranch,
4342 + newRefName: "feature/broken-submodules",
4343 + },
4344 + {
4345 + progress: {
4346 + onSubmodulesFinished: (result) => Ref.update(finished, (items) => [...items, result]),
4347 + },
4348 + },
4349 + );
4350
4351 assert.equal(created.worktree.path, worktreePath);
4352 assert.equal(yield* fileSystem.exists(worktreePath), true);
4353 + const results = yield* Ref.get(finished);
4354 + assert.lengthOf(results, 1);
4355 + assert.isFalse(results[0]!.ok);
4356 + assert.include(results[0]!.detail, "GitVcsDriver.createWorktree.updateSubmodules");
4357 }),
4358 );
4359
apps/server/src/vcs/GitVcsDriverCore.ts
+11 -7
@@ -4239,17 +4239,21 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
4239 submoduleMode.value === "recursive"
4240 ? ["submodule", "update", "--init", "--recursive"]
4241 : ["submodule", "update", "--init"],
4242 - onSubmoduleLine
4243 - ? {
4244 - env: { LC_ALL: "C" },
4245 - progress: { onStdoutLine: onSubmoduleLine, onStderrLine: onSubmoduleLine },
4246 - }
4247 - : {},
4242 + {
4243 + // Cloning scales with remote size; let it finish or be cancelled, like worktree add.
4244 + timeoutMs: null,
4245 + ...(onSubmoduleLine
4246 + ? {
4247 + env: { LC_ALL: "C" },
4248 + progress: { onStdoutLine: onSubmoduleLine, onStderrLine: onSubmoduleLine },
4249 + }
4250 + : {}),
4251 + },
4252 ),
4253 ),
4254 Effect.matchEffect({
4255 onFailure: (cause) =>
4252 - Effect.logWarning("worktree submodule checkout failed; submodule paths are empty", {
4256 + Effect.logWarning("worktree submodule checkout failed; submodules may be incomplete", {
4257 worktreePath,
4258 cause,
4259 }).pipe(