# Durable Nanocode on Cloudflare

Each session is one Durable Object, and the object's own SQLite is the agent's journal. A deploy or an eviction resets the object mid-turn, and the next instance finishes the turn from what the journal holds.

**A Durable Object is already a single writer with its own database, so an agent needs nothing else to survive a reset.** No lock service, no external database, no machine to keep warm. This page covers the Cloudflare host. [Durable Nanocode](/experiments/durable-nanocode) covers the journal format both hosts share.

## TL;DR

* **Three rows a turn:** a turn with text or a tool call writes 3 rows, and a reply writes 2.
* **Survives resets:** the fault drill finished a charge with exactly one charge after a reset, and a turn after five resets.
* **First output in 3.0 s:** the median on the deployed demo, with Claude Haiku 5.5 starting at effort `none`.
* **Eight turns kept:** a session keeps its eight newest finished turns and every unfinished one.

The dates below are the days each number was measured, from [durable-cloudflare's DECISIONS.md](https://github.com/nanocodexyz/durable-cloudflare/blob/master/DECISIONS.md).

## How It Works

```mermaid
flowchart LR
  browser[Browser] --> worker[Worker]
  worker --> session[Session Durable Object]
  session -->|journal| sqlite[(Object SQLite)]
  session -->|alarm| session
  session --> gateway[AI Gateway]
```

* **One object per session:** the Worker routes each request to the session's object, which runs nanocode-ts over its storage. The object runs one request at a time, so the session has one writer without locks.
* **Sync before the model:** the object waits for its storage to confirm before a model request leaves, so every earlier write is durable before the outside sees its effect.
* **An alarm per turn:** the object stores an alarm before a turn runs. If a reset drops its memory, the alarm wakes a new instance, which replays each Code Mode cell from the journal and continues.
* **Unknown, not retried:** a tool call with no committed result reaches the model as an unknown outcome. The model decides what to do, and nothing runs the call a second time.

## What Does a Turn Write?

nanocode-ts keeps each session in one log table with compressed rows, and telemetry stays live-only. Over 10 local turns on 2026-11-13:

| Turn      | Rows written |  Bytes |
| --------- | -----------: | -----: |
| Text      |          3.0 | 1.2 KB |
| Tool call |          3.0 | 1.3 KB |
| Reply     |          2.0 | 0.5 KB |

The release before took 43.2, 44.2 and 29.1 statements for the same turns. A session retires finished turns past its newest eight, so its storage does not grow with every turn it has run.

## Does It Survive a Reset?

`npm run drill` resets the object at the worst moments, on local workerd. On 2026-11-07:

| Fault                                       | Result                                                       |
| ------------------------------------------- | ------------------------------------------------------------ |
| A reset during a charge                     | Completed 2.5 s after submission, one charge                 |
| A reset while a cell sleeps before its call | Completed in 8.1 s, one charge, with the charge's own result |
| A reset during each of five model calls     | Completed in 4.1 s through the five resets                   |

All three scenarios passed again on 2026-11-16, each with one charge.

## How Fast?

On 2026-11-16, three rounds of the demo's four prompts against the deployed demo, with Claude Haiku 5.5:

| Effort                        | First output, median | Model time per turn, median |
| ----------------------------- | -------------------: | --------------------------: |
| `none`                        |                3.0 s |                       6.4 s |
| `low`                         |                3.6 s |                       7.0 s |
| `medium`, the model's default |                3.5 s |                       7.7 s |

Every completed turn answered correctly at every effort, so the demo starts models at `none`. A visitor's saved choice still wins.

## Limits

* **8 MiB per value:** workerd's SQLite refuses a string, BLOB or row above 8,388,608 bytes, locally and in production (measured 2026-10-20), although Cloudflare documents 2 MB.
* **2,000 characters per prompt:** the public demo answers 413 to a longer one.
* **Four resets without progress:** a turn that is reset four times in a row with no progress between them stops recovering and fails, so a broken turn cannot loop forever.

We want to be clear about what the speed table measured: three of its 36 turns failed with 402 from the deployment's provider credit, not from the effort, and whole turns moved with tool time more than with effort.

## Try It Today

Open [nanocode on Cloudflare](https://nanocode.xyz/cloudflare/), select "Kill the next tool call", and ask for a charge. The object resets during the charge, a new instance takes the turn over, and the agent reports that the charge may have gone through.

The host is open source at [nanocodexyz/durable-cloudflare](https://github.com/nanocodexyz/durable-cloudflare). If you run agents on Workers and lose turns to deploys, we would love to hear from you on [GitHub](https://github.com/nanocodexyz).

- [Durable Nanocode](/experiments/durable-nanocode): The journal format, reopens, and costs.

- [Cloudflare Workers](/docs/guides/workers): Run sessions in Durable Objects, step by step.

- [On Vercel](/experiments/durable-nanocode-on-vercel): The same agent in Vercel Functions.
