@devries-cameron20 / t3code Mirror · read-only / commits / fce8508456
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 24, 10:15 UTC

fix(server): surface a missing workspace folder instead of a spawn error (#5040)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com>

Joaquin Navarro committed Sep 4, 2026 at 20:31 UTC fce8508456e7f9218eebb02ecd764f9b3a47df6b
6 files changed +217 -34
apps/server/integration/providerService.integration.test.ts
+4 -1
@@ -100,7 +100,10 @@ const makeIntegrationFixture = (options?: { readonly analytics?: Layer.Layer<Ana
100 Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers),
101 ).pipe(Layer.provide(SqlitePersistenceMemory));
102
103 - const layer = makeProviderServiceLive().pipe(Layer.provide(shared));
103 + const layer = makeProviderServiceLive().pipe(
104 + Layer.provide(NodeServices.layer),
105 + Layer.provide(shared),
106 + );
107
108 return {
109 cwd,
apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts
+58 -2
@@ -39,7 +39,11 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
39
40 import { deriveServerPaths, ServerConfig } from "../../config.ts";
41 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";
47 import { OrchestrationEventStoreLive } from "../../persistence/Layers/OrchestrationEventStore.ts";
48 import { OrchestrationCommandReceiptRepositoryLive } from "../../persistence/Layers/OrchestrationCommandReceipts.ts";
49 import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
@@ -181,7 +185,7 @@ describe("ProviderCommandReactor", () => {
185 readonly stopSessionEffect?: () => Effect.Effect<void, ProviderAdapterRequestError>;
186 readonly startSessionEffect?: (
187 session: ProviderSession,
184 - ) => Effect.Effect<ProviderSession, ProviderAdapterRequestError>;
188 + ) => Effect.Effect<ProviderSession, ProviderServiceError>;
189 readonly tryHandlePromptCommandEffect?: ProviderAuthService["Service"]["tryHandlePromptCommand"];
190 }) {
191 const now = "2026-01-01T00:00:00.000Z";
@@ -1217,6 +1221,58 @@ describe("ProviderCommandReactor", () => {
1221 }),
1222 );
1223
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 +
1276 effectIt.effect("settles a failed provider startup and allows a clean retry", () =>
1277 Effect.gen(function* () {
1278 let failStartup = true;
apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
+5
@@ -34,6 +34,7 @@ import { increment, orchestrationEventsProcessedTotal } from "../../observabilit
34 import {
35 ProviderAdapterRequestError,
36 ProviderAdapterValidationError,
37 + ProviderWorkspaceMissingError,
38 } from "../../provider/Errors.ts";
39 import type { ProviderServiceError } from "../../provider/Errors.ts";
40 import { TextGeneration } from "../../textGeneration/TextGeneration.ts";
@@ -56,6 +57,7 @@ import { VcsStatusBroadcaster } from "../../vcs/VcsStatusBroadcaster.ts";
57 import { GitWorkflowService } from "../../git/GitWorkflowService.ts";
58 const isProviderAdapterRequestError = Schema.is(ProviderAdapterRequestError);
59 const isProviderAdapterValidationError = Schema.is(ProviderAdapterValidationError);
60 +const isProviderWorkspaceMissingError = Schema.is(ProviderWorkspaceMissingError);
61 const isProviderDriverKind = Schema.is(ProviderDriverKind);
62
63 type ProviderIntentEvent = Extract<
@@ -394,6 +396,9 @@ const make = Effect.gen(function* () {
396 if (isProviderAdapterValidationError(failReason?.error)) {
397 return failReason.error.issue;
398 }
399 + if (isProviderWorkspaceMissingError(failReason?.error)) {
400 + return failReason.error.message;
401 + }
402 return Cause.pretty(cause);
403 };
404
apps/server/src/provider/Errors.ts
+17
@@ -85,6 +85,22 @@ export class ProviderAdapterProcessError extends Schema.TaggedErrorClass<Provide
85 }
86 }
87
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 +
104 /**
105 * ProviderValidationError - Invalid provider API input.
106 */
@@ -197,6 +213,7 @@ export type ProviderAdapterError =
213 export type ProviderServiceError =
214 | ProviderValidationError
215 | ProviderUnsupportedError
216 + | ProviderWorkspaceMissingError
217 | ProviderInstanceNotFoundError
218 | ProviderSessionNotFoundError
219 | ProviderSessionDirectoryPersistenceError
apps/server/src/provider/Layers/ProviderService.test.ts
+111 -29
@@ -32,6 +32,7 @@ import {
32 } from "@t3tools/shared/assistantCitations";
33 import { createModelSelection } from "@t3tools/shared/model";
34 import { it, assert, describe, vi } from "@effect/vitest";
35 +import { afterAll } from "vite-plus/test";
36
37 import * as Cause from "effect/Cause";
38 import * as Deferred from "effect/Deferred";
@@ -54,6 +55,7 @@ import {
55 ProviderAdapterSessionNotFoundError,
56 ProviderUnsupportedError,
57 ProviderValidationError,
58 + ProviderWorkspaceMissingError,
59 type ProviderAdapterError,
60 } from "../Errors.ts";
61 import type { ProviderAdapterShape } from "../Services/ProviderAdapter.ts";
@@ -79,6 +81,16 @@ const serverConfigTestLayer = ServerConfig.layerTest(process.cwd(), process.cwd(
81 Layer.provide(NodeServices.layer),
82 );
83
84 +// startSession verifies the workspace folder exists before dispatching to an
85 +// adapter, so session cwd fixtures must be real directories.
86 +const fixtureCwdRoot = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "provider-service-test-"));
87 +afterAll(() => NodeFS.rmSync(fixtureCwdRoot, { recursive: true, force: true }));
88 +function fixtureCwd(name: string): string {
89 + const dir = NodePath.join(fixtureCwdRoot, name);
90 + NodeFS.mkdirSync(dir, { recursive: true });
91 + return dir;
92 +}
93 +
94 const asRequestId = (value: string): ApprovalRequestId => ApprovalRequestId.make(value);
95 const asEventId = (value: string): EventId => EventId.make(value);
96 const asThreadId = (value: string): ThreadId => ThreadId.make(value);
@@ -425,6 +437,7 @@ function makeProviderServiceLayer(
437 const layer = it.layer(
438 Layer.mergeAll(
439 makeProviderServiceLive().pipe(
440 + Layer.provide(NodeServices.layer),
441 Layer.provide(providerAdapterLayer),
442 Layer.provide(directoryLayer),
443 Layer.provide(defaultServerSettingsLayer),
@@ -477,6 +490,7 @@ for (const [enabled, completed] of [
490 const scope = yield* Scope.make();
491 const services = yield* Layer.build(
492 makeProviderServiceLive().pipe(
493 + Layer.provide(NodeServices.layer),
494 Layer.provide(
495 Layer.succeed(ProviderSessionDirectory.ProviderSessionDirectory, directory),
496 ),
@@ -596,6 +610,7 @@ it.effect("ProviderServiceLive catches stopAll failures during shutdown", () =>
610 const directoryLayer = ProviderSessionDirectoryLive.pipe(Layer.provide(runtimeRepositoryLayer));
611 const providerLayer = Layer.mergeAll(
612 makeProviderServiceLive().pipe(
613 + Layer.provide(NodeServices.layer),
614 Layer.provide(providerAdapterLayer),
615 Layer.provide(directoryLayer),
616 Layer.provide(defaultServerSettingsLayer),
@@ -638,6 +653,7 @@ it.effect("ProviderServiceLive flushes deferred completions during shutdown", ()
653 const directoryLayer = ProviderSessionDirectoryLive.pipe(Layer.provide(runtimeRepositoryLayer));
654 const providerLayer = Layer.mergeAll(
655 makeProviderServiceLive().pipe(
656 + Layer.provide(NodeServices.layer),
657 Layer.provide(providerAdapterLayer),
658 Layer.provide(directoryLayer),
659 Layer.provide(defaultServerSettingsLayer),
@@ -774,6 +790,7 @@ it.effect("ProviderServiceLive rejects new sessions for disabled providers", ()
790 );
791 const directoryLayer = ProviderSessionDirectoryLive.pipe(Layer.provide(runtimeRepositoryLayer));
792 const providerLayer = makeProviderServiceLive().pipe(
793 + Layer.provide(NodeServices.layer),
794 Layer.provide(providerAdapterLayer),
795 Layer.provide(directoryLayer),
796 Layer.provide(defaultServerSettingsLayer),
@@ -857,6 +874,7 @@ it.effect(
874 Layer.provide(runtimeRepositoryLayer),
875 );
876 const providerLayer = makeProviderServiceLive().pipe(
877 + Layer.provide(NodeServices.layer),
878 Layer.provide(providerAdapterLayer),
879 Layer.provide(directoryLayer),
880 Layer.provide(serverSettingsLayer),
@@ -926,6 +944,7 @@ it.effect("ProviderServiceLive rejects new sessions for disabled custom instance
944 );
945 const directoryLayer = ProviderSessionDirectoryLive.pipe(Layer.provide(runtimeRepositoryLayer));
946 const providerLayer = makeProviderServiceLive().pipe(
947 + Layer.provide(NodeServices.layer),
948 Layer.provide(providerAdapterLayer),
949 Layer.provide(directoryLayer),
950 Layer.provide(defaultServerSettingsLayer),
@@ -1044,7 +1063,7 @@ unsupportedRollback.layer("ProviderServiceLive unsupported rewind", (it) => {
1063 yield* provider.startSession(threadId, {
1064 providerInstanceId: codexInstanceId,
1065 threadId,
1047 - cwd: "/tmp/project",
1066 + cwd: fixtureCwd("project"),
1067 runtimeMode: "approval-required",
1068 });
1069 if (!active) {
@@ -1098,6 +1117,7 @@ it.effect(
1117 Layer.provide(runtimeRepositoryLayer),
1118 );
1119 const providerLayer = makeProviderServiceLive().pipe(
1120 + Layer.provide(NodeServices.layer),
1121 Layer.provide(Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, registry)),
1122 Layer.provide(directoryLayer),
1123 Layer.provide(defaultServerSettingsLayer),
@@ -1218,6 +1238,7 @@ it.effect("ProviderServiceLive keeps persisted resumable sessions on startup", (
1238 }).pipe(Effect.provide(directoryLayer));
1239
1240 const providerLayer = makeProviderServiceLive().pipe(
1241 + Layer.provide(NodeServices.layer),
1242 Layer.provide(Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, registry)),
1243 Layer.provide(directoryLayer),
1244 Layer.provide(defaultServerSettingsLayer),
@@ -1283,6 +1304,7 @@ it.effect(
1304 Layer.provide(runtimeRepositoryLayer),
1305 );
1306 const firstProviderLayer = makeProviderServiceLive().pipe(
1307 + Layer.provide(NodeServices.layer),
1308 Layer.provide(
1309 Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, firstRegistry),
1310 ),
@@ -1310,7 +1332,7 @@ it.effect(
1332 const session = yield* provider.startSession(threadId, {
1333 provider: ProviderDriverKind.make("codex"),
1334 providerInstanceId: codexInstanceId,
1313 - cwd: "/tmp/project",
1335 + cwd: fixtureCwd("project"),
1336 runtimeMode: "full-access",
1337 threadId,
1338 });
@@ -1343,6 +1365,7 @@ it.effect(
1365 Layer.provide(runtimeRepositoryLayer),
1366 );
1367 const secondProviderLayer = makeProviderServiceLive().pipe(
1368 + Layer.provide(NodeServices.layer),
1369 Layer.provide(
1370 Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, secondRegistry),
1371 ),
@@ -1380,7 +1403,7 @@ it.effect(
1403 threadId?: string;
1404 };
1405 assert.equal(startPayload.provider, "codex");
1383 - assert.equal(startPayload.cwd, "/tmp/project");
1406 + assert.equal(startPayload.cwd, fixtureCwd("project"));
1407 assert.deepEqual(startPayload.resumeCursor, updatedResumeCursor);
1408 assert.equal(startPayload.threadId, startedSession.threadId);
1409 }
@@ -1394,6 +1417,61 @@ it.effect(
1417 );
1418
1419 routing.layer("ProviderServiceLive routing", (it) => {
1420 + it.effect.each([CODEX_DRIVER, CLAUDE_AGENT_DRIVER, CURSOR_DRIVER])(
1421 + "rejects missing, file, and saved workspace paths before starting %s",
1422 + (driver) =>
1423 + Effect.gen(function* () {
1424 + const provider = yield* ProviderService.ProviderService;
1425 + const adapter =
1426 + driver === CODEX_DRIVER
1427 + ? routing.codex
1428 + : driver === CLAUDE_AGENT_DRIVER
1429 + ? routing.claude
1430 + : routing.cursor;
1431 + const cwd = fixtureCwd(`missing-workspace-${driver}`);
1432 + const movedCwd = `${cwd}-moved`;
1433 + const threadId = asThreadId(`missing-workspace-${driver}`);
1434 + const input = {
1435 + provider: driver,
1436 + providerInstanceId: ProviderInstanceId.make(driver),
1437 + threadId,
1438 + runtimeMode: "full-access" as const,
1439 + cwd,
1440 + };
1441 +
1442 + yield* provider.startSession(threadId, input);
1443 + yield* provider.stopSession({ threadId });
1444 + adapter.startSession.mockClear();
1445 + NodeFS.renameSync(cwd, movedCwd);
1446 +
1447 + const failure = yield* provider.startSession(threadId, input).pipe(Effect.flip);
1448 + assert.instanceOf(failure, ProviderWorkspaceMissingError);
1449 + assert.include(failure.message, cwd);
1450 + assert.equal(adapter.startSession.mock.calls.length, 0);
1451 +
1452 + const { cwd: _cwd, ...savedInput } = input;
1453 + const savedFailure = yield* provider.startSession(threadId, savedInput).pipe(Effect.flip);
1454 + assert.instanceOf(savedFailure, ProviderWorkspaceMissingError);
1455 + assert.include(savedFailure.message, cwd);
1456 + assert.equal(adapter.startSession.mock.calls.length, 0);
1457 +
1458 + NodeFS.writeFileSync(cwd, "not a directory");
1459 + const fileFailure = yield* provider.startSession(threadId, input).pipe(Effect.flip);
1460 + assert.instanceOf(fileFailure, ProviderWorkspaceMissingError);
1461 + assert.include(fileFailure.message, cwd);
1462 + assert.equal(adapter.startSession.mock.calls.length, 0);
1463 +
1464 + NodeFS.unlinkSync(cwd);
1465 + NodeFS.renameSync(movedCwd, cwd);
1466 + const restored = yield* provider.startSession(threadId, savedInput);
1467 + assert.equal(restored.cwd, cwd);
1468 + assert.equal(adapter.startSession.mock.calls.length, 1);
1469 + yield* provider.stopSession({ threadId });
1470 + adapter.startSession.mockClear();
1471 + adapter.stopSession.mockClear();
1472 + }),
1473 + );
1474 +
1475 it.effect("allows promptless continuation only for capable providers", () =>
1476 Effect.gen(function* () {
1477 const provider = yield* ProviderService.ProviderService;
@@ -1452,7 +1530,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
1530 provider: ProviderDriverKind.make("codex"),
1531 providerInstanceId: codexInstanceId,
1532 threadId: asThreadId("thread-1"),
1455 - cwd: "/tmp/project",
1533 + cwd: fixtureCwd("project"),
1534 runtimeMode: "full-access",
1535 });
1536 assert.equal(session.provider, "codex");
@@ -1522,7 +1600,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
1600 threadId?: string;
1601 };
1602 assert.equal(startPayload.provider, "codex");
1525 - assert.equal(startPayload.cwd, "/tmp/project");
1603 + assert.equal(startPayload.cwd, fixtureCwd("project"));
1604 assert.deepEqual(startPayload.resumeCursor, session.resumeCursor);
1605 assert.equal(startPayload.threadId, session.threadId);
1606 }
@@ -1799,7 +1877,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
1877 provider: CODEX_DRIVER,
1878 providerInstanceId: codexInstanceId,
1879 threadId,
1802 - cwd: "/tmp/feedback-project",
1880 + cwd: fixtureCwd("feedback-project"),
1881 runtimeMode: "full-access",
1882 });
1883 yield* routing.codex.stopSession(threadId);
@@ -1862,7 +1940,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
1940 provider: ProviderDriverKind.make("codex"),
1941 providerInstanceId: codexInstanceId,
1942 threadId: asThreadId("thread-attach"),
1865 - cwd: "/tmp/project",
1943 + cwd: fixtureCwd("project"),
1944 runtimeMode: "full-access",
1945 });
1946
@@ -1937,7 +2015,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2015 provider: ProviderDriverKind.make("codex"),
2016 providerInstanceId: codexInstanceId,
2017 threadId: asThreadId("thread-1"),
1940 - cwd: "/tmp/project",
2018 + cwd: fixtureCwd("project"),
2019 runtimeMode: "full-access",
2020 });
2021 yield* routing.codex.stopSession(initial.threadId);
@@ -1963,7 +2041,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2041 threadId?: string;
2042 };
2043 assert.equal(startPayload.provider, "codex");
1966 - assert.equal(startPayload.cwd, "/tmp/project");
2044 + assert.equal(startPayload.cwd, fixtureCwd("project"));
2045 assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
2046 assert.equal(startPayload.threadId, initial.threadId);
2047 }
@@ -1982,7 +2060,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2060 provider: ProviderDriverKind.make("codex"),
2061 providerInstanceId: codexInstanceId,
2062 threadId: asThreadId("thread-reap-preserve"),
1985 - cwd: "/tmp/project-reap-preserve",
2063 + cwd: fixtureCwd("project-reap-preserve"),
2064 runtimeMode: "full-access",
2065 });
2066
@@ -2017,7 +2095,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2095 threadId?: string;
2096 };
2097 assert.equal(startPayload.provider, "codex");
2020 - assert.equal(startPayload.cwd, "/tmp/project-reap-preserve");
2098 + assert.equal(startPayload.cwd, fixtureCwd("project-reap-preserve"));
2099 assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
2100 assert.equal(startPayload.threadId, initial.threadId);
2101 }
@@ -2033,7 +2111,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2111 provider: ProviderDriverKind.make("claudeAgent"),
2112 providerInstanceId: claudeAgentInstanceId,
2113 threadId: asThreadId("thread-claude"),
2036 - cwd: "/tmp/project-claude",
2114 + cwd: fixtureCwd("project-claude"),
2115 runtimeMode: "full-access",
2116 });
2117
@@ -2049,7 +2127,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2127 };
2128 assert.equal(startPayload.provider, "claudeAgent");
2129 assert.equal(startPayload.providerInstanceId, claudeAgentInstanceId);
2052 - assert.equal(startPayload.cwd, "/tmp/project-claude");
2130 + assert.equal(startPayload.cwd, fixtureCwd("project-claude"));
2131 }
2132 }),
2133 );
@@ -2064,7 +2142,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2142 provider: ProviderDriverKind.make("codex"),
2143 providerInstanceId: codexInstanceId,
2144 threadId,
2067 - cwd: "/tmp/project-binding-mismatch",
2145 + cwd: fixtureCwd("project-binding-mismatch"),
2146 runtimeMode: "full-access",
2147 });
2148 yield* directory.upsert({
@@ -2094,7 +2172,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2172 provider: ProviderDriverKind.make("codex"),
2173 providerInstanceId: codexInstanceId,
2174 threadId,
2097 - cwd: "/tmp/project-provider-replacement",
2175 + cwd: fixtureCwd("project-provider-replacement"),
2176 runtimeMode: "full-access",
2177 });
2178
@@ -2105,7 +2183,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2183 provider: ProviderDriverKind.make("claudeAgent"),
2184 providerInstanceId: claudeAgentInstanceId,
2185 threadId,
2108 - cwd: "/tmp/project-provider-replacement",
2186 + cwd: fixtureCwd("project-provider-replacement"),
2187 runtimeMode: "full-access",
2188 });
2189
@@ -2132,7 +2210,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2210 provider: ProviderDriverKind.make("codex"),
2211 providerInstanceId: codexInstanceId,
2212 threadId: asThreadId("thread-1"),
2135 - cwd: "/tmp/project-send-turn",
2213 + cwd: fixtureCwd("project-send-turn"),
2214 runtimeMode: "full-access",
2215 });
2216
@@ -2157,7 +2235,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2235 threadId?: string;
2236 };
2237 assert.equal(startPayload.provider, "codex");
2160 - assert.equal(startPayload.cwd, "/tmp/project-send-turn");
2238 + assert.equal(startPayload.cwd, fixtureCwd("project-send-turn"));
2239 assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
2240 assert.equal(startPayload.threadId, initial.threadId);
2241 }
@@ -2173,7 +2251,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2251 provider: ProviderDriverKind.make("claudeAgent"),
2252 providerInstanceId: claudeAgentInstanceId,
2253 threadId: asThreadId("thread-claude-send-turn"),
2176 - cwd: "/tmp/project-claude-send-turn",
2254 + cwd: fixtureCwd("project-claude-send-turn"),
2255 modelSelection: createModelSelection(
2256 ProviderInstanceId.make("claudeAgent"),
2257 "claude-opus-4-6",
@@ -2204,7 +2282,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2282 threadId?: string;
2283 };
2284 assert.equal(startPayload.provider, "claudeAgent");
2207 - assert.equal(startPayload.cwd, "/tmp/project-claude-send-turn");
2285 + assert.equal(startPayload.cwd, fixtureCwd("project-claude-send-turn"));
2286 assert.deepEqual(
2287 startPayload.modelSelection,
2288 createModelSelection(ProviderInstanceId.make("claudeAgent"), "claude-opus-4-6", [
@@ -2368,6 +2446,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2446 Layer.provide(runtimeRepositoryLayer),
2447 );
2448 const firstProviderLayer = makeProviderServiceLive().pipe(
2449 + Layer.provide(NodeServices.layer),
2450 Layer.provide(
2451 Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, firstRegistry),
2452 ),
@@ -2389,7 +2468,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2468 provider: ProviderDriverKind.make("claudeAgent"),
2469 providerInstanceId: claudeAgentInstanceId,
2470 threadId: asThreadId("thread-claude-start"),
2392 - cwd: "/tmp/project-claude-start",
2471 + cwd: fixtureCwd("project-claude-start"),
2472 runtimeMode: "full-access",
2473 });
2474 }).pipe(Effect.provide(firstProviderLayer));
@@ -2407,6 +2486,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2486 Layer.provide(runtimeRepositoryLayer),
2487 );
2488 const secondProviderLayer = makeProviderServiceLive().pipe(
2489 + Layer.provide(NodeServices.layer),
2490 Layer.provide(
2491 Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, secondRegistry),
2492 ),
@@ -2430,7 +2510,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2510 provider: ProviderDriverKind.make("claudeAgent"),
2511 providerInstanceId: claudeAgentInstanceId,
2512 threadId: initial.threadId,
2433 - cwd: "/tmp/project-claude-start",
2513 + cwd: fixtureCwd("project-claude-start"),
2514 runtimeMode: "full-access",
2515 });
2516 }).pipe(Effect.provide(secondProviderLayer));
@@ -2446,7 +2526,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2526 threadId?: string;
2527 };
2528 assert.equal(startPayload.provider, "claudeAgent");
2449 - assert.equal(startPayload.cwd, "/tmp/project-claude-start");
2529 + assert.equal(startPayload.cwd, fixtureCwd("project-claude-start"));
2530 assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
2531 assert.equal(startPayload.threadId, initial.threadId);
2532 }
@@ -2476,6 +2556,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2556 Layer.provide(runtimeRepositoryLayer),
2557 );
2558 const firstProviderLayer = makeProviderServiceLive().pipe(
2559 + Layer.provide(NodeServices.layer),
2560 Layer.provide(
2561 Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, firstRegistry),
2562 ),
@@ -2497,7 +2578,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2578 provider: ProviderDriverKind.make("claudeAgent"),
2579 providerInstanceId: claudeAgentInstanceId,
2580 threadId: asThreadId("thread-claude-cwd"),
2500 - cwd: "/tmp/project-claude-cwd",
2581 + cwd: fixtureCwd("project-claude-cwd"),
2582 runtimeMode: "full-access",
2583 });
2584 }).pipe(Effect.provide(firstProviderLayer));
@@ -2510,6 +2591,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2591 Layer.provide(runtimeRepositoryLayer),
2592 );
2593 const secondProviderLayer = makeProviderServiceLive().pipe(
2594 + Layer.provide(NodeServices.layer),
2595 Layer.provide(
2596 Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, secondRegistry),
2597 ),
@@ -2548,7 +2630,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
2630 threadId?: string;
2631 };
2632 assert.equal(startPayload.provider, "claudeAgent");
2551 - assert.equal(startPayload.cwd, "/tmp/project-claude-cwd");
2633 + assert.equal(startPayload.cwd, fixtureCwd("project-claude-cwd"));
2634 assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
2635 assert.equal(startPayload.threadId, initial.threadId);
2636 }
@@ -2742,7 +2824,7 @@ fanout.layer("ProviderServiceLive fanout", (it) => {
2824 provider: ProviderDriverKind.make("claudeAgent"),
2825 providerInstanceId: claudeAgentInstanceId,
2826 threadId: asThreadId("thread-metrics"),
2745 - cwd: "/tmp/project",
2827 + cwd: fixtureCwd("project"),
2828 runtimeMode: "full-access",
2829 });
2830
@@ -2820,7 +2902,7 @@ fanout.layer("ProviderServiceLive fanout", (it) => {
2902 provider: ProviderDriverKind.make("claudeAgent"),
2903 providerInstanceId: claudeAgentInstanceId,
2904 threadId: asThreadId("thread-send-metrics"),
2823 - cwd: "/tmp/project-send-metrics",
2905 + cwd: fixtureCwd("project-send-metrics"),
2906 runtimeMode: "full-access",
2907 });
2908
@@ -4155,7 +4237,7 @@ validation.layer("ProviderServiceLive validation", (it) => {
4237 provider: ProviderDriverKind.make("codex"),
4238 providerInstanceId: codexInstanceId,
4239 threadId: asThreadId("thread-missing"),
4158 - cwd: "/tmp/project",
4240 + cwd: fixtureCwd("project"),
4241 runtimeMode: "full-access",
4242 });
4243
@@ -4204,7 +4286,7 @@ boundedListing.layer("ProviderServiceLive session listing", (it) => {
4286 provider: CODEX_DRIVER,
4287 providerInstanceId: codexInstanceId,
4288 threadId: activeSessionThreadId,
4207 - cwd: "/tmp/project-active-session",
4289 + cwd: fixtureCwd("project-active-session"),
4290 runtimeMode: "full-access",
4291 });
4292 listThreadIds.mockClear();
apps/server/src/provider/Layers/ProviderService.ts
+22 -2
@@ -35,6 +35,7 @@ import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
35 import * as DateTime from "effect/DateTime";
36 import * as Deferred from "effect/Deferred";
37 import * as Effect from "effect/Effect";
38 +import * as FileSystem from "effect/FileSystem";
39 import * as Layer from "effect/Layer";
40 import * as Option from "effect/Option";
41 import * as PubSub from "effect/PubSub";
@@ -55,8 +56,12 @@ import {
56 providerTurnMetricAttributes,
57 withMetrics,
58 } from "../../observability/Metrics.ts";
58 -import { ProviderAdapterRequestError } from "../Errors.ts";
59 -import { type ProviderAdapterError, ProviderValidationError } from "../Errors.ts";
59 +import {
60 + ProviderAdapterRequestError,
61 + type ProviderAdapterError,
62 + ProviderValidationError,
63 + ProviderWorkspaceMissingError,
64 +} from "../Errors.ts";
65 import type { ProviderAdapterShape } from "../Services/ProviderAdapter.ts";
66 import * as ProviderAdapterRegistry from "../Services/ProviderAdapterRegistry.ts";
67 import * as ProviderService from "../Services/ProviderService.ts";
@@ -322,6 +327,7 @@ const makeProviderService = Effect.fn("makeProviderService")(function* (
327 options?.issueMcpCredential ?? McpSessionRegistry.issueActiveMcpCredential;
328 const revokeMcpCredential =
329 options?.revokeMcpCredential ?? McpSessionRegistry.revokeActiveMcpThread;
330 + const fileSystem = yield* FileSystem.FileSystem;
331 const runtimeEventPubSub = yield* PubSub.unbounded<ProviderRuntimeEvent>();
332 const pendingCompactions = new Map<ThreadId, PendingCompaction>();
333 const timedOutNativeCompactions = new Set<ThreadId>();
@@ -1235,6 +1241,20 @@ const makeProviderService = Effect.fn("makeProviderService")(function* (
1241 : "none",
1242 "provider.cwd.effective": effectiveCwd ?? "",
1243 });
1244 + if (effectiveCwd !== undefined) {
1245 + // Fail fast with an actionable error when the workspace folder is
1246 + // gone (e.g. moved, deleted, or replaced by a plain file).
1247 + // Otherwise every adapter surfaces this as a misleading "failed to
1248 + // spawn <binary>" process error. Stat failures other than "missing"
1249 + // fall through to the adapter.
1250 + const workspaceIsDirectory = yield* fileSystem.stat(effectiveCwd).pipe(
1251 + Effect.map((workspaceStat) => workspaceStat.type === "Directory"),
1252 + Effect.catch((statError) => Effect.succeed(statError.reason._tag !== "NotFound")),
1253 + );
1254 + if (!workspaceIsDirectory) {
1255 + return yield* new ProviderWorkspaceMissingError({ threadId, cwd: effectiveCwd });
1256 + }
1257 + }
1258 const adapter = yield* registry.getByInstance(resolvedInstanceId);
1259 yield* clearTurnAnalyticsSession(resolvedInstanceId, threadId);
1260 yield* prepareMcpSession(threadId, resolvedInstanceId);