Part of a short series on the features in the Delivery Desk demo, a parcel delivery desk run by agents on one durable log, built on Laser SDK. The first post, Killing agents in a delivery desk demo, covers crash and resume. This one covers Rewind, the time-travel view.

What Rewind does

Under the map there is a Rewind button. It rebuilds the day so far and puts a slider on it. Drag the slider back to see the day at any minute: where each van was, which drops had been made, which exceptions were open and what the agents were doing. Back to live returns to the live map.

Rewind at 10:01, with the day rebuilt from 2,160 records on the log
Rewind at 10:01, with the day rebuilt from 2,160 records on the log

The point is where the picture comes from. Rewind uses nothing from KV and nothing from the server's memory. Everything it shows is read back from the log.

Two topics, read from the start

The desk writes two topics:

  • fleet.positions: every van's position report
  • fleet.events: every drop, failed drop, agent step and outcome

For each topic, Rewind opens a new cursor with laser.topic(...).replay(), which starts at the first record, and polls until there is nothing left:

async def read(laser, topic: str) -> tuple[list[dict], list[int]]: cursor = laser.topic(topic).replay() records = [] while True: messages = await cursor.poll() if not messages: return records, list(cursor.offsets) for message in messages: try: value = message.json() except Exception: continue if isinstance(value, dict): records.append(value) 

A replay cursor is separate from the agents' own consumers, so reading the day back does not move anyone else's progress.

Folding records into frames

The records are then grouped into one frame per minute of the demo's clock. A frame holds the last position of each van reported in that minute. A van missing from a frame has not moved since the frame before. Every event is tagged with the minute it happened in.

The browser gets the list of frames and the timed events, and the slider steps through them.

Limits

  • Rewind reads both topics from the start each time. That is fine for a day of a few thousand records.
  • Routes are kept in KV, and KV has no history, so the planned road ahead is not drawn while rewound. Positions, drops, failed drops, exceptions and agent steps are all on the log, so those are shown.

Why this matters

When an agent does something surprising, the first question is what it saw at the time. If everything the agents did is on a durable log, you can answer that by reading the log back, not by hoping someone kept the right debug output. The same records also feed the desk's queries, readers and end-of-day evals.

Try it

You need Python 3.11+ and Docker.

git clone https://github.com/laserdata/laser-delivery-desk cd laser-delivery-desk docker compose up -d python3 -m venv .venv && . .venv/bin/activate pip install -e . python -m fleet.server 

The code is at laserdata/laser-delivery-desk, Laser SDK is at laserdata/laser-sdk, and the docs are at docs.laserdata.com/laser-sdk.