# Durability

> What happens when something dies today, what the post-MVP release will guarantee instead, what is stored from day one to make that possible, and the three acceptance tests.

The MVP does not recover from failures. It marks the agent or the run `failed` and stops. It does store everything recovery needs, so adding recovery later changes behavior, not the schema.

Durability means a failure at any point leaves the run able to continue from where it was. The MVP's claims are about the language and about teams, not about surviving crashes, so durability is table stakes that waits for the release after.

## Failures: now and later

| Failure | MVP behavior | Post-MVP guarantee |
| --- | --- | --- |
| A runner dies mid-turn | The agent is `failed` with `runner_error`. The run continues without it; the overseer is told on `system` | The controller starts a new runner that resumes the same SDK session by its stored session id, with the work folder as it was. The interrupted turn is retried from its input |
| `convoyd` dies mid-turn | On the next start, every active run is marked `failed` with `server_restart` and leftover runner processes are killed | On the next start, convoyd reloads every active run, re-adopts or restarts each runner, and resumes from stored state. No message is lost or delivered twice, and spend is not reset |
| The budget is hit mid-turn | Every agent is stopped with reason `budget`, outputs are kept | The same, plus a run can be continued with a raised budget |

## Stored from day one

Every change is written as it happens. For each agent:

- its SDK session id (the Claude Agent SDK's `session_id`; for the OpenAI Agents SDK, the session id plus the last response id),
- its read cursor on every topic and its wake state,
- its turn count and the priced usage of every turn,
- its process handle, and its status.

For each run: its spec (the stored bundle), spend, and the event log.

The runner contributes by reporting the session id on every `wake`, and by leaving its work folder and `session.db` in place when it exits. The process backend stores an opaque process id so a later `Reattach` can adopt a runner that outlived a convoyd restart; the MVP has no such path, and every runner of an active run dies with the run.

Recovery will resume the real SDK session from these values, not restart from a summary. The change is to the controller's start-up path and its exit rules, described on [Controller](/docs/runtime/controller/#recovery-on-restart).

## Acceptance tests

The durability release is done when all three pass:

1. **Runner kill.** Run `kill -9` on a random runner mid-turn. It resumes its session and the swarm still reaches `done_when`.
2. **Server kill.** Run `kill -9` on `convoyd` mid-run, then start it. Runners are re-adopted or resumed, no message is lost or duplicated, and spend is unchanged.
3. **Budget mid-turn.** Hit the budget mid-turn. Everything stops with reason `budget`, outputs are kept, and overshoot is at most one turn per running agent.

All three run against a local `openai_compatible` model so they cost nothing.

## What the MVP does on a restart

On start, before serving requests, convoyd sets every non-terminal agent of every active run to `failed` with `end_reason = server_restart`, revokes their tokens, sets the run to `failed` with the same reason, and kills every stored process id. A new `convoy run` starts a fresh run. The failed run stays readable with `convoy status --run N`. The details are on [Controller](/docs/runtime/controller/#recovery-on-restart).
