Skip to content

Commit 6f603ac

Browse files
saphidclaude
andcommitted
fix(server): title regeneration works after a thread's worktree is cleaned up
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 60aec28 commit 6f603ac

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ function makeHarness(options: HarnessOptions = {}) {
261261
});
262262
const layerTitleRegeneration = ThreadTitleRegeneration.layer.pipe(
263263
Layer.provide(
264-
Layer.mergeAll(layerThreadManagement, layerProjectedProjects, layerExternalServices),
264+
Layer.mergeAll(
265+
layerThreadManagement,
266+
layerProjectedProjects,
267+
layerExternalServices,
268+
NodeServices.layer,
269+
),
265270
),
266271
);
267272
return {

‎apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { assert, describe, it, vi } from "@effect/vitest";
2+
import * as NodeServices from "@effect/platform-node/NodeServices";
23
import {
34
CommandId,
45
ChatAttachmentId,
@@ -98,6 +99,7 @@ function makeHarness(
9899
layerProjectedProjects,
99100
Layer.mock(TextGeneration.TextGeneration)({ generateThreadTitle }),
100101
layerServerSettings,
102+
NodeServices.layer,
101103
),
102104
),
103105
);
@@ -113,7 +115,11 @@ function makeHarness(
113115
};
114116
}
115117

116-
function createThread(input: { readonly command: string; readonly thread: string }) {
118+
function createThread(input: {
119+
readonly command: string;
120+
readonly thread: string;
121+
readonly worktreePath?: string;
122+
}) {
117123
return Effect.gen(function* () {
118124
const threads = yield* ThreadManagement.ThreadManagementService;
119125
const threadId = ThreadId.make(input.thread);
@@ -127,7 +133,7 @@ function createThread(input: { readonly command: string; readonly thread: string
127133
runtimeMode: "full-access",
128134
interactionMode: "default",
129135
branch: null,
130-
worktreePath: null,
136+
worktreePath: input.worktreePath ?? null,
131137
createdBy: "user",
132138
creationSource: "web",
133139
});
@@ -397,6 +403,7 @@ describe("ThreadTitleRegenerationService", () => {
397403
const threadId = yield* createThread({
398404
command: "command:title:landing:create",
399405
thread: "thread:title:landing",
406+
worktreePath: "/repo-worktrees/removed-by-cleanup",
400407
});
401408
yield* dispatchUserMessage({
402409
command: "command:title:landing:message",

‎apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import * as Cause from "effect/Cause";
1414
import * as Context from "effect/Context";
1515
import * as Effect from "effect/Effect";
16+
import * as FileSystem from "effect/FileSystem";
1617
import * as Layer from "effect/Layer";
1718
import * as Option from "effect/Option";
1819
import * as Schedule from "effect/Schedule";
@@ -50,6 +51,7 @@ const make = Effect.gen(function* () {
5051
const projects = yield* ProjectStore.ProjectStoreV2;
5152
const serverSettings = yield* ServerSettings.ServerSettingsService;
5253
const textGeneration = yield* TextGeneration.TextGeneration;
54+
const fileSystem = yield* FileSystem.FileSystem;
5355

5456
const complete = (input: {
5557
readonly threadId: ThreadId;
@@ -160,8 +162,13 @@ const make = Effect.gen(function* () {
160162
yield* serverSettings.getSettings,
161163
projection.thread.projectId,
162164
).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)));
163170
const result = yield* textGeneration.generateThreadTitle({
164-
cwd: projection.thread.worktreePath ?? project.value.workspaceRoot,
171+
cwd: worktreeExists ? worktreePath : project.value.workspaceRoot,
165172
message: context.message,
166173
attachments: context.attachments,
167174
...(input.kind.type === "regenerate" ? { previousTitle: projection.thread.title } : {}),

0 commit comments

Comments
 (0)