Skip to content

Taskbase — Routines: Recurring Tasks

Kind: reference

A routine is a project's recurring task: a task template and a cron schedule. When a slot of the schedule comes due, Taskbase creates one task from the template in the project's Backlog. A routine only creates tasks; runners still pull them like any other task (ADR-0006). An agent assignee queues the task; a person assignee or none leaves it on the board.

Shipped in task #1737 (taskbase#613, merged 2026-10-27). Source: api/internal/routine/ in the taskbase repository, read on 2026-10-27.

Fields

A routine as the API returns it (routine.Routine in routine.go):

Field Type Meaning
id integer Read-only
project_id integer The project its tasks are created in. Read-only
name string Required, at most 200 characters
schedule string Required. Five-field cron expression, see Schedule
timezone string Required. IANA time zone the schedule is read in, e.g. Europe/Copenhagen
active boolean false pauses the routine. Default true
template object What each task is created from, see Template
skip_if_active boolean Skip a slot while the routine's last task is open. Default true
create_gitea_issue boolean Give each task a Gitea issue. Default false, see Gitea issues
next_run_at timestamp or null The next slot. Null while paused. Read-only
last_run_at timestamp or null When the routine last created a task. Read-only
last_task_id integer or null The newest task it created. Read-only
last_task object or null That task as {id, title, done}. Read-only
schedule_text string The schedule in plain words, see Schedule. Read-only
spend_usd number The routine's spend, see Spend. Read-only
created_by string Username of the person who created it. Read-only
created_at, updated_at timestamp Read-only

Columns and indexes are in Database Schema.

Schedule

schedule has five fields: minute, hour, day of month, month and day of week (schedule.go).

Field Values
minute 0–59
hour 0–23
day of month 1–31
month 1–12
day of week 0–7; both 0 and 7 are Sunday

Each field takes numbers, *, ranges a-b, steps /n and comma lists. Names such as mon are refused. When both day fields are restricted, a day matching either one is due, as in cron. A schedule that never comes due within five years (e.g. 0 8 31 2 *) is refused.

The schedule is read in timezone, so a slot keeps its local time across summer time: 0 8 * * 1 in Europe/Copenhagen is 08:00 local before and after the switch. A local time the clock skips when summer time starts is not a slot. The API embeds the time zone database (time/tzdata), so it does not depend on the image's zoneinfo.

schedule_text says the common shapes in words and anything else as cron <expr> (from TestDescribe in schedule_test.go):

schedule schedule_text
0 8 * * 1 every Monday at 08:00
0 8 * * 1,4 every Monday and Thursday at 08:00
0 8 * * 1-5 every weekday at 08:00
30 17 * * * every day at 17:30
0 8 1 * * on day 1 of every month at 08:00
15 * * * * every hour at :15
*/15 * * * * cron */15 * * * *

Template

template holds the fields of each task the routine creates:

Field Meaning
title Required. {date} is replaced by the date the task is created, in the routine's time zone, as YYYY-MM-DD. It is not the slot's date: after downtime the one task gets today's date, and Run now has no slot
description Markdown
assignee, assignee_type Set both or neither; assignee_type 1 is a person, 2 an agent persona
model Tier or model id, as on a task
required_labels Labels a runner must have, as on a task
priority 0–3
epic_id, milestone_id Must be in the project's organization

The assignee is refused with 400 when a task of the project could not have it: the project's reviewer persona or a session persona (CheckAssignee). This is checked on save and again when a task is created, so Run now of a routine whose assignee became one also answers 400.

Scheduling

The runner sweeper runs routine.Scheduler every 15 s, in every API replica, on the same ticker as the lease sweep (Runners and Runs). Each sweep fires every active routine whose next_run_at has passed:

  • A due slot creates one task, and next_run_at moves to the first slot after now.
  • After downtime, one task covers the missed window. Because the next slot is counted from now, slots missed while the API was down are not created one by one.
  • While the last task is open, the slot is skipped when skip_if_active is on: next_run_at moves on and no task is created. The last task is last_task_id; it counts as open while it is not done.
  • Pausing clears the next run. Setting active to false sets next_run_at to null. Activating it again, or changing schedule or timezone, sets next_run_at to the first slot after now. Any other edit keeps it.
  • Each slot fires once. The scheduler holds the routine's row (FOR UPDATE) while it decides and creates the task, so a replica sweeping at the same moment finds the slot already moved on (TestPostgresSchedulerFiresOnceAcrossReplicas).

A routine whose task cannot be created is logged as routine: task not created and tried again on the next sweep.

Each task records its routine in tasks.created_by_routine_id; the task API returns it as the read-only routine {id, name}, and the task dialog shows "from routine name" next to the id.

Run now

POST /api/routines/{id}/run creates the routine's task at once, even while the routine is paused or its last task is open. next_run_at does not change. It answers 201 with the task.

Spend

spend_usd is the sum of cost_usd of every run of every task the routine created, including the runs of their legacy review tasks. It counts tasks the routine created before an edit too.

Gitea issues

A routine's tasks get no Gitea issue by default. With create_gitea_issue on, in a project linked to a repository, the issue reconciler gives each task an issue on a later sweep (every 2 minutes), not at creation. When the routine is deleted, its tasks keep created_by_routine_id (the column has no foreign key on purpose), so the reconciler still leaves them without an issue.

Who can manage routines

People with a grant on the project's organization. Every routine route is humansOnly in the route guard (api/internal/authz/guard.go): an agent acting for a run gets 403 forbidden: not available to agents acting for a run. The MCP tools below therefore work only with a person's credentials.

API and MCP tools

Route MCP tool Does
GET /api/projects/{id}/routines list_routines The project's routines, by name
POST /api/projects/{id}/routines create_routine Create a routine; answers 201
GET /api/routines/{id} get_routine One routine
PUT /api/routines/{id} update_routine Replace name, schedule, timezone and the whole template; an omitted active, skip_if_active or create_gitea_issue keeps its value
DELETE /api/routines/{id} delete_routine Delete the routine; answers 204. The tasks it created stay
POST /api/routines/{id}/run run_routine Run now

A body with an unknown field, an invalid schedule or time zone, or an invalid template answers 400 with the reason; a missing routine answers 404. A create body, from handler_test.go:

{
  "name": "Weekly status",
  "schedule": "0 8 * * 1",
  "timezone": "Europe/Copenhagen",
  "template": {
    "title": "Weekly status {date}",
    "description": "Report.",
    "assignee": "project-manager",
    "assignee_type": 2
  }
}

Created on Monday 2026-10-26 at 06:00 UTC, it answers with active and skip_if_active true, create_gitea_issue false, next_run_at 2026-10-26 07:00 UTC (08:00 in Copenhagen) and schedule_text "every Monday at 08:00"; Run now creates the task "Weekly status 2026-10-26" (TestCreateDefaultsAndNextRun, TestRunNow; run with go test ./internal/routine/, not against a live API).

The Routines bar

The project page has a Routines bar below the request box (ProjectRoutines in ui/src/Routines.jsx). It is collapsed by default and shows the number of routines. Opened, it lists each routine with:

  • its name and an Active or Paused chip;
  • the schedule in plain words with its time zone, the next run (— while paused), the last task as a link with "(done)" once done, and the spend;
  • an Active checkbox, Run now, Edit and Delete.

+ New routine and Edit open a form for the name, schedule, time zone (the browser's by default), task title, description, assignee, model, required labels, priority, and the checkboxes "Skip a run while the last task is open" and "Create a Gitea issue for each task". The form does not edit the template's epic and milestone; an edit keeps them.