Skip to content

Commit f8d2a8d

Browse files
fix(server): a stale response's dispatch error keeps the not-pending cause
commitCommand wrapped EventSinkRuntimeRequestNotPendingError as its message string, dropping the underlying error. Keep the tagged error as the cause. The WS path already reads a nested Error's message; the MCP dispatchFailure only exposed string causes, so it now also exposes this error's message, which is built from the request id and status alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7557986 commit f8d2a8d

3 files changed

Lines changed: 29 additions & 11 deletions

File tree

‎apps/server/src/mcp/threadAccess.ts‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import {
1010
} from "@t3tools/contracts";
1111
import * as Crypto from "effect/Crypto";
1212
import * as Effect from "effect/Effect";
13+
import * as Schema from "effect/Schema";
1314

15+
import { EventSinkRuntimeRequestNotPendingError } from "../orchestration-v2/EventSink.ts";
1416
import type { OrchestratorV2Error } from "../orchestration-v2/Orchestrator.ts";
1517
import * as ThreadManagement from "../orchestration-v2/ThreadManagementService.ts";
1618
import * as OrchestrationMcp from "./OrchestratorMcpService.ts";
@@ -22,20 +24,25 @@ export const unavailable = () =>
2224
message: "The operation could not be completed.",
2325
});
2426

27+
// Its message is built only from the request id and status, so it is safe to expose.
28+
const isRuntimeRequestNotPending = Schema.is(EventSinkRuntimeRequestNotPendingError);
29+
2530
export const dispatchFailure = (
2631
error: OrchestratorV2Error | ThreadManagement.ThreadManagementProviderInstanceDisabledError,
2732
) =>
2833
error._tag === "ThreadManagementProviderInstanceDisabledError"
2934
? new OrchestratorMcpFailure({ code: "invalid_request", message: error.message })
30-
: (error._tag === "OrchestratorDispatchError" ||
31-
error._tag === "OrchestratorCommandRejectedError") &&
32-
typeof error.cause === "string" &&
33-
error.cause.length > 0
34-
? new OrchestratorMcpFailure({
35-
code: "orchestration_error",
36-
message: Array.from(error.cause).slice(0, 1000).join(""),
37-
})
38-
: unavailable();
35+
: error._tag === "OrchestratorDispatchError" && isRuntimeRequestNotPending(error.cause)
36+
? new OrchestratorMcpFailure({ code: "orchestration_error", message: error.cause.message })
37+
: (error._tag === "OrchestratorDispatchError" ||
38+
error._tag === "OrchestratorCommandRejectedError") &&
39+
typeof error.cause === "string" &&
40+
error.cause.length > 0
41+
? new OrchestratorMcpFailure({
42+
code: "orchestration_error",
43+
message: Array.from(error.cause).slice(0, 1000).join(""),
44+
})
45+
: unavailable();
3946

4047
export interface CallerLimits {
4148
readonly runtimeMode: RuntimeMode;

‎apps/server/src/mcp/toolkits/core.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
OrchestratorDispatchError,
3232
OrchestratorProjectionError,
3333
} from "../../orchestration-v2/Orchestrator.ts";
34+
import { EventSinkRuntimeRequestNotPendingError } from "../../orchestration-v2/EventSink.ts";
3435

3536
import * as ServerSecretStore from "../../auth/ServerSecretStore.ts";
3637
import * as ServerConfig from "../../config.ts";
@@ -216,6 +217,17 @@ it("bounds public command rejections and redacts internal dispatch causes", () =
216217
new OrchestratorCommandRejectedError({ ...command, cause: "Run is not queued." }),
217218
).message,
218219
).toBe("Run is not queued.");
220+
expect(
221+
dispatchFailure(
222+
new OrchestratorDispatchError({
223+
...command,
224+
cause: new EventSinkRuntimeRequestNotPendingError({
225+
requestId: RuntimeRequestId.make("mcp-core-request"),
226+
status: "cancelled",
227+
}),
228+
}),
229+
).message,
230+
).toBe("Runtime request mcp-core-request is cancelled.");
219231
for (const cause of [
220232
undefined,
221233
"",

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11877,8 +11877,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1187711877
new OrchestratorDispatchError({
1187811878
commandId: command.commandId,
1187911879
commandType: command.type,
11880-
cause:
11881-
cause._tag === "EventSinkRuntimeRequestNotPendingError" ? cause.message : cause,
11880+
cause,
1188211881
}),
1188311882
),
1188411883
);

0 commit comments

Comments
 (0)