Skip to content

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 EngineCloud
View as Markdown
On this page
  1. Every case ends in a declared outcome
  2. Outcomes are events
  3. Versions
  4. What an event carries
  5. Where an outcome goes
  6. Areas share only their public outcomes
  7. The event graph

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, 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: … }. 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
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:

TypeScript
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

FieldWhat it is
ida unique id (a UUID, ordered by time). Listeners use it to never handle the same event twice
nameweather.check-weather.RainExpected.v1
datathe outcome’s typed payload, at most 256 KB
occurred_atwhen the run ended
keythe value of the listener’s order_by field, when it has one
traceparentthe trace it belongs to, so Telemetry shows the whole chain as one trace
causethe chain of cases that led here, used to stop loops (Loops)
depthhow many events deep in the chain this one is

The full example is on Delivery.

Where an outcome goes

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

Who needs itWhere it goes
someone is waiting for it: the person on the screen (in_app), or the caller of an api start with respond: outcomeback to them, as the answer
some case listens to itinto the outbox, in the same transaction as the case’s data, and from there to each listener (Delivery)
alwaysto 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). 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)
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:

Terminal
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, listeners of outcomes that do not exist, and outcomes from external and scheduled cases that nothing uses.

  1. Every case ends in a declared outcome
  2. Outcomes are events
  3. Versions
  4. What an event carries
  5. Where an outcome goes
  6. Areas share only their public outcomes
  7. The event graph

    Search pages, sections and terms