Skip to main content

Scheduled tasks API

Schedule recurring prompts for your agents using cron expressions. You can create, update, list, and delete scheduled tasks through these endpoints.
Scheduled tasks are processed by an inline scheduler that runs inside the API process. The scheduler polls for pending tasks every 30 seconds and executes up to 10 tasks per cycle. Each task is dispatched as an HTTP request to the target agent with a 30-second timeout.
Each tick claims due tasks atomically using SELECT ... FOR UPDATE SKIP LOCKED. Tasks are only marked completed when the agent returns a 2xx response. Failed dispatches are re-queued with backoff or marked failed once attempts reaches maxAttempts. See Execution lifecycle below.
All scheduled task endpoints require session authentication. Tasks are scoped to the authenticated user — you can only manage tasks for agents you own.

List scheduled tasks

Returns all scheduled tasks for the authenticated user, sorted by creation date (newest first).

Query parameters

Response

Task object

Errors

Create a scheduled task

Creates a new scheduled task for one of your agents. The cron schedule is validated to ensure it contains 5 or 6 fields.

Request body

Example request

Response (201 Created)

Returns the created task object.

Errors

Update a scheduled task

Updates an existing scheduled task. Only the fields you include in the request body are changed.

Request body

Example request

Response

Returns the updated task object.

Errors

Delete a scheduled task

Permanently deletes a scheduled task.

Request body

Response

Errors

Execution lifecycle

Each scheduled task moves through a small state machine driven by the inline scheduler. The status field on the task object reflects the current state.

Status values

Atomic claim

Each scheduler tick claims due tasks using SELECT ... FOR UPDATE SKIP LOCKED inside a single atomic statement. This guarantees that overlapping ticks, concurrent replicas, or restarted workers can never claim the same task twice. Up to 10 tasks are claimed per tick.

Retry behavior

When a dispatch fails — the agent returns a non-2xx status, the request times out, or the network call raises — the task is settled as follows:
  • If attempts < maxAttempts, the task is re-queued. nextRun is set to NOW() + backoff, status is reset to pending, and lastError is updated. The task is picked up again on a future tick.
  • If attempts >= maxAttempts, the task is marked failed and stops retrying.
Backoff schedule (linear with a hard cap): The backoff is min(30 × attempts, 300) seconds. The default maxAttempts is 5.

Stale-claim recovery

If a worker dies mid-dispatch (process crash, container restart, network partition), the task can be left in running state with no worker driving it forward. On every tick, the scheduler scans for tasks that have been running for more than 10 minutes and returns them to pending with nextRun = NOW(), lastError = "Recovered after stale worker lock". They are then picked up on the next tick. You should never see a task stuck in running for more than 10 minutes during normal operation.