# How each case starts

> The four ways a case starts, and what Run creates for each one: a route of your app, a public endpoint, a schedule or a subscription.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://run.docs.sypnia.com/cases/starts/

For agents: starts → infrastructure. in_app: a route of the app, POST /_cases/<case-id>, called by the case's screen with the person's Sypnia Data session (actor from the session; refused 401/403 by the case's allowed actors); not public to other apps. external: a public endpoint POST /hooks/<case-id> on the app's address, input checked against the schema, authenticated by a case key (Authorization: Bearer syp_rck_…, one case only) or an HMAC signature (signature: { header, secret }), idempotency_key names an input field: a repeat within 24 h returns the first answer without running again. scheduled: an EventBridge Scheduler schedule (cron or every N, IANA timezone, DST handled), overlap skip by default, at least once; same as jobs but declared on the map. event: a subscription to another case's outcome (area.case.Outcome.vN): its own SQS queue and dead letters per listener, EventBridge rule with the filter; on: any of several, on_all: several with a correlation key and a window (a window that closes first runs nothing and ends as WindowExpired, visible in Telemetry). A case with no start fails the build (orphan).

Every case on the map says how it starts with `starts`. Run creates exactly that, and nothing else: a case that starts in the app has no public endpoint, and a scheduled case cannot be called from outside.

| `starts`    | Who starts it                                     | What Run creates                                           |
| ----------- | ------------------------------------------------- | ---------------------------------------------------------- |
| `in_app`    | a person, on a screen of your app                 | a route of your app, for that screen                       |
| `external`  | another app: a payment provider, Rappi, a partner | a public endpoint, with its schema and its idempotency key |
| `scheduled` | the clock                                         | a schedule, in your time zone                              |
| `event`     | another case, when it ends in an outcome          | a subscription, with its own queue                         |

A case with no start is an **orphan**: nothing could ever run it, so the build stops and says which one.

## `in_app`: a person, on a screen

`cases/orders/order-for-tomorrow.case.yaml`

```yaml
id: order-for-tomorrow
actor: customer
starts: in_app
where: shop.order-for-tomorrow
```

Run adds the route `POST /_cases/order-for-tomorrow` to your app. The screen at the case's `where` calls it with the person's [Sypnia Data](https://data.docs.sypnia.com/) session, and the session says who the actor is. A person whose role is not among the case's allowed actors gets `403`, and one with no session gets `401`. The route belongs to your app: it answers only to your own pages, never to other origins.

The answer is the outcome or the failure, typed, with the message for the person.

## `external`: another app calls

`cases/orders/rappi-order.case.yaml`

```yaml
id: rappi-order
actor: rappi
starts: { external: webhook, idempotency_key: rappi_order_id, signature: { header: X-Rappi-Signature, secret: RAPPI_SECRET } }
```

Run publishes `POST /hooks/rappi-order` at your app's address:

- **The input** is checked against the case's schema before your code runs; anything else gets `422`.
- **Who is calling** is proved with a case key (`Authorization: Bearer syp_rck_…`, made with `run cases keys create rappi --case rappi-order`, good for that one case only) or, as here, with the caller's signature: an HMAC of the body with a [secret](https://run.docs.sypnia.com/config/environment-and-secrets) you keep in Run.
- **The idempotency key** names a field of the input. A second call with the same `rappi_order_id` within 24 hours gets the first answer again, and the case does not run twice: a resent order is not baked twice.

## `scheduled`: the clock

`cases/weather/check-weather.case.yaml`

```yaml
id: check-weather
actor: system
starts: { scheduled: every 2h, timezone: America/Bogota }
```

Run creates a schedule, exactly as for a [scheduled job](https://run.docs.sypnia.com/jobs/cron): a cron expression or `every <n>m|h|d`, in the time zone you name, with summer time handled. A run that is still going when the next one is due is skipped, unless the start says `overlap: allow`. Like every schedule, it runs at least once per time, so the case must do no harm if it runs twice. `run cases trigger check-weather` runs it now, by hand.

## `event`: another case ended

`cases/deliveries/pause-deliveries.case.yaml`

```yaml
id: pause-deliveries
actor: system
starts: { event: weather.check-weather.RainExpected.v1 }
```

The case runs each time `check-weather` ends in `RainExpected`. Run creates a **subscription** for it: a queue of its own, its own retries and its own place for messages that keep failing. One listener that fails never slows another. How outcomes travel, and what Run guarantees, is in [Outcomes and events](https://run.docs.sypnia.com/cases/outcomes-and-events).

An event start can also:

| Write                                                                                   | To                                                                                                                                                                            |
| --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `{ on: [orders.order-for-tomorrow.OrderPlaced.v1, orders.rappi-order.OrderPlaced.v1] }` | run on any of several outcomes                                                                                                                                                |
| `{ on_all: [payments.pay.Paid.v1, kitchen.bake.Baked.v1], key: order_id, within: 2h }`  | run once all of them happened for the same `order_id`, within two hours; if the two hours pass first, nothing runs and the wait ends as `WindowExpired`, visible in Telemetry |
| `{ event: …, filter: { total: { gte: 100000 } } }`                                      | run only when the outcome's data matches                                                                                                                                      |
| `{ event: …, order_by: order_id }`                                                      | handle the events of one `order_id` in order                                                                                                                                  |

A case can only listen to the **public** outcomes of another area: what an area keeps internal stays inside it, and the build refuses a listener that reaches for it.
