# Automations

An automation is a saved prompt in a Project with triggers that say when it runs: a GitHub event, a schedule, a webhook call or a Linear issue change.

An automation starts the same run a person starts from the console, with nobody at the keyboard.
It is a saved prompt in a Project plus one or more triggers. When a trigger fires, Rush starts a
run with that prompt and puts the event that fired it after the prompt, marked as third-party data.
The saved prompt is the only instruction.

You create and edit automations in the console, on the Project's page. Its last trigger can't be
removed; switch the automation off to pause it. Anyone who can see the Project can also run one now,
as themselves: their own accounts, plus the Project's. So a saved agent that isn't shared with them
answers 404, and in a Project with a repository they need their own GitHub access to it
(`403 PROJECT_INSTALLATION_NOT_LINKED`).

_Figure: triggers fire, on the page at /docs/concepts/automations._
## What an automation holds

- **A prompt**, up to 20,000 characters.
- **A saved agent** of yours, or none to use the Project's default harness. See
  [Saved agents](/docs/concepts/saved-agents).
- **Read only.** Its runs can read the repository and comment, but not push.
- **Max runs per hour**, 1 to 30, shared by all its triggers and Run now. An event past it waits:
  its run is created `queued` and starts when the hour has room. Turning the automation off, removing
  the trigger or pausing the Project cancels the wait, and switching it to read-only makes the waiting
  run read-only. At most
  one more hour's worth waits; an event past that is refused, and so is Run now at the cap.
- **A session to wake**, optionally. Instead of starting a run, each fire sends the prompt as a
  follow-up to one resumable session in the Project, which keeps its machine and memory between
  fires. A fire that lands mid-turn is skipped.

On its triggers, an automation runs as the member who last changed what it does. If an admin edits
another member's prompt, saved agent or triggers, those runs become the admin's. Run now runs as
whoever presses it, except a wake, which continues its runner's own session. Nobody can make a run
act as someone else.

## Trigger kinds

| Kind | Fires on | Settings |
| --- | --- | --- |
| `github` | `issue_comment.mention`, `pull_request_review_comment.mention`, `pull_request.opened`, `pull_request.synchronize`, `pull_request.closed.merged`, `pull_request.labeled`, `issues.opened`, `issues.labeled`, `check_suite.failure`, `workflow_run.failure` | `branch_patterns` (globs on a pull request's base branch), `labels` (any of), `authors` (GitHub logins) |
| `schedule` | A time slot | `cron` (five fields, at most hourly) or `every` (`10m`, `30m`, `1h`, `1d`), and `timezone` (IANA, UTC by default) |
| `webhook` | A `POST` to the trigger's URL | None. The body, up to 64 KB, becomes the event text |
| `linear` | `linear.issue.state_changed`, `linear.issue.labeled` | `states` (state name to `plan` or `exec`), `labels`, `teams` (team keys; empty means every public team) |

### GitHub

Only work by a repository OWNER, MEMBER or COLLABORATOR fires a trigger. Pull requests from forks
and CI runs from forks never fire, and neither do bot senders.

### Schedule

`every` is stored as its cron, and `1d` means midnight in the trigger's time zone. `10m` and `30m`
are allowed only on an automation that wakes a session. Turning an automation back on moves each
schedule to its next slot rather than firing the slots it missed.

### Webhook

The console shows the trigger's secret once, when you create the trigger or rotate its secret.
Store it then. Call the trigger with `Authorization: Bearer <secret>`, and send an
`Idempotency-Key` header so a retry starts nothing new. An unknown trigger and a wrong secret both
answer `401`. After about 60 of those in a minute from one address to one trigger, that address gets
`429 RATE_LIMITED` on that trigger, even with the right secret, until the minute is up. Calls with
the right secret are never counted.

### Linear

A Linear trigger needs a Linear connection for the automation's runner. It fires when an issue
moves into one of `states` or gains one of `labels`, and only when the person who made the change
is in your Rush org; changes made by an app integration never fire. A state in `plan` mode starts
a read-only run that posts its plan as a comment on the issue. `exec` starts an ordinary run.
See [Linear label to PR](/docs/use-cases/linear-label-to-pr).

## Fire outcomes

Every fire has an outcome. A webhook call answers `202` with it:

| `status` | Meaning |
| --- | --- |
| `started` | A session woke for this fire and took its turn. `execution_id` names the session. |
| `queued` | A run was created. It starts once a run slot is free. `execution_id` names it. |
| `deduped` | The same event already started a run, such as a redelivery or a retried slot. |
| `skipped` | Nothing started. `reason` says why. |

A `queued` run starts at once when a slot is free, unless the automation is past its hourly limit: then it waits until the hour has room, at most an hour. Read the session to see where it is.

A `reason` is one of `disabled` (the automation is off), `paused` (the Project is paused),
`rate_limited` (Run now or a session wake at the hourly cap, or an event once an hour's worth of runs already waits), `not_member` (the runner, or whoever pressed Run now, left the org or can't see the Project), `project_gone`,
`org_deleted`, or `busy` (a wake whose session was mid-turn).

A GitHub event that matches no enabled automation leaves no record. To find out why an automation
did not fire, check its triggers' filters and the delivery history on GitHub.
