diff --git a/apps/server/src/review/ReviewService.test.ts b/apps/server/src/review/ReviewService.test.ts index e97764a7a5..e1a9ebdb72 100644 --- a/apps/server/src/review/ReviewService.test.ts +++ b/apps/server/src/review/ReviewService.test.ts @@ -122,7 +122,9 @@ function makeThread(overrides: Partial = {}): Orchestration runtimeMode: "local", interactionMode: "chat", branch: null, - worktreePath: null, + // Tests mock getProjectShellById to None, so cwd resolution relies on + // the worktree path; a thread with neither now fails loudly by design. + worktreePath: "/tmp/t3-review-test-worktree", latestTurn: null, createdAt: "2026-07-20T00:00:00.000Z", updatedAt: "2026-07-20T00:00:00.000Z", @@ -370,6 +372,28 @@ describe("ReviewService", () => { }).pipe(Effect.provide(NodeServices.layer)), ); + it.effect("summarizeThread fails loudly when no workspace cwd can be resolved", () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const workspaceRoot = yield* fs.makeTempDirectoryScoped({ prefix: "t3-review-workspace-" }); + const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-review-base-" }); + // No worktree and (per the mock) no project shell: cwd is unresolvable. + const thread = makeThread({ worktreePath: null }); + + const error = yield* Effect.gen(function* () { + const review = yield* ReviewService.ReviewService; + return yield* review + .summarizeThread({ threadId: thread.id, canSettleNow: true }) + .pipe(Effect.flip); + }).pipe(Effect.provide(makeLayer({ workspaceRoot, baseDir, thread }))); + + assert.strictEqual(error._tag, "TextGenerationError"); + if (error._tag === "TextGenerationError") { + assert.match(error.detail, /Unable to resolve a workspace directory/); + } + }).pipe(Effect.provide(NodeServices.layer)), + ); + it.effect("summarizeThread treats a queued turn start as active", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; diff --git a/apps/server/src/review/ReviewService.ts b/apps/server/src/review/ReviewService.ts index 43efedf634..a79e6729ba 100644 --- a/apps/server/src/review/ReviewService.ts +++ b/apps/server/src/review/ReviewService.ts @@ -178,11 +178,21 @@ export const make = Effect.gen(function* () { const projectOption = yield* projectionSnapshotQuery .getProjectShellById(thread.projectId) .pipe(Effect.mapError(mapProjectionError)); - const cwd = - resolveThreadWorkspaceCwd({ - thread, - projects: Option.isSome(projectOption) ? [projectOption.value] : [], - }) ?? process.cwd(); + // No silent process.cwd() fallback: the cwd is handed to the provider + // CLI spawn, which reads local context files (AGENTS.md, CLAUDE.md) from + // it — reviewing "the server's own directory" would leak unrelated + // content into an external LLM prompt. Fail the item instead; the client + // shows it as a retry-able error card. + const cwd = resolveThreadWorkspaceCwd({ + thread, + projects: Option.isSome(projectOption) ? [projectOption.value] : [], + }); + if (cwd === undefined) { + return yield* new TextGenerationError({ + operation: "generateThreadReview", + detail: `Unable to resolve a workspace directory for thread '${input.threadId}'.`, + }); + } const settled = thread.messages.filter((message) => !message.streaming); const firstUserMessage = settled.find((message) => message.role === "user")?.text ?? null;