Skip to content
TypeScript

fix(server): run_scheduled_task_now says why a run was refused (#25647)

Fuksss7370b92c3ec1
diff --git a/apps/server/src/mcp/toolkits/core.test.ts b/apps/server/src/mcp/toolkits/core.test.ts
index 2e2bb4e7c76..5774f0e4c4f 100644
--- a/apps/server/src/mcp/toolkits/core.test.ts
+++ b/apps/server/src/mcp/toolkits/core.test.ts
@@ -12,6 +12,8 @@ import {
ProviderDriverKind,
ProviderInstanceId,
RunId,
+ ScheduledTaskError,
+ ScheduledTask,
RuntimeRequestId,
ThreadId,
TurnItemId,
@@ -717,6 +719,66 @@ it.effect("a caller cannot rewrite a scheduled task that runs above its own mode
),
);
+it.effect.each([
+ {
+ scenario: "explains why a webhook task cannot run manually",
+ tasks: [
+ {
+ ...Schema.decodeSync(ScheduledTask)(scheduledTask("task-webhook", "full-access")),
+ schedule: { type: "webhook" as const, signature: null },
+ },
+ ],
+ error: new ScheduledTaskError({
+ message: "Webhook tasks run when their URL receives a request.",
+ cause: new Error("private-webhook-cause"),
+ }),
+ code: "orchestration_error",
+ message: "Webhook tasks run when their URL receives a request.",
+ },
+ {
+ scenario: "reports a missing task before trying to run it",
+ tasks: [],
+ error: new ScheduledTaskError({ message: "must not run a missing task" }),
+ code: "invalid_request",
+ message: "The scheduled task was not found.",
+ },
+])("run_scheduled_task_now $scenario", ({ tasks, error, code, message }) =>
+ Effect.gen(function* () {
+ const server = yield* McpServer.McpServer;
+ const result = yield* server
+ .callTool({ name: "run_scheduled_task_now", arguments: { taskId: "task-webhook" } })
+ .pipe(
+ Effect.provideService(
+ McpInvocationContext.McpInvocationContext,
+ clientScope("full-access"),
+ ),
+ Effect.provideService(McpSchema.McpServerClient, client),
+ );
+ expect(result.isError).toBe(true);
+ expect(result.structuredContent).toBeUndefined();
+ expect(declaredFailure(result)).toEqual({ _tag: "OrchestratorMcpFailure", code, message });
+ expect(JSON.stringify(result)).not.toContain("private-");
+ }).pipe(
+ Effect.provide(
+ McpHttpServer.layerThreadToolkit.pipe(
+ Layer.provideMerge(McpServer.McpServer.layer),
+ Layer.provide(NodeCrypto.layer),
+ Layer.provide(Layer.mock(ThreadManagement.ThreadManagementService)({})),
+ Layer.provide(Layer.mock(ThreadSearch.ThreadSearch)({})),
+ Layer.provide(Layer.mock(PeerForwarding.PeerForwarding)({})),
+ Layer.provide(Layer.mock(PeerLinkRequests.PeerLinkRequests)({})),
+ Layer.provide(Layer.mock(PeerLinks.PeerLinks)({})),
+ Layer.provide(
+ Layer.mock(ScheduledTaskService.ScheduledTaskService)({
+ list: () => Effect.succeed({ tasks }),
+ runNow: () => Effect.fail(error),
+ }),
+ ),
+ ),
+ ),
+ ),
+);
+
function scheduledTask(id: string, runtimeMode: "auto" | "full-access"): never {
return {
id,
diff --git a/apps/server/src/mcp/toolkits/thread/handlers.ts b/apps/server/src/mcp/toolkits/thread/handlers.ts
index b1d34c91be8..f9683124375 100644
--- a/apps/server/src/mcp/toolkits/thread/handlers.ts
+++ b/apps/server/src/mcp/toolkits/thread/handlers.ts
@@ -102,7 +102,12 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
});
const { task, threadId } = yield* scheduler
.runNow({ id: input.taskId })
- .pipe(Effect.mapError(unavailable));
+ .pipe(
+ Effect.mapError(
+ (error) =>
+ new OrchestratorMcpFailure({ code: "orchestration_error", message: error.message }),
+ ),
+ );
const scope = yield* McpInvocationContext.McpInvocationContext;
return {
taskId: task.id,