Skip to content

Commit bf1074b

Browse files
refactor(server): stopped MCP App sessions fail with their own adapter error
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3341c88 commit bf1074b

5 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎apps/server/src/mcpApps/McpAppRequests.test.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,8 @@ describe("McpAppRequests", () => {
205205
...mcpApps,
206206
readResource: () =>
207207
Effect.fail(
208-
new ProviderAdapter.ProviderAdapterProtocolError({
208+
new ProviderAdapter.ProviderAdapterSessionStoppedError({
209209
driver: ProviderDriverKind.make("claudeAgent"),
210-
detail: "stopped",
211-
reason: "session_stopped",
212210
}),
213211
),
214212
},

‎apps/server/src/mcpApps/McpAppRequests.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ const make = Effect.gen(function* () {
6767
const adapterFailure = (threadId: ThreadId) => (cause: ProviderAdapter.ProviderAdapterV2Error) =>
6868
fail(
6969
threadId,
70-
cause._tag === "ProviderAdapterProtocolError" && cause.reason === "session_stopped"
71-
? "session-stopped"
72-
: "request-failed",
70+
cause._tag === "ProviderAdapterSessionStoppedError" ? "session-stopped" : "request-failed",
7371
cause,
7472
);
7573

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7381,10 +7381,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
73817381
liveQuery.stopping ||
73827382
liveQuery.nativeThreadId !== providerThread.nativeThreadRef?.nativeId
73837383
) {
7384-
return yield* new ProviderAdapter.ProviderAdapterProtocolError({
7384+
return yield* new ProviderAdapter.ProviderAdapterSessionStoppedError({
73857385
driver: CLAUDE_PROVIDER,
7386-
detail: "No running Claude process owns this thread.",
7387-
reason: "session_stopped",
73887386
});
73897387
}
73907388
if (!claudeSupportsMcpApps(liveQuery.capabilities)) {

‎packages/provider-core/src/server/ProviderAdapter.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ export class ProviderAdapterEventStreamError extends Schema.TaggedError<Provider
406406
const ProviderAdapterFailureReason = Schema.Literals([
407407
"previous_turn_active",
408408
"attachment_unreadable",
409-
"session_stopped",
410409
]);
411410
export type ProviderAdapterFailureReason = typeof ProviderAdapterFailureReason.Type;
412411

@@ -425,6 +424,15 @@ export class ProviderAdapterProtocolError extends Schema.TaggedError<ProviderAda
425424
}
426425
}
427426

427+
export class ProviderAdapterSessionStoppedError extends Schema.TaggedError<ProviderAdapterSessionStoppedError>()(
428+
"ProviderAdapterSessionStoppedError",
429+
{ driver: ProviderDriverKind },
430+
) {
431+
override get message(): string {
432+
return `No running ${this.driver} session owns this thread.`;
433+
}
434+
}
435+
428436
export const ProviderAdapterV2Error = Schema.Union([
429437
ProviderAdapterCapabilitiesError,
430438
ProviderAdapterOpenSessionError,
@@ -443,6 +451,7 @@ export const ProviderAdapterV2Error = Schema.Union([
443451
ProviderAdapterRuntimeRequestResponseError,
444452
ProviderAdapterEventStreamError,
445453
ProviderAdapterProtocolError,
454+
ProviderAdapterSessionStoppedError,
446455
]);
447456
export type ProviderAdapterV2Error = typeof ProviderAdapterV2Error.Type;
448457

‎packages/provider-core/src/server/failure.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const CODEX_GOAL_VALIDATION_MESSAGE =
6868
const PROVIDER_FAILURE_REASONS: Record<ProviderAdapterFailureReason, string> = {
6969
previous_turn_active: "the previous turn is still running",
7070
attachment_unreadable: "an attachment could not be read",
71-
session_stopped: "the provider session has stopped",
7271
};
7372

7473
/**

0 commit comments

Comments
 (0)