Skip to content

Outcomes and events

How every outcome reaches the caller, every listener and Telemetry: the outbox in the case's own transaction, the fast path and the sweep, and what Run guarantees.

Applies to EngineCloud
View as Markdown
On this page
  1. Where an outcome goes
  2. The outbox: saved with the data
  3. The fast path
  4. The sweep
  5. What each event carries
  6. What Run guarantees
  7. Loops

Where an outcome goes

When a case ends, its outcome goes to three places, and Run decides how it travels:

ToHow
Whoever is waitingThe answer of the request, for a case that starts in_app or external
Every case that listens to itAn event, through the outbox, to each listener’s own queue
Sypnia Telemetry, alwaysThe span of the run, with sypnia.case and sypnia.case.outcome (Telemetry and use cases)

In the code, every run ends with ctx.outcome: the outcome or the failure that happened, with its data (Sypnorm):

src/cases/check-weather.ts
if (forecast.rainFrom) return ctx.outcome('RainExpected', { from: forecast.rainFrom });
return ctx.outcome('ClearSkies', {});

The outbox: saved with the data

An outcome that someone listens to is saved in the same transaction as the data it describes. When pause-deliveries commits, the paused deliveries and the event deliveries.pause-deliveries.DeliveriesPaused.v1 are written together, or neither is. There is never an event about data that was rolled back, and never data whose event was lost.

Run knows at build time which outcomes have listeners. For those, the runtime adds one row to the table sypnia_cases.outbox inside the case’s transaction, with the direct runner and with the Data API’s all-or-nothing transaction alike. An outcome nobody listens to writes nothing.

Then the event leaves by one of two roads:

  1. The fast path

    Right after the commit, the service that ran the case publishes the rows it just wrote and marks them sent. Listeners usually hear the event within a second.

  2. The sweep

    Every minute, a sweeper publishes any row still unsent after 30 seconds: the service stopped between the commit and the publish, or the bus did not answer. Nothing written is ever left behind.

Where Run runsThe busThe sweeper
Cloud Sypnia CloudAmazon EventBridge, one bus per app environment, and an Amazon SQS queue per listenera schedule of the app
Engine The engine in your AWS accountthe same, in your accountthe same
Engine Without AWS: Docker or your own serverPostgres: each listener’s queue is a tablea background task in each service, woken by LISTEN/NOTIFY right after the commit, sweeping every minute

What each event carries

JSON
{
  "id": "0193f6c2-7a1e-7c3b-9d2a-5e8f1b4c6a70",
  "name": "weather.check-weather.RainExpected.v1",
  "data": { "from": "2026-11-18T15:00:00-05:00" },
  "occurred_at": "2026-11-18T13:00:04Z",
  "key": null,
  "traceparent": "00-7c2e9a4b1d8f4e6a9b3c5d7e1f2a4b6c-a1b2c3d4e5f60718-01",
  "cause": ["check-weather"],
  "depth": 1
}
  • name is area.case.Outcome.v<n>. Changing an outcome’s data in a way that would break a listener needs a new version; the old one keeps being published next to it for 90 days, then stops, and the build warns every listener still on it with the days left (Versions).
  • traceparent carries the trace, so the listener’s run is part of the same story in Telemetry: the weather check, the paused deliveries and the message to the baker are one trace.
  • cause and depth say which cases led here. They are how Run stops a loop.
  • data is at most 256 KB. For something bigger, put it in Sypnia Files and send its path.

What Run guarantees

  • At least once. An event reaches every listener at least once. Getting it twice does what getting it once does: the runtime records the event ids each listener already handled, for 7 days, and skips a repeat before your code runs.
  • Each listener on its own. Every listener has its own queue and its own retries: 5 attempts with growing waits. After the last one, the event goes to that listener’s dead letters, shown on its case in the map and in the console. run cases dlq tell-the-baker lists them, and --replay sends them again once the cause is fixed.
  • Order when you ask for it. Events are handled in any order unless the start says order_by: <field>; then the events with the same value of that field are handled one at a time, in order.
  • Waiting for several. An on_all start keeps what it has seen for each key until all of its outcomes arrived within the window, and runs once. A window that closes first runs nothing: it ends as WindowExpired, with what had arrived, on the case in the map and in Sypnia Telemetry, among the case’s outcomes and on the trace of the last event that arrived.

Loops

A chain of cases can come back on itself: «Resume deliveries» leading again to «Pause deliveries». Run checks twice:

  1. At build time, from the map: a chain of listeners that closes a circle stops the build, unless one case in it declares how it stops: loop: { bounded: true, max: 3, until: "the forecast is clear" }. A case can never listen to its own outcome.
  2. At run time, from cause and depth: an event whose chain already holds the case it would start, or that is more than 10 steps deep, does not run it. The run is recorded as LoopStopped on the trace, and Telemetry raises an alert.
  1. Where an outcome goes
  2. The outbox: saved with the data
  3. The fast path
  4. The sweep
  5. What each event carries
  6. What Run guarantees
  7. Loops

    Search pages, sections and terms