@devries-cameron20 / t3code-1 / commits / 18aeb0fb91
Fork 0

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

fix(server): new worktrees show submodule downloads instead of a stuck checkout (#33687)

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

Godfrey Hendrix committed Nov 12, 2026 at 17:51 UTC 18aeb0fb91ca55b79c8919f1ecc5a3166772ad57
7 files changed +157 -10
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+77
@@ -2460,6 +2460,79 @@ it.effect("tells the thread when its worktree branch could not be renamed", () =
2460 }),
2461 );
2462
2463 +it.effect("reports submodule downloads as their own setup step", () =>
2464 + Effect.gen(function* () {
2465 + const progressReady =
2466 + yield* Deferred.make<
2467 + NonNullable<
2468 + NonNullable<
2469 + Parameters<GitWorkflow.GitWorkflowService["Service"]["createWorktree"]>[1]
2470 + >["progress"]
2471 + >
2472 + >();
2473 + const release = yield* Deferred.make<void>();
2474 + const harness = makeHarness({
2475 + createWorktree: (input, options) =>
2476 + Deferred.succeed(progressReady, options?.progress ?? {}).pipe(
2477 + Effect.andThen(Deferred.await(release)),
2478 + Effect.as({
2479 + worktree: {
2480 + path: "/repo-worktrees/feature",
2481 + refName: input.newRefName,
2482 + headSha: "abc",
2483 + },
2484 + } as never),
2485 + ),
2486 + });
2487 + yield* Effect.gen(function* () {
2488 + const launches = yield* ThreadLaunch.ThreadLaunchService;
2489 + const tracker = yield* WorktreeSetupTracker.WorktreeSetupTracker;
2490 + const launched = yield* launches.launch(
2491 + launchInput({
2492 + command: "launch:submodule-progress",
2493 + thread: "thread:submodule-progress",
2494 + message: "Start",
2495 + workspace: { type: "worktree", baseRef: "main" },
2496 + }),
2497 + );
2498 + const stage = (id: string) =>
2499 + tracker
2500 + .get(launched.threadId)
2501 + .pipe(Effect.map((snapshot) => snapshot?.stages.find((entry) => entry.id === id)));
2502 + const progress = yield* Deferred.await(progressReady);
2503 + const line = (text: string) => progress.onSubmoduleLine?.(text) ?? Effect.void;
2504 +
2505 + yield* progress.onSubmodulesStarted?.() ?? Effect.void;
2506 + yield* line("Receiving objects: 20% (2/10), 4.00 MiB | 1.50 MiB/s");
2507 + yield* line("Receiving objects: 30% (3/10), 6.00 MiB | 1.50 MiB/s");
2508 + assert.equal((yield* stage("checkout"))?.status, "done");
2509 + assert.deepInclude(yield* stage("submodules"), {
2510 + status: "running",
2511 + detail: "Receiving objects: 20% (2/10), 4.00 MiB | 1.50 MiB/s",
2512 + });
2513 +
2514 + yield* TestClock.adjust("1 second");
2515 + yield* line("Receiving objects: 60% (6/10), 12.00 MiB | 1.50 MiB/s");
2516 + assert.equal(
2517 + (yield* stage("submodules"))?.detail,
2518 + "Receiving objects: 60% (6/10), 12.00 MiB | 1.50 MiB/s",
2519 + );
2520 +
2521 + yield* line("Submodule path 'vendor/o'hare': checked out 'abc'");
2522 + yield* progress.onSubmodulesFinished?.({ ok: true, detail: null }) ?? Effect.void;
2523 + yield* Deferred.succeed(release, undefined);
2524 + yield* tracker.stream(launched.threadId).pipe(
2525 + Stream.filter((snapshot) => snapshot?.phase !== "running"),
2526 + Stream.runHead,
2527 + );
2528 + assert.deepInclude(yield* stage("submodules"), {
2529 + status: "done",
2530 + detail: "vendor/o'hare",
2531 + });
2532 + }).pipe(Effect.provide(harness.layer));
2533 + }),
2534 +);
2535 +
2536 it.effect.each([0, 1])("releases an async setup before its completion with exit %s", (exitCode) =>
2537 Effect.gen(function* () {
2538 const completion = yield* Deferred.make<{ exitCode: number | null; durationMs: number }>();
@@ -2509,6 +2582,10 @@ it.effect.each([0, 1])("releases an async setup before its completion with exit
2582 settled?.stages.find((stage) => stage.id === "setup-script")?.status,
2583 exitCode === 0 ? "done" : "failed",
2584 );
2585 + assert.deepInclude(
2586 + settled?.stages.find((stage) => stage.id === "submodules"),
2587 + { status: "skipped", detail: "none" },
2588 + );
2589 assert.equal(
2590 (yield* threads.getThreadProjection(launched.threadId)).runs[0]?.status,
2591 "starting",
apps/server/src/orchestration-v2/ThreadLaunchService.ts
+50 -2
@@ -22,6 +22,7 @@ import {
22 ThreadId,
23 } from "@t3tools/contracts";
24 import * as Cause from "effect/Cause";
25 +import * as Clock from "effect/Clock";
26 import * as Context from "effect/Context";
27 import * as DateTime from "effect/DateTime";
28 import * as Effect from "effect/Effect";
@@ -41,6 +42,7 @@ import {
42 } from "@t3tools/shared/git";
43
44 import * as GitWorkflow from "../git/GitWorkflowService.ts";
45 +import { parseGitCloneProgressLine } from "../project/gitCloneProgress.ts";
46 import * as ProjectService from "../project/ProjectService.ts";
47 import * as ProjectSetupScriptRunner from "../project/ProjectSetupScriptRunner.ts";
48 import * as ManagedProjectFolders from "../project/ManagedProjectFolders.ts";
@@ -437,7 +439,7 @@ const make = Effect.gen(function* () {
439 threadId,
440 branch: input.workspaceStrategy.branch ?? null,
441 baseRef: input.workspaceStrategy.baseRef,
440 - stages: ["fetch", "checkout", "setup-script", "agent"],
442 + stages: ["fetch", "checkout", "submodules", "setup-script", "agent"],
443 fiber: yield* Effect.fiber,
444 });
445 } else if (reused !== undefined) {
@@ -552,6 +554,7 @@ const make = Effect.gen(function* () {
554 branch = flattenTemporaryWorktreeBranchName(branch);
555 }
556 yield* setupTracker.stageStatus(threadId, "checkout", "running");
557 + let submoduleProgressReportedAt = Number.NEGATIVE_INFINITY;
558 const worktree = yield* git
559 .createWorktree(
560 {
@@ -570,6 +573,42 @@ const make = Effect.gen(function* () {
573 }),
574 onCheckoutProgress: (progress) =>
575 setupTracker.stage(threadId, "checkout", { percent: progress.percent }),
576 + onSubmodulesStarted: () =>
577 + setupTracker
578 + .stageStatus(threadId, "checkout", "done")
579 + .pipe(
580 + Effect.andThen(setupTracker.stageStatus(threadId, "submodules", "running")),
581 + ),
582 + onSubmodulesDisabled: ({ source }) =>
583 + setupTracker.stageStatus(
584 + threadId,
585 + "submodules",
586 + "skipped",
587 + `disabled in ${source}`,
588 + ),
589 + onSubmoduleLine: (line) => {
590 + // Paths may contain quotes; git closes the path with "': ".
591 + const submodulePath = /^\s*Submodule path '(.+)': /.exec(line)?.[1];
592 + if (submodulePath !== undefined) {
593 + return setupTracker.stage(threadId, "submodules", { detail: submodulePath });
594 + }
595 + if (parseGitCloneProgressLine(line) === null) return Effect.void;
596 + // Git redraws on every percent; hold the websocket to one update a second.
597 + return Effect.flatMap(Clock.currentTimeMillis, (now) => {
598 + if (now - submoduleProgressReportedAt < 1000) return Effect.void;
599 + submoduleProgressReportedAt = now;
600 + return setupTracker.stage(threadId, "submodules", {
601 + detail: line.trim().replace(/\s+/g, " "),
602 + });
603 + });
604 + },
605 + onSubmodulesFinished: ({ ok, detail }) =>
606 + setupTracker.stageStatus(
607 + threadId,
608 + "submodules",
609 + ok ? "done" : "warning",
610 + ok ? undefined : (detail ?? "submodule checkout failed"),
611 + ),
612 },
613 },
614 )
@@ -578,7 +617,16 @@ const make = Effect.gen(function* () {
617 branch = worktree.worktree.refName;
618 createdWorktreePath = worktreePath;
619 createdBranch = branch;
581 - yield* setupTracker.update(threadId, (snapshot) => ({ ...snapshot, worktreePath, branch }));
620 + yield* setupTracker.update(threadId, (snapshot) => ({
621 + ...snapshot,
622 + worktreePath,
623 + branch,
624 + stages: snapshot.stages.map((stage) =>
625 + stage.id === "submodules" && stage.status === "pending"
626 + ? { ...stage, status: "skipped", detail: "none" }
627 + : stage,
628 + ),
629 + }));
630 yield* setupTracker.stageStatus(threadId, "checkout", "done");
631 }
632
apps/server/src/project/ProjectCloneTracker.test.ts
+3
@@ -343,6 +343,9 @@ describe("parseGitCloneProgressLine", () => {
343 expect(
344 parseGitCloneProgressLine("Receiving objects: 45% (4500/10000), 12.30 MiB | 5.00 MiB/s"),
345 ).toEqual({ stage: "receiving", percent: 45, detail: "12.30 MiB | 5.00 MiB/s" });
346 + expect(
347 + parseGitCloneProgressLine("Receiving objects: 100% (5/5), 40.00 MiB | 1.40 MiB/s, done."),
348 + ).toEqual({ stage: "receiving", percent: 100, detail: "40.00 MiB | 1.40 MiB/s" });
349 expect(parseGitCloneProgressLine("Resolving deltas: 100% (700/700), done.")).toEqual({
350 stage: "resolving",
351 percent: 100,
apps/server/src/project/gitCloneProgress.ts
+8 -2
@@ -16,7 +16,10 @@ const STAGE_PREFIXES: ReadonlyArray<readonly [RegExp, ProjectCloneStage]> = [
16 [/^Checking out files/, "checkout"],
17 ];
18
19 -const PERCENT = /:\s+(\d+)%\s+\((\d+)\/(\d+)\)(?:,\s*(.*?))?\s*(?:,\s*done\.)?\s*$/;
19 +// Linear on hostile remote output: the tail is trimmed in code (optional `\s*`/`.*?` groups backtrack
20 +// cubically), and `s` lets it span U+2028 so a failed `$` cannot retry at every later counter.
21 +const PERCENT = /:\s+(\d+)%\s+\((\d+)\/(\d+)\)(.*)$/s;
22 +const DONE_SUFFIX = ", done.";
23
24 /** Pass each bare-CR progress redraw as a separate line. */
25 export function parseGitCloneProgressLine(line: string): GitCloneProgressLine | null {
@@ -26,8 +29,11 @@ export function parseGitCloneProgressLine(line: string): GitCloneProgressLine |
29 const stage = stageEntry[1];
30 const match = PERCENT.exec(trimmed);
31 if (!match) return { stage, percent: null, detail: null };
32 + let tail = (match[4] ?? "").trimEnd();
33 + if (tail.endsWith(DONE_SUFFIX)) tail = tail.slice(0, -DONE_SUFFIX.length).trimEnd();
34 + if (tail.length > 0 && !tail.startsWith(",")) return { stage, percent: null, detail: null };
35 const percent = Number(match[1]);
30 - const rawDetail = match[4]?.trim() ?? "";
36 + const rawDetail = tail.slice(1).trim();
37 const detail = rawDetail.length > 0 && rawDetail !== "done." ? rawDetail : null;
38 return {
39 stage,
apps/server/src/vcs/GitVcsDriverCore.test.ts
+7 -2
@@ -5527,7 +5527,8 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
5527
5528 const cwd = yield* makeTmpDir();
5529 const { initialBranch } = yield* initRepoWithCommit(cwd);
5530 - yield* git(cwd, ["submodule", "add", submoduleRepo, "shared"]);
5530 + // A file URL transfers a pack like a network remote; a plain path hardlinks silently.
5531 + yield* git(cwd, ["submodule", "add", NodeURL.pathToFileURL(submoduleRepo).href, "shared"]);
5532 yield* git(cwd, ["commit", "-m", "add submodule"]);
5533 const recordedHead = yield* git(submoduleRepo, ["rev-parse", "HEAD"]);
5534 yield* writeTextFile(submoduleRepo, "SHARED.md", "# newer remote default\n");
@@ -5602,7 +5603,11 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
5603 yield* git(pathService.join(worktreePath, "shared"), ["status", "--porcelain"]),
5604 "",
5605 );
5605 - if (progress) assert.isNotEmpty(yield* Ref.get(lines));
5606 + if (progress) {
5607 + assert.isTrue(
5608 + (yield* Ref.get(lines)).some((line) => line.startsWith("Receiving objects")),
5609 + );
5610 + }
5611 }).pipe(withGitFileProtocol),
5612 );
5613
apps/server/src/vcs/GitVcsDriverCore.ts
+11 -3
@@ -4708,9 +4708,14 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
4708 runGit(
4709 "GitVcsDriver.createWorktree.updateSubmodules",
4710 worktreePath,
4711 - submoduleMode.value === "recursive"
4712 - ? ["submodule", "update", "--init", "--recursive"]
4713 - : ["submodule", "update", "--init"],
4711 + [
4712 + "submodule",
4713 + "update",
4714 + "--init",
4715 + ...(submoduleMode.value === "recursive" ? ["--recursive"] : []),
4716 + // Git reports transfer progress to a pipe only when forced.
4717 + ...(onSubmoduleLine ? ["--progress"] : []),
4718 + ],
4719 {
4720 // Cloning scales with remote size; let it finish or be cancelled, like worktree add.
4721 timeoutMs: null,
@@ -4718,6 +4723,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
4723 ? {
4724 env: { LANGUAGE: "C" },
4725 progress: { onStdoutLine: onSubmoduleLine, onStderrLine: onSubmoduleLine },
4726 + // Progress for many submodules can pass the output cap; truncate instead of failing.
4727 + appendTruncationMarker: true,
4728 + keepLineCallbacksAfterTruncation: true,
4729 }
4730 : {}),
4731 },
apps/web/src/components/chat/WorktreeSetupCard.tsx
+1 -1
@@ -201,7 +201,7 @@ function StageRow({
201 trailing={
202 <>
203 {trailing ? (
204 - <span className="min-w-0 truncate text-xs text-muted-foreground tabular-nums">
204 + <span className="max-w-1/2 min-w-0 truncate text-xs text-muted-foreground tabular-nums">
205 {trailing}
206 </span>
207 ) : null}