-
Notifications
You must be signed in to change notification settings - Fork 0
AXI-92: Add scheduled task automation surface #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3302785
feat: add scheduled task automation surface
Codename-11 29131fd
fix: address scheduled task review feedback
Codename-11 d2bde75
fix: advance overdue manual task runs
Codename-11 57dc807
fix: close scheduled task claim races
Codename-11 24bdc0e
fix: guard stale scheduled task resumes
Codename-11 5dbbd71
fix: harden task edits and timezone choices
Codename-11 5ee8333
merge main into scheduled tasks
Codename-11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Scheduled tasks | ||
|
|
||
| Scheduled tasks are Forge's first-class recurring automation surface. They are | ||
| separate from legacy recurring issues: existing recurring issue definitions and | ||
| their behavior are unchanged. | ||
|
|
||
| Open **Automation → Scheduled tasks** in a workspace to create and monitor a | ||
| task. Owners and admins can manage tasks; every workspace member can inspect | ||
| their schedule, current status, error state, and recent runs. | ||
|
|
||
| ## Create-issue action | ||
|
|
||
| The initial supported action creates a real Forge issue through the same | ||
| canonical service used by the rest of the product. Configure: | ||
|
|
||
| - a task name and issue title; | ||
| - a prompt, which becomes the issue description; | ||
| - issue priority; | ||
| - delivery to the workspace inbox or an active project; and | ||
| - an interval, daily, or weekly schedule. | ||
|
|
||
| Daily and weekly schedules use an IANA timezone and retain their local | ||
| wall-clock time across daylight-saving changes. Interval schedules are elapsed | ||
| time based and run at least five minutes apart. | ||
|
|
||
| ## Runs and failures | ||
|
|
||
| Every attempt gets a durable run row before the action begins. Successful runs | ||
| link to the issue they created. Failed runs retain a useful error message on | ||
| both the task and run history. | ||
|
|
||
| For scheduled attempts, Forge calculates and saves the next future occurrence | ||
| before executing the action. A failed action therefore remains visibly active | ||
| for its next run. Pausing is the only lifecycle action that clears `nextRunAt`; | ||
| resuming computes a new future occurrence. | ||
|
|
||
| **Run now** executes immediately without moving the regular future occurrence. | ||
| Deleting a task requires typing its exact name and removes its run history, but | ||
| keeps issues created by earlier runs. | ||
|
|
||
| ## Worker operation | ||
|
|
||
| The BullMQ maintenance worker scans due tasks every minute. Run `pnpm worker` | ||
| alongside the web process in deployments that do not enable in-process workers. | ||
| The legacy `RecurringIssue` ticker continues independently. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| -- First-class recurring automation tasks. Legacy RecurringIssue rows remain | ||
| -- untouched and continue to use their existing ticker. | ||
|
|
||
| CREATE TYPE "ScheduledTaskAction" AS ENUM ('CREATE_ISSUE'); | ||
| CREATE TYPE "ScheduledTaskScheduleType" AS ENUM ('INTERVAL', 'DAILY', 'WEEKLY'); | ||
| CREATE TYPE "ScheduledTaskDeliveryType" AS ENUM ('INBOX', 'PROJECT'); | ||
| CREATE TYPE "ScheduledTaskStatus" AS ENUM ('ACTIVE', 'RUNNING', 'SUCCEEDED', 'FAILED', 'PAUSED'); | ||
| CREATE TYPE "ScheduledTaskRunStatus" AS ENUM ('RUNNING', 'SUCCEEDED', 'FAILED'); | ||
| CREATE TYPE "ScheduledTaskRunTrigger" AS ENUM ('SCHEDULE', 'MANUAL'); | ||
|
|
||
| ALTER TYPE "EventKind" ADD VALUE 'SCHEDULED_TASK_CREATED'; | ||
| ALTER TYPE "EventKind" ADD VALUE 'SCHEDULED_TASK_UPDATED'; | ||
| ALTER TYPE "EventKind" ADD VALUE 'SCHEDULED_TASK_DELETED'; | ||
| ALTER TYPE "EventKind" ADD VALUE 'SCHEDULED_TASK_RUN_STARTED'; | ||
| ALTER TYPE "EventKind" ADD VALUE 'SCHEDULED_TASK_RUN_SUCCEEDED'; | ||
| ALTER TYPE "EventKind" ADD VALUE 'SCHEDULED_TASK_RUN_FAILED'; | ||
|
|
||
| CREATE TABLE "ScheduledTask" ( | ||
| "id" TEXT NOT NULL, | ||
| "workspaceId" TEXT NOT NULL, | ||
| "createdById" TEXT NOT NULL, | ||
| "projectId" TEXT, | ||
| "name" TEXT NOT NULL, | ||
| "action" "ScheduledTaskAction" NOT NULL DEFAULT 'CREATE_ISSUE', | ||
| "prompt" TEXT NOT NULL, | ||
| "issueTitle" TEXT NOT NULL, | ||
| "issuePriority" "Priority" NOT NULL DEFAULT 'NONE', | ||
| "deliveryType" "ScheduledTaskDeliveryType" NOT NULL DEFAULT 'INBOX', | ||
| "scheduleType" "ScheduledTaskScheduleType" NOT NULL, | ||
| "intervalMinutes" INTEGER, | ||
| "timeOfDayMinutes" INTEGER, | ||
| "dayOfWeek" INTEGER, | ||
| "timezone" TEXT NOT NULL, | ||
| "enabled" BOOLEAN NOT NULL DEFAULT true, | ||
| "status" "ScheduledTaskStatus" NOT NULL DEFAULT 'ACTIVE', | ||
| "nextRunAt" TIMESTAMP(3), | ||
| "lastRunAt" TIMESTAMP(3), | ||
| "lastSucceededAt" TIMESTAMP(3), | ||
| "lastError" TEXT, | ||
| "consecutiveFailures" INTEGER NOT NULL DEFAULT 0, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
| CONSTRAINT "ScheduledTask_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| CREATE TABLE "ScheduledTaskRun" ( | ||
| "id" TEXT NOT NULL, | ||
| "workspaceId" TEXT NOT NULL, | ||
| "scheduledTaskId" TEXT NOT NULL, | ||
| "outputIssueId" TEXT, | ||
| "status" "ScheduledTaskRunStatus" NOT NULL DEFAULT 'RUNNING', | ||
| "trigger" "ScheduledTaskRunTrigger" NOT NULL, | ||
| "scheduledForAt" TIMESTAMP(3), | ||
| "startedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "completedAt" TIMESTAMP(3), | ||
| "error" TEXT, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| CONSTRAINT "ScheduledTaskRun_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| CREATE INDEX "ScheduledTask_workspaceId_enabled_nextRunAt_idx" | ||
| ON "ScheduledTask"("workspaceId", "enabled", "nextRunAt"); | ||
| CREATE INDEX "ScheduledTask_workspaceId_status_idx" | ||
| ON "ScheduledTask"("workspaceId", "status"); | ||
| CREATE INDEX "ScheduledTask_projectId_idx" ON "ScheduledTask"("projectId"); | ||
| CREATE INDEX "ScheduledTaskRun_scheduledTaskId_createdAt_idx" | ||
| ON "ScheduledTaskRun"("scheduledTaskId", "createdAt"); | ||
| CREATE INDEX "ScheduledTaskRun_workspaceId_createdAt_idx" | ||
| ON "ScheduledTaskRun"("workspaceId", "createdAt"); | ||
| CREATE INDEX "ScheduledTaskRun_outputIssueId_idx" ON "ScheduledTaskRun"("outputIssueId"); | ||
|
|
||
| ALTER TABLE "ScheduledTask" | ||
| ADD CONSTRAINT "ScheduledTask_workspaceId_fkey" | ||
| FOREIGN KEY ("workspaceId") REFERENCES "Workspace"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
| ALTER TABLE "ScheduledTask" | ||
| ADD CONSTRAINT "ScheduledTask_createdById_fkey" | ||
| FOREIGN KEY ("createdById") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
| ALTER TABLE "ScheduledTask" | ||
| ADD CONSTRAINT "ScheduledTask_projectId_fkey" | ||
| FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
| ALTER TABLE "ScheduledTaskRun" | ||
| ADD CONSTRAINT "ScheduledTaskRun_workspaceId_fkey" | ||
| FOREIGN KEY ("workspaceId") REFERENCES "Workspace"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
| ALTER TABLE "ScheduledTaskRun" | ||
| ADD CONSTRAINT "ScheduledTaskRun_scheduledTaskId_fkey" | ||
| FOREIGN KEY ("scheduledTaskId") REFERENCES "ScheduledTask"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
| ALTER TABLE "ScheduledTaskRun" | ||
| ADD CONSTRAINT "ScheduledTaskRun_outputIssueId_fkey" | ||
| FOREIGN KEY ("outputIssueId") REFERENCES "Issue"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
3 changes: 3 additions & 0 deletions
3
prisma/migrations/0108_scheduled_task_due_index/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -- Support the global worker sweep, which filters enabled tasks and orders by nextRunAt. | ||
| CREATE INDEX "ScheduledTask_enabled_nextRunAt_idx" | ||
| ON "ScheduledTask"("enabled", "nextRunAt"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The worker sweep is global across workspaces (
enabled/nextRunAtplusORDER BY nextRunAtinsweepScheduledTasks), but this index leads withworkspaceId, which is not constrained by that query. As scheduled tasks accumulate across tenants, the once-per-minute worker cannot read due rows in next-run order from this index and will have to scan/sort; add a worker-oriented index starting withenabled, nextRunAt(or an equivalent partial index).Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e930b0d. Added Prisma index [enabled, nextRunAt] plus migration 0107; the migration applied cleanly and the live dev schema reports ScheduledTask_enabled_nextRunAt_idx with the expected btree columns.