The best way to control Claude Code, Codex and more from any computer or phone
fix(server): title regeneration works after a thread's worktree is cleaned up (#29606)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 23:07 UTC
476a99c1b937d8150c89e440cdc0dd766f174827
3 files changed
+54
-23
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+6
-1
@@ -266,7 +266,12 @@ function makeHarness(options: HarnessOptions = {}) {
266
});
267
const layerTitleRegeneration = ThreadTitleRegeneration.layer.pipe(
268
Layer.provide(
269
- Layer.mergeAll(layerThreadManagement, layerProjectedProjects, layerExternalServices),
269
+ Layer.mergeAll(
270
+ layerThreadManagement,
271
+ layerProjectedProjects,
272
+ layerExternalServices,
273
+ NodeServices.layer,
274
+ ),
275
),
276
);
277
return {
apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts
+40
-21
@@ -1,4 +1,5 @@
1
import { assert, describe, it, vi } from "@effect/vitest";
2
+import * as NodeServices from "@effect/platform-node/NodeServices";
3
import {
4
CommandId,
5
ChatAttachmentId,
@@ -14,6 +15,7 @@ import {
15
} from "@t3tools/contracts";
16
import * as DateTime from "effect/DateTime";
17
import * as Effect from "effect/Effect";
18
+import * as FileSystem from "effect/FileSystem";
19
import * as Layer from "effect/Layer";
20
import * as Option from "effect/Option";
21
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
@@ -98,6 +100,7 @@ function makeHarness(
100
layerProjectedProjects,
101
Layer.mock(TextGeneration.TextGeneration)({ generateThreadTitle }),
102
layerServerSettings,
103
+ NodeServices.layer,
104
),
105
),
106
);
@@ -113,7 +116,11 @@ function makeHarness(
116
};
117
}
118
116
-function createThread(input: { readonly command: string; readonly thread: string }) {
119
+function createThread(input: {
120
+ readonly command: string;
121
+ readonly thread: string;
122
+ readonly worktreePath?: string;
123
+}) {
124
return Effect.gen(function* () {
125
const threads = yield* ThreadManagement.ThreadManagementService;
126
const threadId = ThreadId.make(input.thread);
@@ -127,7 +134,7 @@ function createThread(input: { readonly command: string; readonly thread: string
134
runtimeMode: "full-access",
135
interactionMode: "default",
136
branch: null,
130
- worktreePath: null,
137
+ worktreePath: input.worktreePath ?? null,
138
createdBy: "user",
139
creationSource: "web",
140
});
@@ -391,31 +398,43 @@ describe("ThreadTitleRegenerationService", () => {
398
const harness = makeHarness({
399
generateTitle: () => Effect.succeed({ title: "Fresh title" }),
400
});
401
+ const fs = yield* FileSystem.FileSystem;
402
+ const existingWorktree = yield* fs.makeTempDirectoryScoped({ prefix: "title-worktree-" });
403
yield* Effect.gen(function* () {
404
const threads = yield* ThreadManagement.ThreadManagementService;
405
const titleRegeneration = yield* ThreadTitleRegeneration.ThreadTitleRegenerationService;
397
- const threadId = yield* createThread({
398
- command: "command:title:landing:create",
399
- thread: "thread:title:landing",
400
- });
401
- yield* dispatchUserMessage({
402
- command: "command:title:landing:message",
403
- threadId,
404
- text: "Investigate the flaky login test",
405
- });
406
- const requestId = yield* armRegeneration({ command: "command:title:landing:1", threadId });
406
+ const cases = [
407
+ { name: "removed", worktreePath: "/repo-worktrees/removed-by-cleanup", cwd: "/repo" },
408
+ { name: "existing", worktreePath: existingWorktree, cwd: existingWorktree },
409
+ ];
410
+ for (const [index, testCase] of cases.entries()) {
411
+ const threadId = yield* createThread({
412
+ command: `command:title:landing:${testCase.name}:create`,
413
+ thread: `thread:title:landing:${testCase.name}`,
414
+ worktreePath: testCase.worktreePath,
415
+ });
416
+ yield* dispatchUserMessage({
417
+ command: `command:title:landing:${testCase.name}:message`,
418
+ threadId,
419
+ text: "Investigate the flaky login test",
420
+ });
421
+ const requestId = yield* armRegeneration({
422
+ command: `command:title:landing:${testCase.name}:1`,
423
+ threadId,
424
+ });
425
408
- yield* titleRegeneration.execute({ threadId, requestId, kind: { type: "regenerate" } });
426
+ yield* titleRegeneration.execute({ threadId, requestId, kind: { type: "regenerate" } });
427
410
- const call = harness.generateThreadTitle.mock.calls[0]?.[0];
411
- assert.equal(call?.previousTitle, "Seed title");
412
- assert.equal(call?.cwd, "/repo");
413
- assert.include(call?.message, "USER:\nInvestigate the flaky login test");
414
- const projection = yield* threads.getThreadProjection(threadId);
415
- assert.equal(projection.thread.title, "Fresh title");
416
- assert.isNotOk(projection.thread.titleRegeneration);
428
+ const call = harness.generateThreadTitle.mock.calls[index]?.[0];
429
+ assert.equal(call?.previousTitle, "Seed title");
430
+ assert.equal(call?.cwd, testCase.cwd);
431
+ assert.include(call?.message, "USER:\nInvestigate the flaky login test");
432
+ const projection = yield* threads.getThreadProjection(threadId);
433
+ assert.equal(projection.thread.title, "Fresh title");
434
+ assert.isNotOk(projection.thread.titleRegeneration);
435
+ }
436
}).pipe(Effect.provide(harness.layer));
418
- }),
437
+ }).pipe(Effect.provide(NodeServices.layer)),
438
);
439
440
it.effect("titles a fork's first message with the source history up to the fork point", () =>
apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts
+8
-1
@@ -13,6 +13,7 @@ import {
13
import * as Cause from "effect/Cause";
14
import * as Context from "effect/Context";
15
import * as Effect from "effect/Effect";
16
+import * as FileSystem from "effect/FileSystem";
17
import * as Layer from "effect/Layer";
18
import * as Option from "effect/Option";
19
import * as Schedule from "effect/Schedule";
@@ -50,6 +51,7 @@ const make = Effect.gen(function* () {
51
const projects = yield* ProjectStore.ProjectStoreV2;
52
const serverSettings = yield* ServerSettings.ServerSettingsService;
53
const textGeneration = yield* TextGeneration.TextGeneration;
54
+ const fileSystem = yield* FileSystem.FileSystem;
55
56
const complete = (input: {
57
readonly threadId: ThreadId;
@@ -160,8 +162,13 @@ const make = Effect.gen(function* () {
162
yield* serverSettings.getSettings,
163
projection.thread.projectId,
164
).settings;
165
+ // Storage cleanup removes worktrees but keeps the path; CLIs cannot spawn in a missing cwd.
166
+ const worktreePath = projection.thread.worktreePath;
167
+ const worktreeExists =
168
+ worktreePath !== null &&
169
+ (yield* fileSystem.exists(worktreePath).pipe(Effect.orElseSucceed(() => false)));
170
const result = yield* textGeneration.generateThreadTitle({
164
- cwd: projection.thread.worktreePath ?? project.value.workspaceRoot,
171
+ cwd: worktreeExists ? worktreePath : project.value.workspaceRoot,
172
message: context.message,
173
attachments: context.attachments,
174
...(input.kind.type === "regenerate" ? { previousTitle: projection.thread.title } : {}),