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, 21:00 UTC
fix(server): a new worktree thread's agent starts on its renamed branch (#34781)
Julius Marminge committed
Nov 11, 2026 at 22:41 UTC
8212aaaf4dc280cb2dce3a79d70d75081bce10c9
2 files changed
+53
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+51
@@ -2353,6 +2353,57 @@ it.effect("stops an in-flight branch rename when tracked setup is cancelled", ()
2353
}),
2354
);
2355
2356
+it.effect("starts the agent of a new worktree thread only after its branch is renamed", () =>
2357
+ Effect.gen(function* () {
2358
+ const branchNameStarted = yield* Deferred.make<void>();
2359
+ const allowBranchName = yield* Deferred.make<void>();
2360
+ const releasedAtRename = yield* Deferred.make<boolean>();
2361
+ let releaseEffects: Effect.Effect<ReadonlyArray<unknown>> = Effect.succeed([]);
2362
+ const harness = makeHarness({
2363
+ generateBranchName: () =>
2364
+ Deferred.succeed(branchNameStarted, undefined).pipe(
2365
+ Effect.andThen(Deferred.await(allowBranchName)),
2366
+ Effect.as({ branch: "generated-branch" }),
2367
+ ),
2368
+ renameBranch: (input) =>
2369
+ Effect.suspend(() => releaseEffects).pipe(
2370
+ Effect.flatMap((effects) => Deferred.succeed(releasedAtRename, effects.length > 0)),
2371
+ Effect.as({ branch: input.newBranch }),
2372
+ ),
2373
+ });
2374
+ yield* Effect.gen(function* () {
2375
+ const launches = yield* ThreadLaunch.ThreadLaunchService;
2376
+ const tracker = yield* WorktreeSetupTracker.WorktreeSetupTracker;
2377
+ const outbox = yield* EffectOutbox.EffectOutboxV2;
2378
+ const input = launchInput({
2379
+ command: "launch:release-after-rename",
2380
+ thread: "thread:release-after-rename",
2381
+ message: "Start",
2382
+ workspace: { type: "worktree", baseRef: "main" },
2383
+ });
2384
+ releaseEffects = outbox
2385
+ .listByCommandId(CommandId.make(`${input.commandId}:release`))
2386
+ .pipe(Effect.orDie);
2387
+ const launched = yield* launches.launch(input);
2388
+ yield* Deferred.await(branchNameStarted);
2389
+ yield* tracker.stream(launched.threadId).pipe(
2390
+ Stream.filter(
2391
+ (snapshot) =>
2392
+ snapshot?.stages.some(
2393
+ (stage) => stage.id === "setup-script" && stage.status === "skipped",
2394
+ ) === true,
2395
+ ),
2396
+ Stream.runHead,
2397
+ );
2398
+ yield* Deferred.succeed(allowBranchName, undefined);
2399
+ assert.isFalse(
2400
+ yield* Deferred.await(releasedAtRename),
2401
+ "the agent's run was released while its branch still had the temporary name",
2402
+ );
2403
+ }).pipe(Effect.provide(harness.layer));
2404
+ }),
2405
+);
2406
+
2407
it.effect.each([0, 1])("releases an async setup before its completion with exit %s", (exitCode) =>
2408
Effect.gen(function* () {
2409
const completion = yield* Deferred.make<{ exitCode: number | null; durationMs: number }>();
apps/server/src/orchestration-v2/ThreadLaunchService.ts
+2
@@ -719,6 +719,8 @@ const make = Effect.gen(function* () {
719
} else {
720
yield* setupTracker.stageStatus(threadId, "setup-script", "skipped");
721
}
722
+ // The agent must start on the branch name the thread will show.
723
+ if (branchRename !== null) yield* Fiber.join(branchRename);
724
yield* setupTracker.markUncancellable(threadId);
725
yield* setupTracker.stageStatus(threadId, "agent", "running");
726
if (runId !== null) {