Skip to content

Commit fce8508

Browse files
kakismashclaudejuliusmarminge
authored
fix(server): surface a missing workspace folder instead of a spawn error (#5040)
Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 8faf031 commit fce8508

6 files changed

Lines changed: 217 additions & 34 deletions

File tree

‎apps/server/integration/providerService.integration.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ const makeIntegrationFixture = (options?: { readonly analytics?: Layer.Layer<Ana
100100
Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers),
101101
).pipe(Layer.provide(SqlitePersistenceMemory));
102102

103-
const layer = makeProviderServiceLive().pipe(Layer.provide(shared));
103+
const layer = makeProviderServiceLive().pipe(
104+
Layer.provide(NodeServices.layer),
105+
Layer.provide(shared),
106+
);
104107

105108
return {
106109
cwd,

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts‎

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
3939

4040
import { deriveServerPaths, ServerConfig } from "../../config.ts";
4141
import { TextGenerationError } from "@t3tools/contracts";
42-
import { ProviderAdapterRequestError } from "../../provider/Errors.ts";
42+
import {
43+
ProviderAdapterRequestError,
44+
ProviderWorkspaceMissingError,
45+
type ProviderServiceError,
46+
} from "../../provider/Errors.ts";
4347
import { OrchestrationEventStoreLive } from "../../persistence/Layers/OrchestrationEventStore.ts";
4448
import { OrchestrationCommandReceiptRepositoryLive } from "../../persistence/Layers/OrchestrationCommandReceipts.ts";
4549
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
@@ -181,7 +185,7 @@ describe("ProviderCommandReactor", () => {
181185
readonly stopSessionEffect?: () => Effect.Effect<void, ProviderAdapterRequestError>;
182186
readonly startSessionEffect?: (
183187
session: ProviderSession,
184-
) => Effect.Effect<ProviderSession, ProviderAdapterRequestError>;
188+
) => Effect.Effect<ProviderSession, ProviderServiceError>;
185189
readonly tryHandlePromptCommandEffect?: ProviderAuthService["Service"]["tryHandlePromptCommand"];
186190
}) {
187191
const now = "2026-01-01T00:00:00.000Z";
@@ -1217,6 +1221,58 @@ describe("ProviderCommandReactor", () => {
12171221
}),
12181222
);
12191223

1224+
effectIt.effect("shows the missing workspace message without a provider stack trace", () =>
1225+
Effect.gen(function* () {
1226+
const attempted = yield* Deferred.make<void>();
1227+
const missingCwd = "/missing/project/worktree";
1228+
const missingWorkspace = new ProviderWorkspaceMissingError({
1229+
threadId: ThreadId.make("thread-1"),
1230+
cwd: missingCwd,
1231+
});
1232+
const harness = yield* Effect.promise(() =>
1233+
createHarness({
1234+
startSessionEffect: () =>
1235+
Deferred.succeed(attempted, undefined).pipe(
1236+
Effect.andThen(Effect.fail(missingWorkspace)),
1237+
),
1238+
}),
1239+
);
1240+
1241+
yield* harness.engine.dispatch({
1242+
type: "thread.turn.start",
1243+
commandId: CommandId.make("cmd-turn-start-missing-workspace"),
1244+
threadId: ThreadId.make("thread-1"),
1245+
message: {
1246+
messageId: asMessageId("user-message-missing-workspace"),
1247+
role: "user",
1248+
text: "continue",
1249+
attachments: [],
1250+
},
1251+
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
1252+
runtimeMode: "approval-required",
1253+
createdAt: "2026-01-01T00:00:00.000Z",
1254+
});
1255+
yield* Deferred.await(attempted);
1256+
yield* Effect.promise(() => harness.drain());
1257+
1258+
const thread = (yield* Effect.promise(() => harness.readModel())).threads.find(
1259+
(entry) => entry.id === ThreadId.make("thread-1"),
1260+
);
1261+
expect(thread?.session).toMatchObject({
1262+
status: "error",
1263+
activeTurnId: null,
1264+
lastError: missingWorkspace.message,
1265+
});
1266+
const failure = thread?.activities.find(
1267+
(activity) => activity.kind === "provider.turn.start.failed",
1268+
);
1269+
expect(failure?.payload).toMatchObject({ detail: missingWorkspace.message });
1270+
expect(harness.runtimeSessions).toEqual([]);
1271+
expect(harness.sendTurn).not.toHaveBeenCalled();
1272+
expect(yield* Effect.promise(() => harness.readPendingTurnStarts())).toEqual([]);
1273+
}),
1274+
);
1275+
12201276
effectIt.effect("settles a failed provider startup and allows a clean retry", () =>
12211277
Effect.gen(function* () {
12221278
let failStartup = true;

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { increment, orchestrationEventsProcessedTotal } from "../../observabilit
3434
import {
3535
ProviderAdapterRequestError,
3636
ProviderAdapterValidationError,
37+
ProviderWorkspaceMissingError,
3738
} from "../../provider/Errors.ts";
3839
import type { ProviderServiceError } from "../../provider/Errors.ts";
3940
import { TextGeneration } from "../../textGeneration/TextGeneration.ts";
@@ -56,6 +57,7 @@ import { VcsStatusBroadcaster } from "../../vcs/VcsStatusBroadcaster.ts";
5657
import { GitWorkflowService } from "../../git/GitWorkflowService.ts";
5758
const isProviderAdapterRequestError = Schema.is(ProviderAdapterRequestError);
5859
const isProviderAdapterValidationError = Schema.is(ProviderAdapterValidationError);
60+
const isProviderWorkspaceMissingError = Schema.is(ProviderWorkspaceMissingError);
5961
const isProviderDriverKind = Schema.is(ProviderDriverKind);
6062

6163
type ProviderIntentEvent = Extract<
@@ -394,6 +396,9 @@ const make = Effect.gen(function* () {
394396
if (isProviderAdapterValidationError(failReason?.error)) {
395397
return failReason.error.issue;
396398
}
399+
if (isProviderWorkspaceMissingError(failReason?.error)) {
400+
return failReason.error.message;
401+
}
397402
return Cause.pretty(cause);
398403
};
399404

‎apps/server/src/provider/Errors.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ export class ProviderAdapterProcessError extends Schema.TaggedErrorClass<Provide
8585
}
8686
}
8787

88+
/**
89+
* ProviderWorkspaceMissingError - The session's working directory no longer
90+
* exists on disk, so no provider process can start in it.
91+
*/
92+
export class ProviderWorkspaceMissingError extends Schema.TaggedErrorClass<ProviderWorkspaceMissingError>()(
93+
"ProviderWorkspaceMissingError",
94+
{
95+
threadId: Schema.String,
96+
cwd: Schema.String,
97+
},
98+
) {
99+
override get message(): string {
100+
return `This thread's workspace folder no longer exists or is not a directory: ${this.cwd}. Restore the folder at this path before retrying.`;
101+
}
102+
}
103+
88104
/**
89105
* ProviderValidationError - Invalid provider API input.
90106
*/
@@ -197,6 +213,7 @@ export type ProviderAdapterError =
197213
export type ProviderServiceError =
198214
| ProviderValidationError
199215
| ProviderUnsupportedError
216+
| ProviderWorkspaceMissingError
200217
| ProviderInstanceNotFoundError
201218
| ProviderSessionNotFoundError
202219
| ProviderSessionDirectoryPersistenceError

0 commit comments

Comments
 (0)