# Outcomes and events

> How every case ends, how its outcomes become events other cases listen to, and how areas share only what they make public.

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

For agents: Every run ends in exactly one declared outcome or failure (failures are outcomes); an undeclared error is not an outcome: it goes to Telemetry as an error and, for event-started runs, to dead letters after retries. Event name <area>.<case>.<Outcome>.v<N> (e.g. weather.check-weather.RainExpected.v1); a breaking payload change needs a new version (check: breaking-change), adding an optional field does not; a new version is declared in the outcome's long form, version: <N> and since: <date> (required from version 2: the day it was first emitted); the case emits both for 90 days after since, the previous one with the payload given in ctx.outcome(name, payload, { previous: { 1: … } }) or the same payload, then the old one stops (check: old-version counts the days from since: a warning with the days left, an error after the 90 days). A declared failure undoes the run's own writes; its event (when someone listens) and the delivery's record still commit. Event envelope: id (uuid v7), name, data (the payload, ≤256 KB), occurred_at, key (order_by value), traceparent, cause (chain of case ids), depth. Delivery decided by the runtime: to the caller if one waits (in_app, external api with respond: outcome), to the outbox if any case listens, always to Telemetry. Areas: outcomes internal by default; map.yaml areas[].public lists the ones other areas may listen to (the area's contract); listening to another area's internal outcome is a check error (internal-outcome). The event graph is drawn from the files and checked for loops.

Every case ends in one of the outcomes it declares. Those outcomes are what the person sees, what the code returns, what Telemetry counts and, when another case listens, the events that start the next part of the work.

## Every case ends in a declared outcome

A run ends in **exactly one** of its outcomes or failures:

- **An outcome** when it went well: `OrderPlaced`, `RainExpected`, `ClearSkies`.
- **A failure** when something expected went wrong: `SoldOut`, `Closed`. Failures are outcomes too: they have a name and a payload, they can be listened to, and they carry the words the person reads. A failure undoes the run's own writes, so nothing half-done stays behind; its event, when some case listens to it, is still sent.

Nothing ends in silence. A case that returns without an outcome, or with one it did not declare, does not compile with Sypnorm and is reported by the check.

What is **not** an outcome is an error nobody declared: a bug, a database that does not answer, a provider that is down. The run ends as `error`, the person sees a short generic message with a reference, and Telemetry records it as a problem with its trace. A run started by an event is retried and, if it keeps failing, its event goes to the subscriber's [dead letters](https://cases.docs.sypnia.com/runtime/delivery#dead-letters), where you can see it and send it again.

## Outcomes are events

Each outcome has a full name: the area, the case, the outcome and a version.

```text
weather.check-weather.RainExpected.v1
└─area─┘└───case────┘└──outcome──┘└version
```

