Skip to content

Commit 7370b92

Browse files
fix(server): run_scheduled_task_now says why a run was refused (pingdotgg#25647)
Co-authored-by: maria-rcks <[email protected]>
1 parent 9ee7da6 commit 7370b92

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
ProviderDriverKind,
1313
ProviderInstanceId,
1414
RunId,
15+
ScheduledTaskError,
16+
ScheduledTask,
1517
RuntimeRequestId,
1618
ThreadId,
1719
TurnItemId,
@@ -717,6 +719,66 @@ it.effect("a caller cannot rewrite a scheduled task that runs above its own mode
717719
),
718720
);
719721

722+
it.effect.each([
723+
{
724+
scenario: "explains why a webhook task cannot run manually",
725+
tasks: [
726+
{
727+
...Schema.decodeSync(ScheduledTask)(scheduledTask("task-webhook", "full-access")),
728+
schedule: { type: "webhook" as const, signature: null },
729+
},
730+
],
731+
error: new ScheduledTaskError({
732+
message: "Webhook tasks run when their URL receives a request.",
733+
cause: new Error("private-webhook-cause"),
734+
}),
735+
code: "orchestration_error",
736+
message: "Webhook tasks run when their URL receives a request.",
737+
},
738+
{
739+
scenario: "reports a missing task before trying to run it",
740+
tasks: [],
741+
error: new ScheduledTaskError({ message: "must not run a missing task" }),
742+
code: "invalid_request",
743+
message: "The scheduled task was not found.",
744+
},
745+
])("run_scheduled_task_now $scenario", ({ tasks, error, code, message }) =>
746+
Effect.gen(function* () {
747+
const server = yield* McpServer.McpServer;
748+
const result = yield* server
749+
.callTool({ name: "run_scheduled_task_now", arguments: { taskId: "task-webhook" } })
750+
.pipe(
751+
Effect.provideService(
752+
McpInvocationContext.McpInvocationContext,
753+
clientScope("full-access"),
754+
),
755+
Effect.provideService(McpSchema.McpServerClient, client),
756+
);
757+
expect(result.isError).toBe(true);
758+
expect(result.structuredContent).toBeUndefined();
759+
expect(declaredFailure(result)).toEqual({ _tag: "OrchestratorMcpFailure", code, message });
760+
expect(JSON.stringify(result)).not.toContain("private-");
761+
}).pipe(
762+
Effect.provide(
763+
McpHttpServer.layerThreadToolkit.pipe(
764+
Layer.provideMerge(McpServer.McpServer.layer),
765+
Layer.provide(NodeCrypto.layer),
766+
Layer.provide(Layer.mock(ThreadManagement.ThreadManagementService)({})),
767+
Layer.provide(Layer.mock(ThreadSearch.ThreadSearch)({})),
768+
Layer.provide(Layer.mock(PeerForwarding.PeerForwarding)({})),
769+
Layer.provide(Layer.mock(PeerLinkRequests.PeerLinkRequests)({})),
770+
Layer.provide(Layer.mock(PeerLinks.PeerLinks)({})),
771+
Layer.provide(
772+
Layer.mock(ScheduledTaskService.ScheduledTaskService)({
773+
list: () => Effect.succeed({ tasks }),
774+
runNow: () => Effect.fail(error),
775+
}),
776+
),
777+
),
778+
),
779+
),
780+
);
781+
720782
function scheduledTask(id: string, runtimeMode: "auto" | "full-access"): never {
721783
return {
722784
id,

‎apps/server/src/mcp/toolkits/thread/handlers.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
102102
});
103103
const { task, threadId } = yield* scheduler
104104
.runNow({ id: input.taskId })
105-
.pipe(Effect.mapError(unavailable));
105+
.pipe(
106+
Effect.mapError(
107+
(error) =>
108+
new OrchestratorMcpFailure({ code: "orchestration_error", message: error.message }),
109+
),
110+
);
106111
const scope = yield* McpInvocationContext.McpInvocationContext;
107112
return {
108113
taskId: task.id,

0 commit comments

Comments
 (0)