Fail thread review loudly when workspace cwd is unresolvable
The provider CLI spawn reads local context files (AGENTS.md, CLAUDE.md) from its cwd, so silently falling back to process.cwd() when a thread has no worktree and its project shell is missing would mix the server's own directory contents into an external LLM prompt. Return a typed TextGenerationError instead — the sweep UI already renders it as a retry-able error card. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
f8e63b222d
commit
3afe22dd31
2 files changed
+40
-6
No files matched your search
@@ -122,7 +122,9 @@ function makeThread(overrides: Partial<OrchestrationThread> = {}): 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user