Any case can start on it with [`starts: { event: … }`](https://cases.docs.sypnia.com/map/starts#event). La Espiga's rain chain is three cases joined by two events:

```yaml
# cases/weather/check-weather.case.yaml
starts: { scheduled: 'every 2h', timezone: America/Bogota }
outcomes: { RainExpected: { from: datetime }, ClearSkies: {} }

# cases/deliveries/pause-deliveries.case.yaml
starts: { event: weather.check-weather.RainExpected.v1 }
outcomes: { DeliveriesPaused: { until: datetime } }

# cases/deliveries/tell-the-baker.case.yaml
starts: { event: deliveries.pause-deliveries.DeliveriesPaused.v1 }
outcomes: { BakerTold: { channel: whatsapp } }
```

### Versions

The version protects the listeners. A change that would break one, such as removing a field, renaming it or changing its type, needs a new version: `RainExpected.v2`. Adding an optional field keeps the version. The check refuses a breaking change under the same version (`breaking-change`).

A new version is written in the outcome's long form, with the day it was first emitted:

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

```yaml
outcomes:
  RainExpected:
    payload: { from: datetime, until: datetime }
    version: 2
    since: 2026-11-18
  ClearSkies: {}
```

`since` is required from version 2 on. From that day, the case emits both versions for **90 days**, and the map shows who has not moved yet. `v1` carries the payload the code gives for it, or the same payload:

```ts
return ctx.outcome('RainExpected', { from, until }, { previous: { 1: { from } } });
```

A failure takes `version` and `since` the same way, next to `when` and `tell`. After those 90 days, `v1` is no longer emitted (sooner, if no case listens to it any more). While both are emitted, `cases check` counts the days from `since` and warns every case still listening to `v1`, with the days left (`old-version`); after the 90 days the warning becomes an error, so a listener cannot stay on an event that no longer arrives.

### What an event carries

| Field         | What it is                                                                                                  |
| ------------- | ----------------------------------------------------------------------------------------------------------- |
| `id`          | a unique id (a UUID, ordered by time). Listeners use it to never handle the same event twice                |
| `name`        | `weather.check-weather.RainExpected.v1`                                                                     |
| `data`        | the outcome's typed payload, at most 256 KB                                                                 |
| `occurred_at` | when the run ended                                                                                          |
| `key`         | the value of the listener's `order_by` field, when it has one                                               |
| `traceparent` | the trace it belongs to, so Telemetry shows the whole chain as one trace                                    |
| `cause`       | the chain of cases that led here, used to stop loops ([Loops](https://cases.docs.sypnia.com/runtime/loops)) |
| `depth`       | how many events deep in the chain this one is                                                               |

The full example is on [Delivery](https://cases.docs.sypnia.com/runtime/delivery#what-each-event-carries).

## Where an outcome goes

You never choose by hand where an outcome is sent. The runtime decides it from the map:

| Who needs it                                                                                                            | Where it goes                                                                                                                                             |
| ----------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| someone is waiting for it: the person on the screen (`in_app`), or the caller of an `api` start with `respond: outcome` | back to them, as the answer                                                                                                                               |
| some case listens to it                                                                                                 | into the outbox, in the same transaction as the case's data, and from there to each listener ([Delivery](https://cases.docs.sypnia.com/runtime/delivery)) |
| always                                                                                                                  | to Telemetry, as the outcome of the run's span                                                                                                            |

So an outcome nobody listens to costs nothing more than its span, and adding a listener later needs no change to the case that emits it.

## Areas share only their public outcomes

An **area** is a group of cases that belong together ([Actors, areas and journeys](https://cases.docs.sypnia.com/map/actors-areas-journeys#areas)). Its outcomes are **internal** by default: only cases of the same area can listen to them. The ones other areas may listen to are listed in the area, and that list is the area's contract with the rest of the app:

`cases/map.yaml (areas)`

```yaml
areas:
  - id: weather
    title: Weather
    cases: [check-weather]
    public: [check-weather.RainExpected]
  - id: deliveries
    title: Deliveries
    cases: [pause-deliveries, tell-the-baker]
    public: [pause-deliveries.DeliveriesPaused]
```

A case that listens to another area's internal outcome is a check error (`internal-outcome`). That keeps areas apart: an area can change everything inside it, as long as its public outcomes keep their shape.

## The event graph

Every case says what it listens to, so the flow of events is never hidden: Cases draws the **event graph** from the files. In the editor it is a second view of the map, next to the navigation tree: cases as nodes, events as arrows, each arrow with its queue, its retries and its dead letters. In the terminal:

```bash
npx @sypnia/cases graph                     # the whole graph, as text
npx @sypnia/cases graph --from weather.check-weather.RainExpected.v1
```

```text
weather.check-weather ──RainExpected.v1──▶ deliveries.pause-deliveries ──DeliveriesPaused.v1──▶ deliveries.tell-the-baker
```

The check reads the same graph to find [loops](https://cases.docs.sypnia.com/runtime/loops), listeners of outcomes that do not exist, and outcomes from external and scheduled cases that nothing uses.
