# Configuration

> The important cairnflow runtime flags, their environment variables and defaults, grouped by purpose.

Source: https://cairnflow.dev/docs/self-hosting/configuration

`cairnflow --help` lists every flag. This page covers the ones you are likely to set.

## How settings are read

1. Built-in defaults.
2. Environment variables, where a flag has one.
3. Command-line flags, which win over environment variables.

A malformed number in an environment variable is ignored and the default is kept; a malformed flag
value stops the node at startup. Values that select a mode (such as `CAIRNFLOW_QUIET_LEASE` or
`CAIRNFLOW_ADVERTISE_HOST`) are checked strictly in both forms.

## Storage

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--main-store URI` | `CAIRNFLOW_MAIN_STORE` | none | Main store: `file://`, `memory://` or `s3://`. See [Object stores](/docs/self-hosting/storage). |
| `--data-dir DIR` | `CAIRNFLOW_DATA_DIR` | `./cairnflow-data` | Shortcut for `--main-store file://DIR`. `--main-store` wins if both are set. |
| `--wal-store URI` | `CAIRNFLOW_WAL_STORE` | main store | Separate store for the write-ahead log. |
| `--wal-atomic-put true\|false` | none | by store | Declares whether PUTs on the log store are atomic under crashes. Required for `s3://` stores other than AWS S3, Tigris and SeaweedFS; use `false` for MinIO. |

