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

# Deterministic replay

> Export a world as a scenario document and rebuild it exactly — the data-level half of Euca's byte-for-byte determinism.

Because the world is [data](/concepts/world-as-table) and the engine is
[deterministic](/concepts/determinism), a run is reproducible: capture the starting world as a
**scenario**, and re-applying it plus the same seed and inputs reproduces the run.

<Note>
  Start a local server first — see the [Quickstart](/quickstart). All commands target
  `http://localhost:3917`; every `POST` sends `Content-Type: application/json`.
</Note>

## 1. Export the world

`GET /scenario` serializes the current world — entities, rules, templates, and assertions —
into one declarative document:

```bash theme={null}
curl -s http://localhost:3917/scenario > world.json
```

A `world.json` for a two-entity world with one rule looks like this (the export also emits an
explicit `null` for every unset spawn field — `velocity`, `collider`, `mesh`, … — trimmed here
for readability; only the set fields matter on re-apply):

```json theme={null}
{
  "version": 2,
  "entities": [
    { "position": [-3, 1, 0], "health": 100, "team": 1 },
    { "position": [3, 1, 0], "health": 60, "team": 2 }
  ],
  "rules": [
    {
      "when": { "kind": "death" },
      "filter": "any",
      "actions": [ { "action": "heal", "target": "this", "amount": 10 } ]
    }
  ]
}
```

## 2. Rebuild it

`POST /scenario` wipes the entities and rebuilds the world from the document:

```bash theme={null}
curl -s -X POST http://localhost:3917/scenario \
  -H 'Content-Type: application/json' --data @world.json
# { "ok": true, "entities_spawned": 2, "rules": 1, "templates": 0, "assertions": 0 }

curl -s -X POST http://localhost:3917/step -H 'Content-Type: application/json' -d '{"ticks":1}'
curl -s -X POST http://localhost:3917/observe
# → the two entities (position, health, team) and the rule are reproduced
```

From here, stepping the rebuilt world with the same inputs reproduces the original run — that
is the [determinism guarantee](/concepts/determinism), verified by the engine's content digest.

## What round-trips, and what to watch

<Check>
  Entity **position, scale, health, and team**, and the **typed rules**, round-trip faithfully.
</Check>

For an *exact* replay, rebuild into a **fresh process** and mind three things:

* **Rebuild on a fresh server.** Rules are [sticky](/guides/data-driven-rules) — re-applying a
  scenario onto a world that already has rules *appends* them, doubling the rule set. A clean
  round-trip starts from a freshly started server.
* **`velocity` and `physics_body` are not exported** (they serialize as `null`). Re-add them
  after rebuilding if your scene relies on them.
* **Entity ids and generations are reassigned** on rebuild — thread the new ids from the
  rebuilt world rather than assuming the originals.
