@devries-cameron20 / t3code-1 / commits / 7370b92c3e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

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

Co-authored-by: maria-rcks <maria@kuuro.net>

Fuksss committed Nov 1, 2026 at 03:32 UTC 7370b92c3ec1979bffca166796bc75025cba8459
2 files changed +68 -1
apps/server/src/mcp/toolkits/core.test.ts
+62
@@ -12,6 +12,8 @@ import {
12 ProviderDriverKind,
13 ProviderInstanceId,
14 RunId,
15 + ScheduledTaskError,
16 + ScheduledTask,
17 RuntimeRequestId,
18 ThreadId,
19 TurnItemId,
@@ -717,6 +719,66 @@ it.effect("a caller cannot rewrite a scheduled task that runs above its own mode
719 ),
720 );
721
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 +
782 function scheduledTask(id: string, runtimeMode: "auto" | "full-access"): never {
783 return {
784 id,
apps/server/src/mcp/toolkits/thread/handlers.ts
+6 -1
@@ -102,7 +102,12 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
102 });
103 const { task, threadId } = yield* scheduler
104 .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 + );
111 const scope = yield* McpInvocationContext.McpInvocationContext;
112 return {
113 taskId: task.id,