# Durable Nanocode on Vercel

A Vercel Function has no database and no long life. So each session's Workflow run is the journal: every SQL batch nanocode commits is a step of the run, and the next Function replays the steps and finishes the turn.

**A Function that dies mid-turn loses nothing, because the turn's state was never only in the Function.** The Workflow queue starts a new one, and it picks up from the last committed batch. This page covers the Vercel host. [Durable Nanocode](/experiments/durable-nanocode) covers the journal format both hosts share.

## TL;DR

* **First text in 1.4 s:** the median for new sessions once the deployment's instances are up, and 1.1 s for a later turn.
* **100 of 100:** a hundred concurrent sessions all finished, at a median of 4.5 s to the end of the stream.
* **One charge per crash:** the fault drill kills a Function during a charge and recovered in 222 to 360 ms.
* **2.7x fewer Workflow events:** writes that return before they commit use 65 events for a session where waiting for each commit uses 173.

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

## How It Works

```mermaid
flowchart LR
  browser[Browser] --> fn[Vercel Function]
  fn -->|each SQL batch is a step| run[(Workflow run)]
  run -->|replay| fn
  fn --> gateway[Model gateway]
  queue[Workflow queue] -->|new Function after a crash| fn
```

* **A run per session:** `App.create` from `nanocode-ts/vercel` builds the agent on [durable-harness](https://github.com/vercel-labs/durable-harness). Each session is a Workflow run.
* **Batches as steps:** every SQL batch the SDK commits is a step of that run, keyed by its position. The Workflow kernel keeps the first step for each key, so two drives of one session agree on batch n.
* **Replay into memory:** each drive replays the batches into an in-memory `node:sqlite` database before it serves the SDK.
* **Two modes:** with durability `on`, the default, a write returns as soon as it runs locally and its batch commits in the background, in order. With `strict`, each write waits for its commit.

## Does It Survive a Crash?

`npm run drill` kills a Function in the middle of a charge and checks the ledger, for both harnesses in both modes. On 2026-11-08 it passed all eight runs: recovery took 222 to 360 ms after a kill during the charge, and a kill while a cell waited finished in 4.5 s, with one charge each. It passed again on 2026-11-16.

On 2026-10-20 on a laptop, for a session of one recovered turn and one workspace turn:

|                                       | Durability `on` |      `strict` |
| ------------------------------------- | --------------: | ------------: |
| SQL batches, Claude                   |              12 |            48 |
| Workflow events                       |              65 |    173 to 176 |
| Recovery to the end of the first turn |   213 to 227 ms | 406 to 503 ms |

Strict drives spent 62 to 76% of their time waiting on batches.

## How Fast?

On 2026-11-14, against the production deployment, 592 turns with no failures:

| Case                           | First text, median |      p90 |
| ------------------------------ | -----------------: | -------: |
| A new session after idle       |           3,246 ms | 4,376 ms |
| 20 new sessions right after    |           1,425 ms | 1,654 ms |
| A later turn of a long session |           1,099 ms |          |

A hundred sessions at once reached the end of the stream at a median of 4,470 ms and a p90 of 6,181 ms, and all 100 finished. The model's first byte stayed at 600 to 650 ms.

On 2026-11-16, with Claude Haiku 5.5 on the demo's four prompts, the first output came at a median of 2.1 s at effort `none` against 3.2 s at `low` and at `medium`, the model's default. All 45 turns answered correctly, so the demo starts models at `none`. A visitor's saved choice still wins.

## Limits

* **300 s per Function:** the chat route sets `maxDuration` to 300 s. A longer turn continues in the next Function from the journal.
* **The public demo's policy:** a prompt of at most 2,000 characters (413 beyond), at most 20 prompts per session, and at most 30 requests a minute per visitor through nanocode.xyz.

We want to be clear about cold starts: a brand-new instance after idle still takes 4.1 to 4.4 s to first text, about 1.5 s of boot and module load before the headers and 1.8 s more before the model request. Under concurrency, new-session work before the headers costs about 250 ms per session per instance, against about 5 ms locally.

## Try It Today

Open [nanocode on Vercel](https://nanocode.xyz/vercel), select "Kill the next tool call", and ask for a charge. The Function dies during the charge, the next one takes the turn over, and the agent reports that the charge may have gone through.

The app is open source at [nanocodexyz/durable-vercel](https://github.com/nanocodexyz/durable-vercel). If you run agents on Vercel and lose turns to timeouts or crashes, we would love to hear from you on [GitHub](https://github.com/nanocodexyz).

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

- [Vercel Functions](/docs/guides/vercel): Run a durable agent on Vercel, step by step.

- [On Cloudflare](/experiments/durable-nanocode-on-cloudflare): The same agent in Durable Objects.
