GeezerVison is showing github.com — feat(server): scheduled tasks can run on a webhook (#15085) · incognitojam/styal@7dfb86a
File treeExpand file treeCollapse file tree Open diff view settings mobile/src/features/settings
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -87,6 +87,7 @@ const DAYS = [ | 87 | 87 | ] as const; | 88 | 88 |
| 89 | 89 | function describeSchedule(task: ScheduledTask): string { | | 90 | + if (task.schedule.type === "webhook") return "On webhook"; | 90 | 91 | if (task.schedule.type === "interval") return formatScheduledTaskInterval(task.schedule.everyMs); | 91 | 92 | const days = task.schedule.weekdays?.length ? repeatLabel(task.schedule.weekdays) : "Every day"; | 92 | 93 | return `${days} at ${formatTime(task.schedule.timeOfDay)}`; | @@ -1024,6 +1025,8 @@ function EnvironmentTasks({ | 1024 | 1025 | <Pressable | 1025 | 1026 | accessibilityRole="button" | 1026 | 1027 | accessibilityLabel={`Edit ${task.title}`} | | 1028 | + // Webhook tasks are not editable here yet; saving would drop their URL. | | 1029 | + disabled={task.schedule.type === "webhook"} | 1027 | 1030 | onPress={() => { | 1028 | 1031 | onEdit(task); | 1029 | 1032 | }} | @@ -1048,7 +1051,7 @@ function EnvironmentTasks({ | 1048 | 1051 | </Pressable> | 1049 | 1052 | <ControlPillMenu | 1050 | 1053 | actions={[ | 1051 | | - { id: "edit", title: "Edit" }, | | 1054 | + ...(task.schedule.type === "webhook" ? [] : [{ id: "edit", title: "Edit" }]), | 1052 | 1055 | { id: "toggle", title: task.enabled ? "Pause" : "Resume" }, | 1053 | 1056 | { id: "run", title: "Run now" }, | 1054 | 1057 | { id: "delete", title: "Delete", attributes: { destructive: true } }, | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/settings/scheduledTaskDraft.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,8 @@ export const DEFAULT_SCHEDULE: ScheduleDraft = { | 51 | 51 | }; | 52 | 52 |
| 53 | 53 | export function scheduleDraftForTask(task: Pick<ScheduledTask, "schedule">): ScheduleDraft { | | 54 | + // Webhook tasks cannot be edited here yet; show them as the default schedule. | | 55 | + if (task.schedule.type === "webhook") return DEFAULT_SCHEDULE; | 54 | 56 | return task.schedule.type === "fixed_time" | 55 | 57 | ? { | 56 | 58 | ...DEFAULT_SCHEDULE, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/auth/RpcAuthorization.test.ts +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,6 +38,16 @@ describe("RPC authorization scopes", () => { | 38 | 38 | ); | 39 | 39 | }); | 40 | 40 |
| | 41 | + it("keeps webhook delivery logs, which hold request bodies, behind operate scope", () => { | | 42 | + for (const method of [ | | 43 | + WS_METHODS.scheduledTasksListWebhookDeliveries, | | 44 | + WS_METHODS.scheduledTasksGetWebhookDelivery, | | 45 | + WS_METHODS.scheduledTasksRotateWebhookToken, | | 46 | + ]) { | | 47 | + expect(requiredScopeForRpcMethod(method)).toBe(AuthOrchestrationOperateScope); | | 48 | + } | | 49 | + }); | | 50 | + | 41 | 51 | it("allows relay status reads without granting relay installation access", () => { | 42 | 52 | expect(requiredScopeForRpcMethod(WS_METHODS.cloudGetRelayClientStatus)).toBe( | 43 | 53 | AuthRelayReadScope, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/auth/RpcAuthorization.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -95,6 +95,10 @@ export const RPC_REQUIRED_SCOPES = { | 95 | 95 | [WS_METHODS.scheduledTasksSetEnabled]: AuthOrchestrationOperateScope, | 96 | 96 | [WS_METHODS.scheduledTasksDelete]: AuthOrchestrationOperateScope, | 97 | 97 | [WS_METHODS.scheduledTasksRunNow]: AuthOrchestrationOperateScope, | | 98 | + [WS_METHODS.scheduledTasksRotateWebhookToken]: AuthOrchestrationOperateScope, | | 99 | + // Delivery logs hold request bodies, so they need the same scope as the URL. | | 100 | + [WS_METHODS.scheduledTasksListWebhookDeliveries]: AuthOrchestrationOperateScope, | | 101 | + [WS_METHODS.scheduledTasksGetWebhookDelivery]: AuthOrchestrationOperateScope, | 98 | 102 | [WS_METHODS.cloudGetRelayClientStatus]: AuthRelayReadScope, | 99 | 103 | [WS_METHODS.cloudInstallRelayClient]: AuthRelayWriteScope, | 100 | 104 | [WS_METHODS.pullRequestsList]: AuthOrchestrationReadScope, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/http.ts +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -46,6 +46,7 @@ import { | 46 | 46 | failEnvironmentInternal, | 47 | 47 | } from "./auth/http.ts"; | 48 | 48 | import * as ServerEnvironment from "./environment/ServerEnvironment.ts"; | | 49 | +import { WEBHOOK_ROUTE_PREFIX } from "./scheduledTasks/ScheduledTaskService.ts"; | 49 | 50 | import { browserApiCorsAllowedHeaders, browserApiCorsAllowedMethods } from "./httpCors.ts"; | 50 | 51 |
| 51 | 52 | const OTLP_TRACES_PROXY_PATH = "/api/observability/v1/traces"; | @@ -381,9 +382,9 @@ const UNTRACED_REQUEST_PATHS: ReadonlySet<string> = new Set([OTLP_TRACES_PROXY_P | 381 | 382 | // ignored, as in routing. | 382 | 383 | const untracedRequestsLayer = Layer.succeed(HttpMiddleware.TracerDisabledWhen)((request) => { | 383 | 384 | const queryIndex = request.url.indexOf("?"); | 384 | | - return UNTRACED_REQUEST_PATHS.has( | 385 | | - queryIndex === -1 ? request.url : request.url.slice(0, queryIndex), | 386 | | - ); | | 385 | + const path = queryIndex === -1 ? request.url : request.url.slice(0, queryIndex); | | 386 | + // Webhook URLs carry their secret token in the path, so they never reach a trace. | | 387 | + return UNTRACED_REQUEST_PATHS.has(path) || path.startsWith(`${WEBHOOK_ROUTE_PREFIX}/`); | 387 | 388 | }); | 388 | 389 |
| 389 | 390 | export const withUntracedRequests = Layer.provide(untracedRequestsLayer); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/OrchestratorMcpService.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -212,6 +212,7 @@ function scheduledTaskSummary(task: ScheduledTask): OrchestratorMcpScheduledTask | 212 | 212 | schedule: task.schedule, | 213 | 213 | nextRunAt: task.nextRunAt, | 214 | 214 | lastRunStatus: task.lastRunStatus, | | 215 | + ...(task.webhook === undefined ? {} : { webhookUrl: task.webhook.url ?? task.webhook.path }), | 215 | 216 | }; | 216 | 217 | } | 217 | 218 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts +10-1Lines changed: 10 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -443,7 +443,8 @@ function scheduledTaskFromUpsert(input: ScheduledTaskUpsertInput): ScheduledTask | 443 | 443 | title: input.title, | 444 | 444 | prompt: input.prompt, | 445 | 445 | enabled: input.enabled, | 446 | | - schedule: input.schedule, | | 446 | + schedule: | | 447 | + input.schedule.type === "webhook" ? { type: "webhook", signature: null } : input.schedule, | 447 | 448 | projectId: input.projectId, | 448 | 449 | threadId: input.threadId ?? null, | 449 | 450 | workspaceStrategy: input.workspaceStrategy, | @@ -471,6 +472,10 @@ const unusedScheduledTaskStubLayer = Layer.succeed( | 471 | 472 | setEnabled: () => Effect.die("ScheduledTaskService.setEnabled is unused in this test"), | 472 | 473 | delete: () => Effect.die("ScheduledTaskService.delete is unused in this test"), | 473 | 474 | runNow: () => Effect.die("ScheduledTaskService.runNow is unused in this test"), | | 475 | + rotateWebhookToken: () => Effect.die("unused in this test"), | | 476 | + listWebhookDeliveries: () => Effect.die("unused in this test"), | | 477 | + getWebhookDelivery: () => Effect.die("unused in this test"), | | 478 | + triggerWebhook: () => Effect.die("unused in this test"), | 474 | 479 | }), | 475 | 480 | ); | 476 | 481 |
| @@ -628,6 +633,10 @@ describe("orchestrator MCP toolkit", () => { | 628 | 633 | all.filter((candidate) => candidate.id !== input.id), | 629 | 634 | ).pipe(Effect.as({ id: input.id })), | 630 | 635 | runNow: () => Effect.die("ScheduledTaskService.runNow is unused in this test"), | | 636 | + rotateWebhookToken: () => Effect.die("unused in this test"), | | 637 | + listWebhookDeliveries: () => Effect.die("unused in this test"), | | 638 | + getWebhookDelivery: () => Effect.die("unused in this test"), | | 639 | + triggerWebhook: () => Effect.die("unused in this test"), | 631 | 640 | }), | 632 | 641 | ); | 633 | 642 | const testLayer = Layer.merge( | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/toolkits/orchestrator/tools.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -97,7 +97,7 @@ const TaskCancelTool = Tool.make("task_cancel", { | 97 | 97 |
| 98 | 98 | export const ScheduleTaskTool = Tool.make("schedule_task", { | 99 | 99 | description: | 100 | | - "Create persistent recurring work in the app scheduler, which runs even when no turn is active. Pass schedule as a STRUCTURED OBJECT, never JSON text: {type:'interval', everyMs:3600000} means hourly; {type:'fixed_time', timeOfDay:'09:00', weekdays:[1,2,3,4,5]} means weekday mornings. Omit projectId for this thread's project. In this thread's project, runs post into THIS thread by default (bindToCurrentThread=true); use false only when the user wants a fresh top-level thread per run. Elsewhere each run launches a fresh thread. Provider, model, and runtime settings inherit from this thread, or from the project default when there is no calling thread. Report the returned schedule and nextRunAt after success.", | | 100 | + "Create persistent recurring work in the app scheduler, which runs even when no turn is active. Pass schedule as a STRUCTURED OBJECT, never JSON text: {type:'interval', everyMs:3600000} means hourly; {type:'fixed_time', timeOfDay:'09:00', weekdays:[1,2,3,4,5]} means weekday mornings; {type:'webhook'} runs on each request to a generated URL (returned as webhookUrl), and its prompt may use {{body.path}}, {{headers.name}}, {{query.name}}, {{body}} or {{request}} placeholders, which are the only request data the run sees. Omit projectId for this thread's project. In this thread's project, runs post into THIS thread by default (bindToCurrentThread=true); use false only when the user wants a fresh top-level thread per run. Elsewhere each run launches a fresh thread. Provider, model, and runtime settings inherit from this thread, or from the project default when there is no calling thread. Report the returned schedule and nextRunAt after success.", | 101 | 101 | parameters: OrchestratorMcpScheduleTaskInput, | 102 | 102 | success: OrchestratorMcpScheduleTaskResult, | 103 | 103 | failure: OrchestratorMcpFailure, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/persistence/Migrations.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -70,6 +70,7 @@ import Migration0053 from "./Migrations/053_PullRequestFilesViewed.ts"; | 70 | 70 | import Migration0054 from "./Migrations/054_ProjectionThreadsAutoSettleDisabledAt.ts"; | 71 | 71 | import Migration0055 from "./Migrations/055_OrchestrationV2.ts"; | 72 | 72 | import Migration0056 from "./Migrations/056_RemoveRedundantProjectionIndexes.ts"; | | 73 | +import Migration0057 from "./Migrations/057_ScheduledTaskWebhooks.ts"; | 73 | 74 |
| 74 | 75 | /** | 75 | 76 | * Migration loader with all migrations defined inline. | @@ -140,6 +141,7 @@ export const migrationEntries = [ | 140 | 141 | // Preserve this migration's schema. Future V2 schema changes need new migrations. | 141 | 142 | [55, "OrchestrationV2", Migration0055], | 142 | 143 | [56, "RemoveRedundantProjectionIndexes", Migration0056], | | 144 | + [57, "ScheduledTaskWebhooks", Migration0057], | 143 | 145 | ] as const; | 144 | 146 |
| 145 | 147 | export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/persistence/Migrations/055_OrchestrationV2.test.ts +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,7 @@ layer("055_OrchestrationV2", (it) => { | 13 | 13 | Effect.sync(() => { | 14 | 14 | assert.deepStrictEqual( | 15 | 15 | migrationEntries.map(([id]) => id), | 16 | | - Array.from({ length: 56 }, (_, index) => index + 1), | | 16 | + Array.from({ length: 57 }, (_, index) => index + 1), | 17 | 17 | ); | 18 | 18 | }), | 19 | 19 | ); | @@ -28,6 +28,7 @@ layer("055_OrchestrationV2", (it) => { | 28 | 28 | [54, "ProjectionThreadsAutoSettleDisabledAt"], | 29 | 29 | [55, "OrchestrationV2"], | 30 | 30 | [56, "RemoveRedundantProjectionIndexes"], | | 31 | + [57, "ScheduledTaskWebhooks"], | 31 | 32 | ]); | 32 | 33 | assert.deepStrictEqual(yield* runMigrations(), []); | 33 | 34 |
| @@ -50,6 +51,7 @@ layer("055_OrchestrationV2", (it) => { | 50 | 51 | { migration_id: 54, name: "ProjectionThreadsAutoSettleDisabledAt" }, | 51 | 52 | { migration_id: 55, name: "OrchestrationV2" }, | 52 | 53 | { migration_id: 56, name: "RemoveRedundantProjectionIndexes" }, | | 54 | + { migration_id: 57, name: "ScheduledTaskWebhooks" }, | 53 | 55 | ]); | 54 | 56 |
| 55 | 57 | const tables = yield* sql<{ readonly name: string }>` | |
|