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]>
This commit is contained in:
6 files changed
+217
-34
No files matched your search
@@ -100,7 +100,10 @@ const makeIntegrationFixture = (options?: { readonly analytics?: Layer.Layer<Ana
|
||||
Layer.succeed(ProviderEventLoggers, NoOpProviderEventLoggers),
|
||||
).pipe(Layer.provide(SqlitePersistenceMemory));
|
||||
|
||||
const layer = makeProviderServiceLive().pipe(Layer.provide(shared));
|
||||
const layer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(shared),
|
||||
);
|
||||
|
||||
return {
|
||||
cwd,
|
||||
|
||||
@@ -39,7 +39,11 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
|
||||
|
||||
import { deriveServerPaths, ServerConfig } from "../../config.ts";
|
||||
import { TextGenerationError } from "@t3tools/contracts";
|
||||
import { ProviderAdapterRequestError } from "../../provider/Errors.ts";
|
||||
import {
|
||||
ProviderAdapterRequestError,
|
||||
ProviderWorkspaceMissingError,
|
||||
type ProviderServiceError,
|
||||
} from "../../provider/Errors.ts";
|
||||
import { OrchestrationEventStoreLive } from "../../persistence/Layers/OrchestrationEventStore.ts";
|
||||
import { OrchestrationCommandReceiptRepositoryLive } from "../../persistence/Layers/OrchestrationCommandReceipts.ts";
|
||||
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
|
||||
@@ -181,7 +185,7 @@ describe("ProviderCommandReactor", () => {
|
||||
readonly stopSessionEffect?: () => Effect.Effect<void, ProviderAdapterRequestError>;
|
||||
readonly startSessionEffect?: (
|
||||
session: ProviderSession,
|
||||
) => Effect.Effect<ProviderSession, ProviderAdapterRequestError>;
|
||||
) => Effect.Effect<ProviderSession, ProviderServiceError>;
|
||||
readonly tryHandlePromptCommandEffect?: ProviderAuthService["Service"]["tryHandlePromptCommand"];
|
||||
}) {
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
@@ -1217,6 +1221,58 @@ describe("ProviderCommandReactor", () => {
|
||||
}),
|
||||
);
|
||||
|
||||
effectIt.effect("shows the missing workspace message without a provider stack trace", () =>
|
||||
Effect.gen(function* () {
|
||||
const attempted = yield* Deferred.make<void>();
|
||||
const missingCwd = "/missing/project/worktree";
|
||||
const missingWorkspace = new ProviderWorkspaceMissingError({
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
cwd: missingCwd,
|
||||
});
|
||||
const harness = yield* Effect.promise(() =>
|
||||
createHarness({
|
||||
startSessionEffect: () =>
|
||||
Deferred.succeed(attempted, undefined).pipe(
|
||||
Effect.andThen(Effect.fail(missingWorkspace)),
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
yield* harness.engine.dispatch({
|
||||
type: "thread.turn.start",
|
||||
commandId: CommandId.make("cmd-turn-start-missing-workspace"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
message: {
|
||||
messageId: asMessageId("user-message-missing-workspace"),
|
||||
role: "user",
|
||||
text: "continue",
|
||||
attachments: [],
|
||||
},
|
||||
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
|
||||
runtimeMode: "approval-required",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
});
|
||||
yield* Deferred.await(attempted);
|
||||
yield* Effect.promise(() => harness.drain());
|
||||
|
||||
const thread = (yield* Effect.promise(() => harness.readModel())).threads.find(
|
||||
(entry) => entry.id === ThreadId.make("thread-1"),
|
||||
);
|
||||
expect(thread?.session).toMatchObject({
|
||||
status: "error",
|
||||
activeTurnId: null,
|
||||
lastError: missingWorkspace.message,
|
||||
});
|
||||
const failure = thread?.activities.find(
|
||||
(activity) => activity.kind === "provider.turn.start.failed",
|
||||
);
|
||||
expect(failure?.payload).toMatchObject({ detail: missingWorkspace.message });
|
||||
expect(harness.runtimeSessions).toEqual([]);
|
||||
expect(harness.sendTurn).not.toHaveBeenCalled();
|
||||
expect(yield* Effect.promise(() => harness.readPendingTurnStarts())).toEqual([]);
|
||||
}),
|
||||
);
|
||||
|
||||
effectIt.effect("settles a failed provider startup and allows a clean retry", () =>
|
||||
Effect.gen(function* () {
|
||||
let failStartup = true;
|
||||
|
||||
@@ -34,6 +34,7 @@ import { increment, orchestrationEventsProcessedTotal } from "../../observabilit
|
||||
import {
|
||||
ProviderAdapterRequestError,
|
||||
ProviderAdapterValidationError,
|
||||
ProviderWorkspaceMissingError,
|
||||
} from "../../provider/Errors.ts";
|
||||
import type { ProviderServiceError } from "../../provider/Errors.ts";
|
||||
import { TextGeneration } from "../../textGeneration/TextGeneration.ts";
|
||||
@@ -56,6 +57,7 @@ import { VcsStatusBroadcaster } from "../../vcs/VcsStatusBroadcaster.ts";
|
||||
import { GitWorkflowService } from "../../git/GitWorkflowService.ts";
|
||||
const isProviderAdapterRequestError = Schema.is(ProviderAdapterRequestError);
|
||||
const isProviderAdapterValidationError = Schema.is(ProviderAdapterValidationError);
|
||||
const isProviderWorkspaceMissingError = Schema.is(ProviderWorkspaceMissingError);
|
||||
const isProviderDriverKind = Schema.is(ProviderDriverKind);
|
||||
|
||||
type ProviderIntentEvent = Extract<
|
||||
@@ -394,6 +396,9 @@ const make = Effect.gen(function* () {
|
||||
if (isProviderAdapterValidationError(failReason?.error)) {
|
||||
return failReason.error.issue;
|
||||
}
|
||||
if (isProviderWorkspaceMissingError(failReason?.error)) {
|
||||
return failReason.error.message;
|
||||
}
|
||||
return Cause.pretty(cause);
|
||||
};
|
||||
|
||||
|
||||
@@ -85,6 +85,22 @@ export class ProviderAdapterProcessError extends Schema.TaggedErrorClass<Provide
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ProviderWorkspaceMissingError - The session's working directory no longer
|
||||
* exists on disk, so no provider process can start in it.
|
||||
*/
|
||||
export class ProviderWorkspaceMissingError extends Schema.TaggedErrorClass<ProviderWorkspaceMissingError>()(
|
||||
"ProviderWorkspaceMissingError",
|
||||
{
|
||||
threadId: Schema.String,
|
||||
cwd: Schema.String,
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return `This thread's workspace folder no longer exists or is not a directory: ${this.cwd}. Restore the folder at this path before retrying.`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ProviderValidationError - Invalid provider API input.
|
||||
*/
|
||||
@@ -197,6 +213,7 @@ export type ProviderAdapterError =
|
||||
export type ProviderServiceError =
|
||||
| ProviderValidationError
|
||||
| ProviderUnsupportedError
|
||||
| ProviderWorkspaceMissingError
|
||||
| ProviderInstanceNotFoundError
|
||||
| ProviderSessionNotFoundError
|
||||
| ProviderSessionDirectoryPersistenceError
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
} from "@t3tools/shared/assistantCitations";
|
||||
import { createModelSelection } from "@t3tools/shared/model";
|
||||
import { it, assert, describe, vi } from "@effect/vitest";
|
||||
import { afterAll } from "vite-plus/test";
|
||||
|
||||
import * as Cause from "effect/Cause";
|
||||
import * as Deferred from "effect/Deferred";
|
||||
@@ -54,6 +55,7 @@ import {
|
||||
ProviderAdapterSessionNotFoundError,
|
||||
ProviderUnsupportedError,
|
||||
ProviderValidationError,
|
||||
ProviderWorkspaceMissingError,
|
||||
type ProviderAdapterError,
|
||||
} from "../Errors.ts";
|
||||
import type { ProviderAdapterShape } from "../Services/ProviderAdapter.ts";
|
||||
@@ -79,6 +81,16 @@ const serverConfigTestLayer = ServerConfig.layerTest(process.cwd(), process.cwd(
|
||||
Layer.provide(NodeServices.layer),
|
||||
);
|
||||
|
||||
// startSession verifies the workspace folder exists before dispatching to an
|
||||
// adapter, so session cwd fixtures must be real directories.
|
||||
const fixtureCwdRoot = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "provider-service-test-"));
|
||||
afterAll(() => NodeFS.rmSync(fixtureCwdRoot, { recursive: true, force: true }));
|
||||
function fixtureCwd(name: string): string {
|
||||
const dir = NodePath.join(fixtureCwdRoot, name);
|
||||
NodeFS.mkdirSync(dir, { recursive: true });
|
||||
return dir;
|
||||
}
|
||||
|
||||
const asRequestId = (value: string): ApprovalRequestId => ApprovalRequestId.make(value);
|
||||
const asEventId = (value: string): EventId => EventId.make(value);
|
||||
const asThreadId = (value: string): ThreadId => ThreadId.make(value);
|
||||
@@ -425,6 +437,7 @@ function makeProviderServiceLayer(
|
||||
const layer = it.layer(
|
||||
Layer.mergeAll(
|
||||
makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(providerAdapterLayer),
|
||||
Layer.provide(directoryLayer),
|
||||
Layer.provide(defaultServerSettingsLayer),
|
||||
@@ -477,6 +490,7 @@ for (const [enabled, completed] of [
|
||||
const scope = yield* Scope.make();
|
||||
const services = yield* Layer.build(
|
||||
makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(
|
||||
Layer.succeed(ProviderSessionDirectory.ProviderSessionDirectory, directory),
|
||||
),
|
||||
@@ -596,6 +610,7 @@ it.effect("ProviderServiceLive catches stopAll failures during shutdown", () =>
|
||||
const directoryLayer = ProviderSessionDirectoryLive.pipe(Layer.provide(runtimeRepositoryLayer));
|
||||
const providerLayer = Layer.mergeAll(
|
||||
makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(providerAdapterLayer),
|
||||
Layer.provide(directoryLayer),
|
||||
Layer.provide(defaultServerSettingsLayer),
|
||||
@@ -638,6 +653,7 @@ it.effect("ProviderServiceLive flushes deferred completions during shutdown", ()
|
||||
const directoryLayer = ProviderSessionDirectoryLive.pipe(Layer.provide(runtimeRepositoryLayer));
|
||||
const providerLayer = Layer.mergeAll(
|
||||
makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(providerAdapterLayer),
|
||||
Layer.provide(directoryLayer),
|
||||
Layer.provide(defaultServerSettingsLayer),
|
||||
@@ -774,6 +790,7 @@ it.effect("ProviderServiceLive rejects new sessions for disabled providers", ()
|
||||
);
|
||||
const directoryLayer = ProviderSessionDirectoryLive.pipe(Layer.provide(runtimeRepositoryLayer));
|
||||
const providerLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(providerAdapterLayer),
|
||||
Layer.provide(directoryLayer),
|
||||
Layer.provide(defaultServerSettingsLayer),
|
||||
@@ -857,6 +874,7 @@ it.effect(
|
||||
Layer.provide(runtimeRepositoryLayer),
|
||||
);
|
||||
const providerLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(providerAdapterLayer),
|
||||
Layer.provide(directoryLayer),
|
||||
Layer.provide(serverSettingsLayer),
|
||||
@@ -926,6 +944,7 @@ it.effect("ProviderServiceLive rejects new sessions for disabled custom instance
|
||||
);
|
||||
const directoryLayer = ProviderSessionDirectoryLive.pipe(Layer.provide(runtimeRepositoryLayer));
|
||||
const providerLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(providerAdapterLayer),
|
||||
Layer.provide(directoryLayer),
|
||||
Layer.provide(defaultServerSettingsLayer),
|
||||
@@ -1044,7 +1063,7 @@ unsupportedRollback.layer("ProviderServiceLive unsupported rewind", (it) => {
|
||||
yield* provider.startSession(threadId, {
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId,
|
||||
cwd: "/tmp/project",
|
||||
cwd: fixtureCwd("project"),
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
if (!active) {
|
||||
@@ -1098,6 +1117,7 @@ it.effect(
|
||||
Layer.provide(runtimeRepositoryLayer),
|
||||
);
|
||||
const providerLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, registry)),
|
||||
Layer.provide(directoryLayer),
|
||||
Layer.provide(defaultServerSettingsLayer),
|
||||
@@ -1218,6 +1238,7 @@ it.effect("ProviderServiceLive keeps persisted resumable sessions on startup", (
|
||||
}).pipe(Effect.provide(directoryLayer));
|
||||
|
||||
const providerLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, registry)),
|
||||
Layer.provide(directoryLayer),
|
||||
Layer.provide(defaultServerSettingsLayer),
|
||||
@@ -1283,6 +1304,7 @@ it.effect(
|
||||
Layer.provide(runtimeRepositoryLayer),
|
||||
);
|
||||
const firstProviderLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(
|
||||
Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, firstRegistry),
|
||||
),
|
||||
@@ -1310,7 +1332,7 @@ it.effect(
|
||||
const session = yield* provider.startSession(threadId, {
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
providerInstanceId: codexInstanceId,
|
||||
cwd: "/tmp/project",
|
||||
cwd: fixtureCwd("project"),
|
||||
runtimeMode: "full-access",
|
||||
threadId,
|
||||
});
|
||||
@@ -1343,6 +1365,7 @@ it.effect(
|
||||
Layer.provide(runtimeRepositoryLayer),
|
||||
);
|
||||
const secondProviderLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(
|
||||
Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, secondRegistry),
|
||||
),
|
||||
@@ -1380,7 +1403,7 @@ it.effect(
|
||||
threadId?: string;
|
||||
};
|
||||
assert.equal(startPayload.provider, "codex");
|
||||
assert.equal(startPayload.cwd, "/tmp/project");
|
||||
assert.equal(startPayload.cwd, fixtureCwd("project"));
|
||||
assert.deepEqual(startPayload.resumeCursor, updatedResumeCursor);
|
||||
assert.equal(startPayload.threadId, startedSession.threadId);
|
||||
}
|
||||
@@ -1394,6 +1417,61 @@ it.effect(
|
||||
);
|
||||
|
||||
routing.layer("ProviderServiceLive routing", (it) => {
|
||||
it.effect.each([CODEX_DRIVER, CLAUDE_AGENT_DRIVER, CURSOR_DRIVER])(
|
||||
"rejects missing, file, and saved workspace paths before starting %s",
|
||||
(driver) =>
|
||||
Effect.gen(function* () {
|
||||
const provider = yield* ProviderService.ProviderService;
|
||||
const adapter =
|
||||
driver === CODEX_DRIVER
|
||||
? routing.codex
|
||||
: driver === CLAUDE_AGENT_DRIVER
|
||||
? routing.claude
|
||||
: routing.cursor;
|
||||
const cwd = fixtureCwd(`missing-workspace-${driver}`);
|
||||
const movedCwd = `${cwd}-moved`;
|
||||
const threadId = asThreadId(`missing-workspace-${driver}`);
|
||||
const input = {
|
||||
provider: driver,
|
||||
providerInstanceId: ProviderInstanceId.make(driver),
|
||||
threadId,
|
||||
runtimeMode: "full-access" as const,
|
||||
cwd,
|
||||
};
|
||||
|
||||
yield* provider.startSession(threadId, input);
|
||||
yield* provider.stopSession({ threadId });
|
||||
adapter.startSession.mockClear();
|
||||
NodeFS.renameSync(cwd, movedCwd);
|
||||
|
||||
const failure = yield* provider.startSession(threadId, input).pipe(Effect.flip);
|
||||
assert.instanceOf(failure, ProviderWorkspaceMissingError);
|
||||
assert.include(failure.message, cwd);
|
||||
assert.equal(adapter.startSession.mock.calls.length, 0);
|
||||
|
||||
const { cwd: _cwd, ...savedInput } = input;
|
||||
const savedFailure = yield* provider.startSession(threadId, savedInput).pipe(Effect.flip);
|
||||
assert.instanceOf(savedFailure, ProviderWorkspaceMissingError);
|
||||
assert.include(savedFailure.message, cwd);
|
||||
assert.equal(adapter.startSession.mock.calls.length, 0);
|
||||
|
||||
NodeFS.writeFileSync(cwd, "not a directory");
|
||||
const fileFailure = yield* provider.startSession(threadId, input).pipe(Effect.flip);
|
||||
assert.instanceOf(fileFailure, ProviderWorkspaceMissingError);
|
||||
assert.include(fileFailure.message, cwd);
|
||||
assert.equal(adapter.startSession.mock.calls.length, 0);
|
||||
|
||||
NodeFS.unlinkSync(cwd);
|
||||
NodeFS.renameSync(movedCwd, cwd);
|
||||
const restored = yield* provider.startSession(threadId, savedInput);
|
||||
assert.equal(restored.cwd, cwd);
|
||||
assert.equal(adapter.startSession.mock.calls.length, 1);
|
||||
yield* provider.stopSession({ threadId });
|
||||
adapter.startSession.mockClear();
|
||||
adapter.stopSession.mockClear();
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("allows promptless continuation only for capable providers", () =>
|
||||
Effect.gen(function* () {
|
||||
const provider = yield* ProviderService.ProviderService;
|
||||
@@ -1452,7 +1530,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId: asThreadId("thread-1"),
|
||||
cwd: "/tmp/project",
|
||||
cwd: fixtureCwd("project"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
assert.equal(session.provider, "codex");
|
||||
@@ -1522,7 +1600,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
threadId?: string;
|
||||
};
|
||||
assert.equal(startPayload.provider, "codex");
|
||||
assert.equal(startPayload.cwd, "/tmp/project");
|
||||
assert.equal(startPayload.cwd, fixtureCwd("project"));
|
||||
assert.deepEqual(startPayload.resumeCursor, session.resumeCursor);
|
||||
assert.equal(startPayload.threadId, session.threadId);
|
||||
}
|
||||
@@ -1799,7 +1877,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: CODEX_DRIVER,
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId,
|
||||
cwd: "/tmp/feedback-project",
|
||||
cwd: fixtureCwd("feedback-project"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
yield* routing.codex.stopSession(threadId);
|
||||
@@ -1862,7 +1940,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId: asThreadId("thread-attach"),
|
||||
cwd: "/tmp/project",
|
||||
cwd: fixtureCwd("project"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
@@ -1937,7 +2015,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId: asThreadId("thread-1"),
|
||||
cwd: "/tmp/project",
|
||||
cwd: fixtureCwd("project"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
yield* routing.codex.stopSession(initial.threadId);
|
||||
@@ -1963,7 +2041,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
threadId?: string;
|
||||
};
|
||||
assert.equal(startPayload.provider, "codex");
|
||||
assert.equal(startPayload.cwd, "/tmp/project");
|
||||
assert.equal(startPayload.cwd, fixtureCwd("project"));
|
||||
assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
|
||||
assert.equal(startPayload.threadId, initial.threadId);
|
||||
}
|
||||
@@ -1982,7 +2060,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId: asThreadId("thread-reap-preserve"),
|
||||
cwd: "/tmp/project-reap-preserve",
|
||||
cwd: fixtureCwd("project-reap-preserve"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
@@ -2017,7 +2095,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
threadId?: string;
|
||||
};
|
||||
assert.equal(startPayload.provider, "codex");
|
||||
assert.equal(startPayload.cwd, "/tmp/project-reap-preserve");
|
||||
assert.equal(startPayload.cwd, fixtureCwd("project-reap-preserve"));
|
||||
assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
|
||||
assert.equal(startPayload.threadId, initial.threadId);
|
||||
}
|
||||
@@ -2033,7 +2111,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
providerInstanceId: claudeAgentInstanceId,
|
||||
threadId: asThreadId("thread-claude"),
|
||||
cwd: "/tmp/project-claude",
|
||||
cwd: fixtureCwd("project-claude"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
@@ -2049,7 +2127,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
};
|
||||
assert.equal(startPayload.provider, "claudeAgent");
|
||||
assert.equal(startPayload.providerInstanceId, claudeAgentInstanceId);
|
||||
assert.equal(startPayload.cwd, "/tmp/project-claude");
|
||||
assert.equal(startPayload.cwd, fixtureCwd("project-claude"));
|
||||
}
|
||||
}),
|
||||
);
|
||||
@@ -2064,7 +2142,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId,
|
||||
cwd: "/tmp/project-binding-mismatch",
|
||||
cwd: fixtureCwd("project-binding-mismatch"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
yield* directory.upsert({
|
||||
@@ -2094,7 +2172,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId,
|
||||
cwd: "/tmp/project-provider-replacement",
|
||||
cwd: fixtureCwd("project-provider-replacement"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
@@ -2105,7 +2183,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
providerInstanceId: claudeAgentInstanceId,
|
||||
threadId,
|
||||
cwd: "/tmp/project-provider-replacement",
|
||||
cwd: fixtureCwd("project-provider-replacement"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
@@ -2132,7 +2210,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId: asThreadId("thread-1"),
|
||||
cwd: "/tmp/project-send-turn",
|
||||
cwd: fixtureCwd("project-send-turn"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
@@ -2157,7 +2235,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
threadId?: string;
|
||||
};
|
||||
assert.equal(startPayload.provider, "codex");
|
||||
assert.equal(startPayload.cwd, "/tmp/project-send-turn");
|
||||
assert.equal(startPayload.cwd, fixtureCwd("project-send-turn"));
|
||||
assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
|
||||
assert.equal(startPayload.threadId, initial.threadId);
|
||||
}
|
||||
@@ -2173,7 +2251,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
providerInstanceId: claudeAgentInstanceId,
|
||||
threadId: asThreadId("thread-claude-send-turn"),
|
||||
cwd: "/tmp/project-claude-send-turn",
|
||||
cwd: fixtureCwd("project-claude-send-turn"),
|
||||
modelSelection: createModelSelection(
|
||||
ProviderInstanceId.make("claudeAgent"),
|
||||
"claude-opus-4-6",
|
||||
@@ -2204,7 +2282,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
threadId?: string;
|
||||
};
|
||||
assert.equal(startPayload.provider, "claudeAgent");
|
||||
assert.equal(startPayload.cwd, "/tmp/project-claude-send-turn");
|
||||
assert.equal(startPayload.cwd, fixtureCwd("project-claude-send-turn"));
|
||||
assert.deepEqual(
|
||||
startPayload.modelSelection,
|
||||
createModelSelection(ProviderInstanceId.make("claudeAgent"), "claude-opus-4-6", [
|
||||
@@ -2368,6 +2446,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
Layer.provide(runtimeRepositoryLayer),
|
||||
);
|
||||
const firstProviderLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(
|
||||
Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, firstRegistry),
|
||||
),
|
||||
@@ -2389,7 +2468,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
providerInstanceId: claudeAgentInstanceId,
|
||||
threadId: asThreadId("thread-claude-start"),
|
||||
cwd: "/tmp/project-claude-start",
|
||||
cwd: fixtureCwd("project-claude-start"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
}).pipe(Effect.provide(firstProviderLayer));
|
||||
@@ -2407,6 +2486,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
Layer.provide(runtimeRepositoryLayer),
|
||||
);
|
||||
const secondProviderLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(
|
||||
Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, secondRegistry),
|
||||
),
|
||||
@@ -2430,7 +2510,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
providerInstanceId: claudeAgentInstanceId,
|
||||
threadId: initial.threadId,
|
||||
cwd: "/tmp/project-claude-start",
|
||||
cwd: fixtureCwd("project-claude-start"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
}).pipe(Effect.provide(secondProviderLayer));
|
||||
@@ -2446,7 +2526,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
threadId?: string;
|
||||
};
|
||||
assert.equal(startPayload.provider, "claudeAgent");
|
||||
assert.equal(startPayload.cwd, "/tmp/project-claude-start");
|
||||
assert.equal(startPayload.cwd, fixtureCwd("project-claude-start"));
|
||||
assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
|
||||
assert.equal(startPayload.threadId, initial.threadId);
|
||||
}
|
||||
@@ -2476,6 +2556,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
Layer.provide(runtimeRepositoryLayer),
|
||||
);
|
||||
const firstProviderLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(
|
||||
Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, firstRegistry),
|
||||
),
|
||||
@@ -2497,7 +2578,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
providerInstanceId: claudeAgentInstanceId,
|
||||
threadId: asThreadId("thread-claude-cwd"),
|
||||
cwd: "/tmp/project-claude-cwd",
|
||||
cwd: fixtureCwd("project-claude-cwd"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
}).pipe(Effect.provide(firstProviderLayer));
|
||||
@@ -2510,6 +2591,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
Layer.provide(runtimeRepositoryLayer),
|
||||
);
|
||||
const secondProviderLayer = makeProviderServiceLive().pipe(
|
||||
Layer.provide(NodeServices.layer),
|
||||
Layer.provide(
|
||||
Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistry, secondRegistry),
|
||||
),
|
||||
@@ -2548,7 +2630,7 @@ routing.layer("ProviderServiceLive routing", (it) => {
|
||||
threadId?: string;
|
||||
};
|
||||
assert.equal(startPayload.provider, "claudeAgent");
|
||||
assert.equal(startPayload.cwd, "/tmp/project-claude-cwd");
|
||||
assert.equal(startPayload.cwd, fixtureCwd("project-claude-cwd"));
|
||||
assert.deepEqual(startPayload.resumeCursor, initial.resumeCursor);
|
||||
assert.equal(startPayload.threadId, initial.threadId);
|
||||
}
|
||||
@@ -2742,7 +2824,7 @@ fanout.layer("ProviderServiceLive fanout", (it) => {
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
providerInstanceId: claudeAgentInstanceId,
|
||||
threadId: asThreadId("thread-metrics"),
|
||||
cwd: "/tmp/project",
|
||||
cwd: fixtureCwd("project"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
@@ -2820,7 +2902,7 @@ fanout.layer("ProviderServiceLive fanout", (it) => {
|
||||
provider: ProviderDriverKind.make("claudeAgent"),
|
||||
providerInstanceId: claudeAgentInstanceId,
|
||||
threadId: asThreadId("thread-send-metrics"),
|
||||
cwd: "/tmp/project-send-metrics",
|
||||
cwd: fixtureCwd("project-send-metrics"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
@@ -4155,7 +4237,7 @@ validation.layer("ProviderServiceLive validation", (it) => {
|
||||
provider: ProviderDriverKind.make("codex"),
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId: asThreadId("thread-missing"),
|
||||
cwd: "/tmp/project",
|
||||
cwd: fixtureCwd("project"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
|
||||
@@ -4204,7 +4286,7 @@ boundedListing.layer("ProviderServiceLive session listing", (it) => {
|
||||
provider: CODEX_DRIVER,
|
||||
providerInstanceId: codexInstanceId,
|
||||
threadId: activeSessionThreadId,
|
||||
cwd: "/tmp/project-active-session",
|
||||
cwd: fixtureCwd("project-active-session"),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
listThreadIds.mockClear();
|
||||
|
||||
@@ -35,6 +35,7 @@ import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Deferred from "effect/Deferred";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
import * as PubSub from "effect/PubSub";
|
||||
@@ -55,8 +56,12 @@ import {
|
||||
providerTurnMetricAttributes,
|
||||
withMetrics,
|
||||
} from "../../observability/Metrics.ts";
|
||||
import { ProviderAdapterRequestError } from "../Errors.ts";
|
||||
import { type ProviderAdapterError, ProviderValidationError } from "../Errors.ts";
|
||||
import {
|
||||
ProviderAdapterRequestError,
|
||||
type ProviderAdapterError,
|
||||
ProviderValidationError,
|
||||
ProviderWorkspaceMissingError,
|
||||
} from "../Errors.ts";
|
||||
import type { ProviderAdapterShape } from "../Services/ProviderAdapter.ts";
|
||||
import * as ProviderAdapterRegistry from "../Services/ProviderAdapterRegistry.ts";
|
||||
import * as ProviderService from "../Services/ProviderService.ts";
|
||||
@@ -322,6 +327,7 @@ const makeProviderService = Effect.fn("makeProviderService")(function* (
|
||||
options?.issueMcpCredential ?? McpSessionRegistry.issueActiveMcpCredential;
|
||||
const revokeMcpCredential =
|
||||
options?.revokeMcpCredential ?? McpSessionRegistry.revokeActiveMcpThread;
|
||||
const fileSystem = yield* FileSystem.FileSystem;
|
||||
const runtimeEventPubSub = yield* PubSub.unbounded<ProviderRuntimeEvent>();
|
||||
const pendingCompactions = new Map<ThreadId, PendingCompaction>();
|
||||
const timedOutNativeCompactions = new Set<ThreadId>();
|
||||
@@ -1235,6 +1241,20 @@ const makeProviderService = Effect.fn("makeProviderService")(function* (
|
||||
: "none",
|
||||
"provider.cwd.effective": effectiveCwd ?? "",
|
||||
});
|
||||
if (effectiveCwd !== undefined) {
|
||||
// Fail fast with an actionable error when the workspace folder is
|
||||
// gone (e.g. moved, deleted, or replaced by a plain file).
|
||||
// Otherwise every adapter surfaces this as a misleading "failed to
|
||||
// spawn <binary>" process error. Stat failures other than "missing"
|
||||
// fall through to the adapter.
|
||||
const workspaceIsDirectory = yield* fileSystem.stat(effectiveCwd).pipe(
|
||||
Effect.map((workspaceStat) => workspaceStat.type === "Directory"),
|
||||
Effect.catch((statError) => Effect.succeed(statError.reason._tag !== "NotFound")),
|
||||
);
|
||||
if (!workspaceIsDirectory) {
|
||||
return yield* new ProviderWorkspaceMissingError({ threadId, cwd: effectiveCwd });
|
||||
}
|
||||
}
|
||||
const adapter = yield* registry.getByInstance(resolvedInstanceId);
|
||||
yield* clearTurnAnalyticsSession(resolvedInstanceId, threadId);
|
||||
yield* prepareMcpSession(threadId, resolvedInstanceId);
|
||||
|
||||
Reference in new issue
Block a user