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): tell the thread when its worktree branch keeps the temporary name (#34813)
Julius Marminge committed
Nov 11, 2026 at 23:14 UTC
c833a60de23fa45859bd026510d2c33397f39610
3 files changed
+91
-1
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+40
@@ -25,6 +25,7 @@ import {
25
ScheduledTaskId,
26
type ServerProvider,
27
ThreadId,
28
+ TextGenerationError,
29
} from "@t3tools/contracts";
30
import * as Cause from "effect/Cause";
31
import * as Deferred from "effect/Deferred";
@@ -241,6 +242,7 @@ function makeHarness(options: HarnessOptions = {}) {
242
layerExternalServices,
243
layerThreadManagement,
244
layerReceipts,
245
+ layerOrchestrator,
246
IdAllocator.layer,
247
),
248
),
@@ -2420,6 +2422,44 @@ it.effect("starts the agent of a new worktree thread only after its branch is re
2422
}),
2423
);
2424
2425
+it.effect("tells the thread when its worktree branch could not be renamed", () =>
2426
+ Effect.gen(function* () {
2427
+ const harness = makeHarness({
2428
+ generateBranchName: () =>
2429
+ Effect.fail(
2430
+ new TextGenerationError({
2431
+ operation: "generateBranchName",
2432
+ detail: "Failed to spawn Codex CLI process",
2433
+ }),
2434
+ ),
2435
+ });
2436
+ yield* Effect.gen(function* () {
2437
+ const launches = yield* ThreadLaunch.ThreadLaunchService;
2438
+ const tracker = yield* WorktreeSetupTracker.WorktreeSetupTracker;
2439
+ const threads = yield* ThreadManagement.ThreadManagementService;
2440
+ const launched = yield* launches.launch(
2441
+ launchInput({
2442
+ command: "launch:rename-fails",
2443
+ thread: "thread:rename-fails",
2444
+ message: "Start",
2445
+ workspace: { type: "worktree", baseRef: "main" },
2446
+ }),
2447
+ );
2448
+ yield* tracker.stream(launched.threadId).pipe(
2449
+ Stream.filter((snapshot) => snapshot?.phase === "done"),
2450
+ Stream.runHead,
2451
+ );
2452
+ const projection = yield* threads.getThreadProjection(launched.threadId);
2453
+ const notice = projection.turnItems.find((item) => item.type === "system_notice");
2454
+ assert.equal(notice?.type === "system_notice" ? notice.runId : null, projection.runs[0]?.id);
2455
+ assert.include(
2456
+ notice?.type === "system_notice" ? notice.message : "",
2457
+ `stays ${projection.thread.branch}. Text generation failed in generateBranchName: Failed to spawn Codex CLI process`,
2458
+ );
2459
+ }).pipe(Effect.provide(harness.layer));
2460
+ }),
2461
+);
2462
+
2463
it.effect.each([0, 1])("releases an async setup before its completion with exit %s", (exitCode) =>
2464
Effect.gen(function* () {
2465
const completion = yield* Deferred.make<{ exitCode: number | null; durationMs: number }>();
apps/server/src/orchestration-v2/ThreadLaunchService.ts
+50
-1
@@ -23,6 +23,7 @@ import {
23
} from "@t3tools/contracts";
24
import * as Cause from "effect/Cause";
25
import * as Context from "effect/Context";
26
+import * as DateTime from "effect/DateTime";
27
import * as Effect from "effect/Effect";
28
import * as Exit from "effect/Exit";
29
import * as Fiber from "effect/Fiber";
@@ -47,6 +48,7 @@ import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
48
import * as ServerSettings from "../serverSettings.ts";
49
import * as TextGeneration from "../textGeneration/TextGeneration.ts";
50
import * as CommandReceiptStore from "./CommandReceiptStore.ts";
51
+import * as EventSink from "./EventSink.ts";
52
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
53
import type * as Orchestrator from "./Orchestrator.ts";
54
import { makeProviderFailure } from "@t3tools/provider-core/server/failure";
@@ -247,6 +249,7 @@ const make = Effect.gen(function* () {
249
const receipts = yield* CommandReceiptStore.CommandReceiptStoreV2;
250
const ids = yield* IdAllocator.IdAllocatorV2;
251
const threads = yield* ThreadManagement.ThreadManagementService;
252
+ const eventSink = yield* EventSink.EventSinkV2;
253
const managedFolders = yield* ManagedProjectFolders.ManagedProjectFolders;
254
// A project-folder launch that names no branch records the folder's checkout, as the composer does.
255
const launchBranch = (strategy: ThreadLaunchWorkspaceStrategy, workspaceRoot: string) =>
@@ -268,6 +271,46 @@ const make = Effect.gen(function* () {
271
cause,
272
});
273
274
+ const recordBranchRenameFailure = Effect.fn("ThreadLaunchService.recordBranchRenameFailure")(
275
+ function* (threadId: ThreadId, runId: RunId, branch: string, cause: Cause.Cause<unknown>) {
276
+ const error = Cause.squash(cause);
277
+ const now = yield* DateTime.now;
278
+ yield* eventSink.write({
279
+ events: [
280
+ {
281
+ id: yield* ids.allocate.event({ threadId }),
282
+ type: "turn-item.updated",
283
+ threadId,
284
+ runId,
285
+ occurredAt: now,
286
+ payload: {
287
+ id: ids.derive.runSignalTurnItem({ runId, signal: "branch-rename" }),
288
+ threadId,
289
+ runId,
290
+ nodeId: null,
291
+ providerThreadId: null,
292
+ providerTurnId: null,
293
+ nativeItemRef: null,
294
+ parentItemId: null,
295
+ // EventSink allocates the real position, after the run's existing items.
296
+ ordinal: 0,
297
+ status: "completed",
298
+ title: "Branch not renamed",
299
+ startedAt: now,
300
+ completedAt: now,
301
+ updatedAt: now,
302
+ type: "system_notice",
303
+ message: `Could not rename the worktree branch, so it stays ${branch}. ${error instanceof Error ? error.message : String(error)}`,
304
+ },
305
+ },
306
+ ],
307
+ });
308
+ },
309
+ Effect.catchCause((cause) =>
310
+ Effect.logWarning("Could not record the branch rename failure", { cause }),
311
+ ),
312
+ );
313
+
314
const readReceipt = (input: ThreadLaunchInput, commandId: CommandId) =>
315
receipts
316
.getByCommandId(commandId)
@@ -638,7 +681,13 @@ const make = Effect.gen(function* () {
681
threadId,
682
oldBranch,
683
cause,
641
- }),
684
+ }).pipe(
685
+ Effect.andThen(
686
+ runId === null || Cause.hasInterruptsOnly(cause)
687
+ ? Effect.void
688
+ : recordBranchRenameFailure(threadId, runId, oldBranch, cause),
689
+ ),
690
+ ),
691
),
692
Effect.forkIn(preparationScope),
693
);
apps/server/src/orchestration-v2/runtimeLayer.ts
+1
@@ -283,6 +283,7 @@ const layerThreadLaunchProvided = ThreadLaunchService.layer.pipe(
283
layerManagedProjectFoldersProvided,
284
layerThreadManagementProvided,
285
layerCommandReceiptStoreProvided,
286
+ layerEventSink,
287
IdAllocator.layer,
288
),
289
),