S3 credentials and endpoint come from environment variables such as `AWS_ACCESS_KEY_ID`; there are
no flags for them (see [Object stores](/docs/self-hosting/storage#s3-credentials-and-endpoint)).

## Network

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--host ADDR` | `CAIRNFLOW_HOST` | `127.0.0.1` | Bind address. Also the advertised address unless `--advertise-host` is set. |
| `--advertise-host ADDR` | `CAIRNFLOW_ADVERTISE_HOST` | `--host` | Host advertised to peers and clients. |
| `--port N` | `CAIRNFLOW_PORT` | `8080` | Client port: API, console, metrics. `0` lets the OS choose; the real port is in the first log line. |
| `--internal-port N` | `CAIRNFLOW_INTERNAL_PORT` | `--port` + 1 | Node-to-node port. `0` when `--port` is `0`. |
| `--http-header-timeout-ms N` | `CAIRNFLOW_HTTP_HEADER_TIMEOUT_MS` | `75000` | Time allowed to read request headers on both ports. Also the idle limit of keep-alive connections: set it above the idle timeout of the proxy in front, so the proxy closes idle connections first. |
| `--trust-proxy CIDR[,CIDR]` | `CAIRNFLOW_TRUST_PROXY` | none | Peers in these ranges are trusted TLS proxies: their `X-Forwarded-*` headers are used. Repeatable. |

Both ports speak HTTP/1 only.

## Cluster

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--node-id ID` | `CAIRNFLOW_NODE_ID` | generated per process | Node identity. Keep it stable per machine. |
| `--partitions N` | `CAIRNFLOW_PARTITIONS` | `1` | Number of ranges when the bucket is first initialised. Must match on every node. |
| `--lease-ttl-ms N` | `CAIRNFLOW_LEASE_TTL_MS` | `10000` | Lease lifetime; failover takes about one TTL. |
| `--shutdown-timeout-ms N` | `CAIRNFLOW_SHUTDOWN_TIMEOUT_MS` | `20000` | Cap on a graceful shutdown after `SIGTERM`/`SIGINT`. |
| `--quiet-lease off\|solo\|delegation` | `CAIRNFLOW_QUIET_LEASE` | `delegation` | Lease renewal mode written when this node **creates** a new bucket. `delegation`: a single node renews with conditional reads, and a multi-node cluster delegates renewal to a coordinating node. `solo`: only the single-node mode. `off`: every node renews with writes. Ignored for a bucket that already holds a cluster. |
| `--auto-split off\|suggest\|on` | `CAIRNFLOW_AUTO_SPLIT` | `suggest` | Automatic range splitting. See [Running a cluster](/docs/self-hosting/cluster). |
| `--max-range-bytes N` | none | 8 GiB | Size above which a range is proposed for a split. |
| `--auto-split-max-ranges N` | none | `128` | Splits for load stop once the range table has this many ranges. `0` removes the cap. |
| `--auto-split-merge-cold-ms N` | none | `21600000` (6 h) | Two adjacent ranges cold for this long are proposed for a merge (never merged automatically). `0` turns merge proposals off. |
| `--lineage-compact-depth N` | none | `2` | A range that still reads the files of this many ancestor ranges gets one full compaction. `0` turns it off. |
| `--slow-shed on\|off` | `CAIRNFLOW_SLOW_SHED` | `on` | A node that is much slower than its peers at writing to the store gives up leadership, one node at a time. |
| `--deploy-refresh-ms N` | `CAIRNFLOW_DEPLOY_REFRESH_MS` | `30000` | Safety-net interval for re-reading cluster-wide records (deployments, keys, tenants). Changes are pushed to peers immediately; this bounds the delay when a push is missed. |

`--cluster` (`CAIRNFLOW_CLUSTER`) is still accepted but has no effect: every node runs the lease
protocol.

## Authentication and secrets

These are environment variables only. See [Security](/docs/self-hosting/security).

| Variable | Meaning |
|---|---|
| `CAIRNFLOW_ADMIN_KEY` | Bootstrap key: `cluster-admin` role, tenant `default`, never written anywhere. At least 32 bytes, or the node does not start. |
| `CAIRNFLOW_ADMIN_KEY_SHA256` | 64 hex digits, the SHA-256 of a bootstrap key. The node knows only the hash. Do not set it together with `CAIRNFLOW_ADMIN_KEY`. |
| `CAIRNFLOW_PROVISION_KEY_SHA256` | 64 hex digits, the SHA-256 of a `provision` key for tenant `default`. |
| `CAIRNFLOW_METRICS_KEY` | Token that can only call `GET /metrics`. At least 32 bytes, different from the bootstrap key. |
| `CAIRNFLOW_CLUSTER_SECRET` | HMAC secret between nodes. At least 32 bytes and identical on every node. If unset, the first node creates one in the bucket. |
| `CAIRNFLOW_IDENTITY_MASTER` | Master secret for signing requests to your services. At least 32 bytes, identical on every node. Unset: requests are not signed. |

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--no-auth` | `CAIRNFLOW_NO_AUTH` | off | Disables API keys. Development only; the internal port still requires signatures. |
| `--profile saas` | `CAIRNFLOW_PROFILE=saas` | off | Hardened defaults for a shared, multi-tenant node; refuses to start when a requirement is missing. |

## Invocations

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--invoke-wait-ms N` | `CAIRNFLOW_INVOKE_WAIT_MS` | `5000` | How long `POST /invoke` waits for a result before answering `202` with the id. `0` answers right after the first turn. |
| `--attach-max-wait-ms N` | `CAIRNFLOW_ATTACH_MAX_WAIT_MS` | `60000` | Cap on `?wait_ms=` for attach calls. |
| `--inactivity-timeout-ms N` | `CAIRNFLOW_INACTIVITY_TIMEOUT_MS` | `60000` | A turn is abandoned (and retried with backoff, journal intact) when your service makes no progress for this long. In practice, the longest `ctx.run` closure you allow. `0` disables it. |
| `--inactivity-timeout-max-ms N` | `CAIRNFLOW_INACTIVITY_TIMEOUT_MAX_MS` | `3600000` (1 h) | Upper bound for the `inactivityTimeout` a handler declares; longer values are clamped. |
| `--max-concurrent-turns N` | `CAIRNFLOW_MAX_CONCURRENT_TURNS` | `32` | Client-initiated turns running at once on the node, shared by its ranges. Each turn is one connection to your service. |
| `--max-turns-per-tenant N` | `CAIRNFLOW_MAX_TURNS_PER_TENANT` | `0` (no cap) | Turns of one tenant running at once on the node, so one tenant whose service hangs cannot hold every slot. |
| `--key-rate N/S` | `CAIRNFLOW_KEY_RATE` | no cap | Request rate of one API key (or one SSO user) on the node: a burst of `N`, then one request every `S/N` seconds. Over it: `429 key_rate_limited` with `Retry-After`. |
| `--replay-ram-budget-bytes N` | `CAIRNFLOW_REPLAY_RAM_BUDGET_BYTES` | `536870912` (512 MiB) | Journal bytes the node's running turns may hold in memory at once; one tenant holds at most a quarter. A turn that does not fit is rescheduled after 1 s without calling your service. `0` removes the budget. |
| `--retention-ms N` | `CAIRNFLOW_RETENTION_MS` | `86400000` (24 h) | How long finished invocations are kept before they are purged. Also the deduplication window of idempotency keys. `0` keeps them forever. A handler's `journalRetention` overrides it. |
| `--no-archive` | `CAIRNFLOW_NO_ARCHIVE` | archive on | Purge without writing an archive copy first. |
| `--archive-artifacts` | none | off | Copy artifact bytes into the archive too. By default the archive keeps only references. |
| `--schedule-min-period-ms N` | `CAIRNFLOW_SCHEDULE_MIN_PERIOD_MS` | `10000` | Smallest `everyMs` accepted for a server-side schedule. |
| `--max-open-streams-per-tenant N` | `CAIRNFLOW_MAX_OPEN_STREAMS_PER_TENANT` | `256` | Long-lived connections (stream reads, pending attaches) per tenant per node. Over the limit: `429 too_many_open_streams`. `0` removes the limit. |
| `--tick-interval-ms N` | `CAIRNFLOW_TICK_MS` | `200` | Background safety-net tick for timers and retries. |

## Backpressure

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--queue-wait-ms N` | `CAIRNFLOW_QUEUE_WAIT_MS` | `10000` | How long a request waits for a concurrency slot before the client gets `429`. `0` waits forever. |
| `--l0-soft N` | `CAIRNFLOW_L0_SOFT` | `5` | From this many level-0 views in a range (the limit is 8), new work is refused with some probability (`429 range_overloaded`). `0` disables it. |
| `--l0-max-reject P` | `CAIRNFLOW_L0_MAX_REJECT` | `0.9` | Highest refusal probability, in `[0, 1)`. |

See [Flow control](/docs/reference/flow-control).

## SQL queries

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--query-isolation auto\|process\|inline` | none | `auto` | Where SQL sent to `POST /query` runs. `process`: a `cairn-query-worker` child process per query, killed at the query deadline or its memory limit. `inline`: inside the node. `auto`: `process` when `cairn-query-worker` sits next to `cairnflow`, otherwise `inline` with a warning at startup. |
| `--query-worker PATH` | `CAIRNFLOW_QUERY_WORKER` | next to `cairnflow` | Path of the `cairn-query-worker` binary. |
| `--query-worker-memory-mb N` | none | `512` | Memory limit of each query process. A query over it gets `422 query_budget`; the node is unaffected. |

See [Security](/docs/self-hosting/security#sql-queries-run-in-a-child-process).

## Web console

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--no-ui` | `CAIRNFLOW_NO_UI` | console on | Do not serve the web console. |
| `--ui-base-path P` | `CAIRNFLOW_UI_BASE_PATH` | `/ui` | Path of the console. Must not collide with an API route. |
| `--ui-cookie-secure on\|off` | `CAIRNFLOW_UI_COOKIE_SECURE` | on unless `--host` is loopback | Whether the session cookie carries `Secure`. |
| `--ui-env-label L` | `CAIRNFLOW_UI_ENV_LABEL` | none | Environment badge in the console header, 1 to 24 printable ASCII characters. |

## Outbound requests (egress)

| Flag | Default | Meaning |
|---|---|---|
| `--egress-deny-private` | off | Requests to your services may not reach loopback, private, link-local and metadata, CGNAT or other special addresses. |
| `--egress-allow-cidr CIDR` | none | Repeatable. A private network you do want to reach; wins over `--egress-deny-private`. |
| `--egress-deny-cidr CIDR` | none | Repeatable. Always blocked, even when `--egress-deny-private` is off. |
| `--egress-require-https` | off | Accept only `https://` service endpoints. |

## Shared write-ahead log (advanced)

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--flush-interval-ms N` | `CAIRNFLOW_FLUSH_INTERVAL_MS` | `10` | Minimum gap between two log objects of one stream. On S3 a PUT takes longer than this, so it rarely binds. Smaller means more PUTs under heavy load. |
| `--wal-window-ms N` | none | `--flush-interval-ms` | Node-wide log window; a range can have its own (`PUT /ranges/{id}/window`). |
| `--wal-linger-us N` | none | `1000` | After an idle period, wait this long so commits that arrive together share one object. Maximum `100000`. |
| `--wal-stripes N` | none | `2` | Log streams per node. |
| `--wal-inflight N` | none | `1` | PUTs in flight per stream. |
| `--wal-object-cap-bytes N` | none | `1048576` | Maximum size of one log object. |
| `--wal-age-flush-ms N` | none | `60000` | Age after which a range's in-memory data is flushed to sorted files. |
| `--wal-put-timeout-ms N` | none | `2000` | Timeout of one log PUT; after three consecutive failures the node stops itself. |
| `--engine-threads N` | `CAIRNFLOW_ENGINE_THREADS` | `0` (one per core) | Threads that run range engines. |

`--wal-kind shared` is accepted and changes nothing; any other value is refused at startup.

## SST disk cache

| Flag | Default | Meaning |
|---|---|---|
| `--disk-cache-dir DIR` | off | Cache copies of sorted files (SSTs) of every range on local disk. Holds customer data. See [Operations](/docs/self-hosting/operations). |
| `--disk-cache-bytes N` | `17179869184` (16 GiB) | Cache size limit, kept by LRU eviction. |

## Background maintenance

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--gc-retired-dbs` | `CAIRNFLOW_GC_RETIRED_DBS=1` | off | Remove the data of ranges retired by split or merge once nothing references it. Deletes data. `--gc-retired-dbs=plan` (or `=plan` in the variable) only logs the plan. |
| `--gc-every-s N` | `CAIRNFLOW_GC_EVERY_S` | `600` | Interval of that collection. |
| `--gc-min-age-s N` | `CAIRNFLOW_GC_MIN_AGE_S` | `1800` | Minimum age of retired data before it can be collected. |
| `--trash-keep-s N` | `CAIRNFLOW_TRASH_KEEP_S` | `604800` (7 days) | How long deleted objects stay in the trash. `0` never empties it. |
| `--tenant-purge-keep-s N` | `CAIRNFLOW_TENANT_PURGE_KEEP_S` | `604800` (7 days) | How long a tenant marked for deletion stays reversible before its data is deleted. `0` never deletes. |
| `--scrub-every-s N` | `CAIRNFLOW_SCRUB_EVERY_S` | `600` | Shortest interval of the background consistency check (read-only). `0` disables it. |
| `--scrub-requests-per-hour N` | `CAIRNFLOW_SCRUB_REQUESTS_PER_HOUR` | `6000` at the default interval | Caps the store requests of that check: after a round that cost C requests it pauses at least C/N hours, so the interval stretches as the number of ranges grows. `0` removes the cap. |
| `--retire-orphans-every-s N` | `CAIRNFLOW_RETIRE_ORPHANS_EVERY_S` | `3600` | Safety-net interval for cleaning up after interrupted splits and merges. `0` disables it. |
| `--reconcile-intents-every-s N` | `CAIRNFLOW_RECONCILE_INTENTS_EVERY_S` | `15` | Interval for rolling back splits and merges that no node is coordinating. `0` disables it. |

## Handler health

| Flag | Environment | Default | Meaning |
|---|---|---|---|
| `--slow-log-ms N` | `CAIRNFLOW_SLOW_LOG_MS` | `5000` | Runs longer than this leave one `warn` line (target `cairnflow::slow_log`), at most 10 lines per second per node. |
| `--quarantine off\|observe\|cooldown\|hold` | `CAIRNFLOW_QUARANTINE` | `observe` | What to do with a handler that keeps failing. `observe` only logs and counts; `cooldown` limits it to one concurrent run per range; `hold` puts new invocations of it in `paused` (code 576). |
| `--quarantine-rule A/I/S` | none | `20/5/300` | A handler is flagged after at least A failed attempts across at least I invocations, with no success, within S seconds. |
| `--quarantine-ttl-s N` | none | `3600` | How long a quarantine entry lives. |

## Logging and tracing

| Variable | Meaning |
|---|---|
| `RUST_LOG` | Log filter, default `info`. Logs go to stderr. |
| `CAIRNFLOW_LOG=json` | One JSON object per line instead of text. |
| `CAIRNFLOW_OTEL_ENDPOINT` (or `OTEL_EXPORTER_OTLP_ENDPOINT`) | Export traces over OTLP/HTTP, when the binary is built with OpenTelemetry support. |

`--no-user-otlp` (`CAIRNFLOW_NO_USER_OTLP`) exports only system spans and keeps the spans and logs
your handlers write inside cairnflow.
