> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nika.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# SSE streaming

> Observe a run through bounded additive event views and durable recovery.

```ts theme={"system"}
for await (const event of run.events({ bufferSize: 64 })) {
  render(event)
  if (event.sequence !== undefined) {
    await persistSequence(run.id, event.sequence)
  }
}
```

`NikaRunEvent` is open to additive fields and event kinds. Render only what
the application understands, preserve the sequence, and use `run.result()`
for terminal truth. The untouched protocol frame is on `event.raw`.

A `nika serve` 0.124.1 job streams two lifecycle events: `run.started`
(`execution.started`), then `run.settled` (`execution.settled`, or
`execution.cancelled` / `execution.refused`) or `run.waiting` for a paused
job. A job admitted with a non-empty `inputs` map first records
`execution.queued` (sequence 1), which arrives as an `engine.event`. There
are no per-task events over HTTP, and the SDK never invents one; read
`run.status()` for the current state between them.
[Run events](https://docs.nika.sh/sdk/runtime/events.md#how-many-events-on-which-door) maps every
kind on both transports.

Each subscriber has a bounded queue. If a consumer falls behind, the SDK
throws `NikaEventBufferOverflowError` rather than silently losing evidence.

## Stop one view

```ts theme={"system"}
const controller = new AbortController()

for await (const event of run.events({
  signal: controller.signal,
})) {
  render(event)
}
```

The signal stops only this subscriber. Call `run.cancel()` to ask the
server to cancel engine work.

## Resume from application state

```ts theme={"system"}
const recovered = await nika.attachRun(jobId, {
  lastEventId: lastCommittedSequence,
})
```

The HTTP adapter uses the persisted cursor for SSE continuity. The application
owns when a sequence is durable.

A `paused` settlement closes the stream and resolves `run.result()` with
`status: 'paused'`. In 0.124.1 the server has no route to answer the gate, so
the job stays paused ([Jobs](https://docs.nika.sh/sdk/remote/jobs.md#recover-after-a-process-restart)).
Replaying or attaching after the settlement event was consumed still reads
the full stored settlement. Stopping a stream or attaching to a job never
answers a human gate.

> [accordion] Which published source this page describes
>
> > [!NOTE]
> >
> > **The same client selects HTTP when `url` and
> > `token` are present.** A served name such as
> > `workflows/release.nika` (its path from the project root) goes
> > directly to the server and needs no local engine or file. An explicit local
> > path such as `./release.nika` needs a compatible local engine to
> > capture an immutable snapshot. The released OpenAPI of
> > `nika serve` 0.124.1 covers jobs, SSE events,
> > cancellation, trace verification, the artifacts a settled job's sealed
> > journal records (behind `run.artifacts()`), workflow listing,
> > schedule read and write, and stateless authoring
> > (`POST /v1/compile`, behind `compile()`). It has no
> > `POST /v1/run`, job-list, or schedule list, delete, trigger
> > or backfill route. The server owns its engine version; check its
> > compatibility separately from the bundled local engine.

> [card] [Jobs](https://docs.nika.sh/sdk/remote/jobs.md)
>
> Own identity and recovery around the stream.

> [card] [Runtime events](https://docs.nika.sh/sdk/runtime/events.md)
>
> Build a tolerant presentation reducer.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.