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 forks.
The bill
At the end of the day, the carrier sends a bill. With Overbilled invoice on, the bill charges for drops and kilometres the log does not show. In the demo run below, van-3 is billed for 11 drops and 47.0 km, and the log shows 9 drops and 41.0 km.

The invoice agent waiting on the desk: van-3 billed for 11 drops and 47.0 km against 9 drops and 41.0 km on the log
Finding a difference is easy. The invoice agent wants to show that the difference is exactly the extra work, nothing more and nothing less, without writing anything the log never saw into the real views.
What a fork is
A fork is a copy-on-write copy of the views. You can add rows to it and query it without changing the real views. It stores only the rows you add, and everything else comes from the real views.
Staging the carrier's version of the day
The invoice agent creates a fork with laser.fork(...) and adds the drops and kilometres the log does not show as speculative rows with put_row:
fork = laser.fork(fork_id) await fork.create() for line in invoice["lines"]: van, truth = line["van"], logged.get(line["van"], {"drops": 0, "km": 0.0}) for _ in range(max(0, line["drops"] - truth["drops"])): await (fork.put_row(C.EVENTS_INDEX, 0, FORK_OFFSET + rows) .projection(f"{C.EVENTS_INDEX}.v1", 1) .field("van", van).field("kind", "delivered").field("stop", "") .field("agent", "carrier").field("ts", now).send()) rows += 1 Then it runs the same drop and kilometre totals it always runs, but against the fork, with query(...).fork(id):
def query(index: str): q = laser.query(index) return q.fork(fork) if fork else q rows = await query(C.EVENTS_INDEX).where_eq("kind", "delivered").count().group_by(["van"]).fetch() If the fork's totals now match the bill, the rows it added are exactly the work the carrier charged for that the log has no record of. The agent writes that conclusion to the log.
A person decides, then the fork goes away
Before disputing anything, the invoice agent pauses on ctx.approval_gate(...) with a prompt naming the van, what the carrier billed, what the log shows and the amount to hold. Someone approves or declines on the desk.
Once the desk has decided, the agent squashes the fork. Promoting it would write deliveries the log never saw into the real views, so the real views only ever hold what the log shows.
await self.fleet.laser.fork(fork["id"]).squash() If the invoice agent is killed while a fork is open, the fork id is kept in KV, and the next run drops the stale fork before starting again.
Limits
The what-if fork needs a deployment that serves forks (capabilities().forks). Where it does not, the check carries on without it and says so on the log.
Why this matters
Agents increasingly need to ask "what if": what would this bill, this plan or this change look like if it were true? A fork lets an agent run its normal queries on a hypothesis and throw it away afterwards, without a second database and without polluting the real data.
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.
