# Configuration

This page is `durable.config.ts`, the one file where the engine is configured, as `durable-sdk init` writes it. It teaches each option of `createDurable` the template sets, what the value means and where it comes from; the variables themselves are on [Environment variables](https://durablesdk.com/docs/reference/environment-variables.md).

The engine is configured once per process, in this file, and every route and workflow reaches it through the barrel `src/durable.ts`. A second `createDurable` with a different configuration is refused (`AlreadyConfigured`); nothing in the app calls it elsewhere, and the doctor holds that (`durable-sdk doctor --host`).

## The file the template writes

```ts
// durable.config.ts: the one call, once per process.
import { createDurable, DEFAULT_POLICY } from "@durable-sdk/core";
import { postgresStores } from "@durable-sdk/postgres";
import { roleFromVercel, vercelPlatform } from "@durable-sdk/vercel";
import pg from "pg";

import { EVENTS } from "./src/events/catalog";

const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });

export const durable = createDurable({
  stores: postgresStores({ pool }),
  defaultScope: "app",
  catalog: EVENTS,
  partition: (_name, _key, payload) =>
    (payload as { scope?: string }).scope ?? "app",
  platform: vercelPlatform({
    plan: "pro",
    queue: false,
    cronSecret: (env) => env.CRON_SECRET,
  }),
  principal: { prefixes: ["user"] },
  redaction: DEFAULT_POLICY,
  reverters: {},
  workflows: () => import("./src/workflows/all"),
  listeners: () => import("./src/listeners"),
  schemaPolicy: "refuse",
  environment: {
    name: process.env.DURABLE_ENV_NAME!,
    role: roleFromVercel(),
  },
  reconfigure: process.env.NODE_ENV === "development" ? "rebind" : "refuse",
});
```

## The options

| Option         | The template's value                                        | What it does                                                                                                                                                                                                                                                                                                                                       |
| -------------- | ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `stores`       | `postgresStores({ pool })` over `DATABASE_URL`              | The engine's tables (runs, steps, the ledger, the outbox) on your app's database, in the schema `durable` under the `snake` naming the migrator wrote. One pool, shared with whatever else the app runs on `pg`; the engine reads the pool's `max` once and keeps its own background work under it.                                                |
| `defaultScope` | `"app"`                                                     | The ledger partition of work that belongs to no scope. A workflow names its own scope in its key (`key: ["orderId", "requestId"]` with a `scope` part) and the ledger chains per scope.                                                                                                                                                            |
| `catalog`      | `EVENTS` from `src/events/catalog.ts`                       | Every fact the app emits, each with a schema and a clock-free key. `ctx.emit` of a fact not in the catalog is refused. [Events and listeners](https://durablesdk.com/docs/guide/events-and-listeners.md).                                                                                                                                                                   |
| `partition`    | the payload's `scope`, else `"app"`                         | The ordering rule: facts of one partition are delivered one at a time in order; partitions run side by side.                                                                                                                                                                                                                                       |
| `platform`     | `vercelPlatform({ plan: "pro", queue: false, cronSecret })` | The function's deadline from the plan row, the wake (`DURABLE_WAKE=inline` on the platform: the drain runs inside the request that kicked it, the minute cron the fallback), the self URL (`DURABLE_ALIAS_URL`), the deployment's identity. `queue: false`: no delayed wake is handed to a queue; timers resume at minute precision from the cron. |
| `principal`    | `{ prefixes: ["user"] }`                                    | The actor prefixes the app records on a run (`user:<id>`); `system:` and `operator:` are the engine's.                                                                                                                                                                                                                                             |
| `redaction`    | `DEFAULT_POLICY`                                            | The names and shapes the ledger refuses to store (`password`, `token`, `secret`, a connection string with userinfo, a bearer). Widen it with `withPolicy(DEFAULT_POLICY, { secretKeys: [...] })`; never narrow it. [Concepts](https://durablesdk.com/docs/concepts.md).                                                                                                     |
| `reverters`    | `{}`                                                        | The compare-and-set restorers a step's undo calls by name for a write the engine does not know how to reverse. The template has none; add one per external table you write.                                                                                                                                                                        |
| `workflows`    | `() => import("./src/workflows/all")`                       | Lazy: the manifest of every workflow, loaded on the first tick. A workflow file not in the manifest is a doctor finding.                                                                                                                                                                                                                           |
| `listeners`    | `() => import("./src/listeners")`                           | Lazy: every `on(fact, ...)` the app registers.                                                                                                                                                                                                                                                                                                     |
| `retention`    | the defaults                                                | When finished runs, delivered facts and old ledger images are pruned; the engine's `retention.apply` runs daily. Set `retention: { schedule: { cron, input } }` to move it.                                                                                                                                                                        |
| `schemaPolicy` | `"refuse"`                                                  | A database behind the package refuses every run, resume, dispatch and relay until `durable-sdk migrate` ran. The template's build runs `migrate --baseline=if-missing` before `tsc`, so a deployment never reaches a schema it cannot use. `"warn"` logs once and goes on; never on production.                                                    |
| `environment`  | `name` from `DURABLE_ENV_NAME`, `role` from the platform    | This deployment's identity on the stream: `production` or `preview` on the platform. A production role inserts the one instance row on an empty database and refuses to run against a database whose row names another environment (`InstanceMismatch`); previews share one database branch named `preview`.                                       |
| `reconfigure`  | `"rebind"` in development, `"refuse"` otherwise             | The dev server's hot reload re-evaluates this module; in production a second configuration is an error.                                                                                                                                                                                                                                            |

Options the template does not set and you may: `services` (clients a step reads as `i.services.<name>`, each a factory called at every read, never a client held on the module), `sessions`, `tickTasks` (your own work inside the dispatch tick, by name and in order), `scrub` (the workflow that rewrites stored outputs on a redaction request), `steps: "lenient"` (never on a hosted app: the doctor refuses it), `remedies` (your own error rows for `durable-sdk explain`).

## The guard manifest

`durable.guards.ts` beside it is the descriptor the doctor reads (`DurableGuards` of `@durable-sdk/testing/guards`): the framework convention (`vercel-functions`: a recursive walk of `api/`, the `maxDuration` pin on each handler), the routes directory, the pin the routes must repeat, the roots the source rules walk (the application root, the tests root), the modules (the barrel, the catalog, the listeners, the manifest, the primitives), the doubles the doctor's spec imports first and, since GR-004 (ADR-0060 decision 14 as amended 2026-10-30), `index.prismaSchemas`, the Prisma schema per database client the host's graph-index walk reads as text. The template writes it whole and you rarely touch it; a route or a module you add is held by name the day it lands. `durable-sdk doctor --host` reads it and runs every guard rule offline; a failed rule prints as one line with its fix and the rule's id, and `durable-sdk doctor --host --explain <rule id>` says the rule's law and hazard. [The doctor](https://durablesdk.com/docs/guide/the-doctor.md).

## The routes the engine needs

The template mounts the engine's four doors under `api/` and `vercel.json` rewrites the canonical paths onto them: `/jobs/dispatch` (the minute cron's tick, `CRON_SECRET` as bearer), `/health`, `/admin/api/*` (the operator API, behind `ADMIN_TOKEN`, `ADMIN_READ_TOKEN` and the platform's signed sessions), `/internal/relay` (404 while the app has no peers). Each handler refuses a `Host` outside `DURABLE_HOSTNAMES` with 404, so only the product's hostnames serve the app. The cron is `* * * * *` on the production deployment; a preview has no cron and ticks at its own requests. You do not edit these; the doctor holds their pins (`maxDuration` equal to the plan row's).

---

Prompt for an agent:

```text
Read https://durablesdk.com/docs/reference/configuration.md, then change one option of durable.config.ts and keep the doctor green; run durable-sdk doctor --host before and after; a refused line is a refusal id: durable-sdk explain <id>
```
