@devries-cameron20 / t3code Mirror · read-only / commits / c924d7898f
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, 13:30 UTC

fix(server): a worktree launch from a missing base branch names the branch (#34452)

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

Michael Bennett committed Nov 14, 2026 at 20:16 UTC c924d7898fb4a03aa04f390918b348ec980afe37
2 files changed +83 -3
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+63
@@ -1401,6 +1401,69 @@ it.effect("shows the fetch diagnosis when preparing a worktree from origin fails
1401 }).pipe(Effect.provide(harness.layer));
1402 });
1403
1404 +it.effect("names the missing base branch when a worktree cannot be created from it", () =>
1405 + Effect.gen(function* () {
1406 + const fs = yield* FileSystem.FileSystem;
1407 + const git = yield* GitVcsDriver.GitVcsDriver;
1408 + const directory = yield* fs.makeTempDirectoryScoped({ prefix: "launch-missing-base-" });
1409 + const cwd = `${directory}/repo`;
1410 + const remote = `${directory}/remote.git`;
1411 + yield* fs.makeDirectory(cwd);
1412 + const command = (at: string, args: string[]) =>
1413 + git.execute({ operation: "launch-test", cwd: at, args });
1414 + yield* command(cwd, ["init", "-b", "dev"]);
1415 + yield* command(cwd, ["config", "user.name", "Test"]);
1416 + yield* command(cwd, ["config", "user.email", "test@example.test"]);
1417 + yield* command(cwd, ["commit", "--allow-empty", "-m", "initial"]);
1418 + yield* command(cwd, ["init", "--bare", remote]);
1419 + yield* command(cwd, ["remote", "add", "origin", remote]);
1420 + yield* command(cwd, ["push", "-u", "origin", "dev"]);
1421 +
1422 + const harness = makeHarness({
1423 + git: {
1424 + resolveWorktreeBaseRemote: (input) => git.resolveWorktreeBaseRemote({ ...input, cwd }),
1425 + },
1426 + fetchWorktreeBaseCommit: (input) => git.fetchWorktreeBaseCommit({ ...input, cwd }),
1427 + createWorktree: (input, options) =>
1428 + git.createWorktree({ ...input, cwd, path: `${directory}/worktree` }, options),
1429 + });
1430 + yield* Effect.gen(function* () {
1431 + const launches = yield* ThreadLaunch.ThreadLaunchService;
1432 + const threads = yield* ThreadManagement.ThreadManagementService;
1433 + const launched = yield* launches.launch(
1434 + launchInput({
1435 + command: "command:launch:missing-base",
1436 + thread: "thread:launch:missing-base",
1437 + message: "Start from master",
1438 + workspace: { type: "worktree", baseRef: "master", startFromOrigin: true },
1439 + }),
1440 + );
1441 + yield* threads.streamStoredEventsFrom({ threadId: launched.threadId }).pipe(
1442 + Stream.filter(
1443 + (stored) =>
1444 + stored.event.type === "run.updated" && stored.event.payload.status === "failed",
1445 + ),
1446 + Stream.runHead,
1447 + );
1448 + const projection = yield* threads.getThreadProjection(launched.threadId);
1449 + assert.equal(projection.runs[0]?.status, "failed");
1450 + assert.include(
1451 + projection.turnItems.find((item) => item.type === "error")?.failure.message ?? "",
1452 + `Base ref "master" does not resolve to a commit in project "Project" (/repo).`,
1453 + );
1454 + }).pipe(Effect.provide(harness.layer));
1455 + }).pipe(
1456 + Effect.provide(
1457 + GitVcsDriver.layer.pipe(
1458 + Layer.provide(
1459 + ServerConfig.layerTest(process.cwd(), { prefix: "launch-missing-base-git-" }),
1460 + ),
1461 + Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1462 + ),
1463 + ),
1464 + ),
1465 +);
1466 +
1467 it.effect("rejects a preparation retry after the project disables its provider", () => {
1468 let fetchAttempts = 0;
1469 const harness = makeHarness({
apps/server/src/orchestration-v2/ThreadLaunchService.ts
+20 -3
@@ -164,6 +164,7 @@ export class ThreadLaunchBaseRefError extends Schema.TaggedError<ThreadLaunchBas
164 projectTitle: Schema.String,
165 workspaceRoot: Schema.String,
166 baseRef: Schema.String,
167 + cause: Schema.optional(Schema.Defect()),
168 },
169 ) {
170 override get message(): string {
@@ -564,8 +565,9 @@ const make = Effect.gen(function* () {
565 })
566 .pipe(Effect.mapError(mapError(input, "update-thread", threadId)));
567 }
567 - let startRef = input.workspaceStrategy.baseRef;
568 - let baseRefName = input.workspaceStrategy.baseRef;
568 + const requestedBaseRef = input.workspaceStrategy.baseRef;
569 + let startRef = requestedBaseRef;
570 + let baseRefName = requestedBaseRef;
571 const remote =
572 input.workspaceStrategy.startFromOrigin === true
573 ? yield* git
@@ -668,7 +670,22 @@ const make = Effect.gen(function* () {
670 },
671 },
672 )
671 - .pipe(Effect.mapError(mapError(input, "provision-worktree", threadId)));
673 + .pipe(
674 + Effect.catchIf(
675 + (error) => error.reason === "ref_not_found",
676 + (cause) =>
677 + Effect.fail(
678 + new ThreadLaunchBaseRefError({
679 + projectId: project.id,
680 + projectTitle: project.title,
681 + workspaceRoot: project.workspaceRoot,
682 + baseRef: requestedBaseRef,
683 + cause,
684 + }),
685 + ),
686 + ),
687 + Effect.mapError(mapError(input, "provision-worktree", threadId)),
688 + );
689 worktreePath = worktree.worktree.path;
690 branch = worktree.worktree.refName;
691 createdWorktreePath = worktreePath;