# Config and state

> Where Orbit reads its config, every section and key with what it means, how to check the value in effect, what reloads live, and what lives in the state directory.
>
> Describes Orbit 0.1.9. Web page: https://docs.orbit.dialectic.com/0.1.9/reference/config-and-state/

This page is for contributors who need to know exactly which file Orbit reads, which keys exist, what a change takes to apply, and what Orbit writes to disk. Everything here is checked against `src/settings.rs`, `src/tools/config_watch.rs` and the makinaX library's config types as of Orbit 0.1.9. On a running install, the config file plus `health_check` → `config` and the `refresh_state` reply are the source of truth.

## The config file

Orbit reads exactly one file:

| Condition | Path |
|---|---|
| default | `~/.config/orbit/config.toml` |
| `XDG_CONFIG_HOME` set | `$XDG_CONFIG_HOME/orbit/config.toml` |

Resolution is `Settings::default_path()` in `src/settings.rs`. Two traps:

- The header of `example.config.toml` still says `$XDG_CONFIG_HOME/orbit-mcp/config.toml`. That is stale: the directory is `orbit`, with or without `XDG_CONFIG_HOME`.
- A `config.toml` in the current working directory is **not** read. If one exists and parses differently from the real file, Orbit warns at startup and in every `refresh_state` report (`settings::divergence_warning`).

`orbit-mcp init [--force]` writes a minimal valid config (mode 0600) at that path. `orbit-mcp onboard` adopts an existing Safe and writes the config for it.

### Finding the value in effect

This page names each key and what it does; it does not state values. On a running install:

- The running value of a key is the one in the config file, or Orbit's built-in default for a key the file leaves out (`orbit-mcp init` writes a minimal config, so most keys take the built-in default).
- `health_check` → `config` says whether the file on disk is the one in effect (`loaded_digest_matches_disk`, `last_reload_result`). When it is not, `health_check.blocking` names why, and the previous settings are still running.
- The `refresh_state` reply lists what changed and what needs a restart (`requires_restart`).
- Several values are also reported where they are used, for example `expires_in_s` on a swap quote and `sim_receipt.valid_for_s` on a simulation.
- The shipped example config, `example.config.toml`, lists the keys with comments. Releases ship it at `share/example.config.toml` in the release archive (beside `share/watchdog.example.toml`); a self-update install keeps `share/` under the state directory, and `ORBIT_SHARE_DIR` points elsewhere.

### Loading and validation

`Settings::load_from` layers two sources with the `config` crate: the file (optional at the parser level), then environment variables. Before parsing, `refuse_legacy_config` rejects retired surfaces with a fix-it message:

- a `[machines.<name>]` section (renamed to `[safes.<name>]`);
- `mcp.allow_mainnet_writes` (it gated nothing; delete it, use `execution_paused` to halt);
- any `[safes.<name>.data_feed]` block (curator data now comes only from installed packages).

Then `validate` enforces:

- at least one `[safes.*]` entry (except on the quick-setup path, `load_allowing_no_safes`, which exists to deploy the first Safe);
- at most one Safe with `default_context = true`;
- every Safe's `chain` has an `[rpc_urls.<chain>]` entry;
- in the read-only build only: `[signer]` must be absent or `type = "unsigned"`, `[tenderly]` must be absent, and `mcp.mode` must not be `"read-write"`.

Load errors name the file and a fixed sentence for the kind of failure (`settings::describe_load_failure`), never the parser's own message, because a broken line can carry a secret the redactor does not know yet.

Write paths absolute. `~` is expanded only in built-in defaults, not in values you set.

### Environment overrides

Every key can be overridden with an `ORBIT__` variable, `__` as the separator, values parsed (`try_parsing(true)`):

```sh
ORBIT__MCP__POLL_INTERVAL_S=30
ORBIT__RPC_URLS__BASE=https://your-node.example
```

An override is still subject to validation, and the load error says when the file is valid but an `ORBIT__` setting is not.

## Sections and keys

Types marked "makinaX" are defined in the makinaX library (`makinax::ext`) and re-exported by `src/settings.rs` so existing configs parse unchanged.

### `[rpc_urls]` (required)

One entry per chain key (`base`, `mainnet`, `hyperevm`, …). Each value is a single URL string or an ordered array (makinaX `Endpoints`). With an array, the transport fails over to the next URL only on an infrastructure error (transport error, 429, timeout), never on a contract revert. `health_check` reports `rpc_endpoint_count` per Safe.

### `[safes.<name>]` (at least one)

| Key | Meaning |
|---|---|
| `chain` | Required. Key into `[rpc_urls]`. |
| `safe` | Required. The Safe address. |
| `module` | Required. The `MakinaXModule` address. |
| `rootfile` | `"local:<path>"` or `"github:<org>/<repo>/<path>"`. Optional on purpose: a Safe with no rootfile boots unrooted (it can be read, install packages and compose a root, but cannot execute). |
| `rootfile_pin` | Expected merkle root; startup and reload fail on mismatch. |
| `default_context` | The Safe tool calls use when none is named. At most one. |
| `deploy_block` | Block the module was deployed at, where event scans start. If unset, found once by an `eth_getCode` binary search (needs an archive RPC) and cached. |
| `operator_address` | `from` for operator-gated accounting reads. If unset, the signer's address. Set it on read-only builds. |
| `mandate_path` | Per-Safe mandate slot under `<state>/mandates/`. The mandate Orbit governs with is the global document at `<state>/mandates/global.toml`; see `docs/mandate.md`. |
| `swappers` | Quote adapter name to on-chain `swapperId` (`<adapter> = <id>`). Retired adapters are dropped at load. |
| `tracked_positions.<id>` | Fallback valuation by `balanceOf(safe)` for positions with no accounting instruction (`token`, `label`, `is_debt`). Ignored, with a warning, when the rootfile has an accounting instruction for that id. |
| `expected_operating_mode` | `"OPEN"`, `"FENCED"` or `"WALLED"`. `verify_setup` flags a mismatch; writes are never gated on it. |
| `guardian_address` | Watchdog guardian address for `verify_setup`'s `isGuardian` check. If unset, Orbit falls back to the address recorded in `<state>/keystore/guardian.json` (`settings::guardian_address_for`). |
| `bridge_intents` | Array of `{ bridge_id, dest_chain, input_token, output_token, recipient? }`. Drives bridge precondition checks and the execute-time bridge preflight. |

### `[signer]` (write build only)

makinaX `SignerConfig`, tagged by `type`. With no signer configured, Orbit runs unsigned.

| `type` | Keys |
|---|---|
| `keystore` | `path` (required). Passphrase sources, checked in order: `passphrase_file` (must be 0600), `passphrase_env`, `keychain_service` (macOS). |
| `gcp` | `project_id`, `keyring`, `key_name` (required); `location`, `key_version` (optional). |
| `private_key` | `env` (name of the variable holding the key). Refused unless Orbit runs with `--dev` or `mcp.dev_mode = true`. |
| `unsigned` | none. Writes impossible. |

`orbit-mcp keystore-create [--path DIR] [--role operator|guardian]` creates an encrypted keystore; by default it writes into `<state>/keystore/`.

### `[mcp]`

| Key | Meaning |
|---|---|
| `mode` | Informational label (`read-only` or `read-write`). Write capability is decided by the build, the signer and the mandate. The read-only build rejects `read-write`. |
| `poll_interval_s` | Background snapshot and config-watch cadence. An explicitly set value (any value, even one equal to the default) wins over `rpc_usage_mode`. |
| `rpc_usage_mode` | `low`, `medium` or `high`: the polling pace each names is a constant in `src/rpc_usage.rs`, and the `set_rpc_usage_mode` tool states it. A choice made through `set_rpc_usage_mode` is stored in the database and outlives the config value. |
| `snapshot_retention_days` | Full portfolio-reading detail for this many days, then one reading a day. `"off"` keeps everything. |
| `position_index_db` | SQLite ledger (in the state directory unless set). |
| `audit_log` | Append-only audit trail (in the state directory unless set). |
| `execution_paused` | Boot default of the soft local pause. `set_execution_paused` overrides it and the override persists. Not a security boundary; the guardian pause and the circuit breaker are. |
| `sim_receipt_ttl_blocks` | Kept so old configs load; ignored. A simulation receipt's lifetime is a fixed window, the same on every chain: a constant in the receipt window module (`src/writes/receipt_window.rs`), reported as `sim_receipt.valid_for_s`. |
| `quote_ttl_s` | Swap quote freshness window, reported as `expires_in_s` on each quote. The pipeline re-quotes once automatically if a quote expires between simulate and execute. |
| `approval_requote_drop_bps` | Owner approvals re-quote at approval time; the approved `min_out` is the floor. |
| `confirmation_expiry_s` | Pending owner confirmations expire after this. |
| `event_chunk_size` | `eth_getLogs` chunk size for event backfill. |
| `dev_mode` | Same as `--dev`. Never in production. |
| `fork_hardfork` | Hardfork for spawned anvil forks. Copied over `[fork].hardfork` when Orbit builds the makinaX config, so this is the key that counts. |
| `staleness_file` | Optional JSON `{"<safe>": {"age_s": <seconds>}}` input to the policy engine. |

### `[owner]`

| Key | Meaning |
|---|---|
| `enabled` | Serve the owner page. |
| `port` | Loopback port. |
| `token_file` | Bearer token (in the state directory unless set), generated with mode 0600 on first start if absent. |
| `bind` | `"localhost"` or `"tailscale"`: bind the machine's tailnet IP (100.64.0.0/10). Token auth is unchanged. |
| `wc_project_id` | Public WalletConnect project id. Unset: browser-extension wallets still sign, the QR and mobile path is off. |

### `[fork]` (makinaX `ForkConfig`)

Tuning for the warm anvil fork used for pre-execution simulation.

A remote fork source, `http(s)` or `ws(s)`, is reached through a local relay, so a key in its address never appears on anvil's command line. Without a running relay, a `ws(s)` source is not used: the fork points at a closed local port and a warning says why.

| Key | Meaning |
|---|---|
| `timeout_ms` | Spawn-ready wait and anvil's upstream request timeout. |
| `retries` | `anvil --retries`. |
| `retry_backoff_ms` | `anvil --fork-retry-backoff`. |
| `compute_units_per_second` | Self-imposed rate limit against the fork source. Unset: none. |
| `anvil_path` | Explicit anvil binary; otherwise `$PATH`, then `~/.foundry/bin/anvil`. |
| `base_anvil_path` | Base-capable anvil binary (Orbit adds `--base`). Without it, Orbit uses its bundled Base anvil, then the `base-anvil` wrapper on `PATH`. |
| `probe` | `health_check` fork-readiness probe, cached for a fixed time. `"off"` skips it. |
| `sim_fallback` | On an infrastructure failure of the fork (RPC error, 429, spawn or timeout), fall back to Tenderly if configured, else `eth_call`. A genuine revert is never masked, and reduced fidelity is flagged on the result. |
| `source_rpc_urls.<chain>` | Fork from a different endpoint than the read path (otherwise `[rpc_urls]`). |
| `hardfork` | Overridden by `[mcp].fork_hardfork`. |

### Other sections

| Section | Keys | Notes |
|---|---|---|
| `[tenderly]` | `account`, `project`, `api_key_env` | Optional simulation backend. Rejected by the read-only build. |
| `[dev_rpc_urls]` | `<chain> = url` | Targets for `target: "fork"` practice runs in dev mode. |
| `[bridges]` | `cctp_v2.domains`, `lz_v2.endpoints`, `across_v4.spoke_pools` (maps keyed by chain) | makinaX `BridgesConfig`. |
| `[packages]` | `catalog_url`, `dir` (the state directory's `packages/` unless set), `layer_retirement_date`, `trusted_curators.<id> = address`, `private_beta` (whether a fresh install needs an access code), `billing_url` | The default catalog is the curator service at feed.dialectic.com. `billing_url` unset: Dialectic's billing service when the catalog is Dialectic's, none otherwise (from 0.1.9); `""` turns billing off; an address that isn't https is refused at start (plain http only for this computer). The Dialectic curator pin ships compiled in; `trusted_curators` adds pins or overrides a shipped one. See [Packages for curators](https://docs.orbit.dialectic.com/0.1.9/contributing/packages-for-curators/). |
| `[compose]` | `integrations_dir`, `integrations_ref`, `integrations_repo` | Optional. Without it, Orbit stages Makina's public integrations catalog at its reviewed ref into `<state>/integrations/<owner>/<repo>/` the first time it composes. Set it only to pin another ref or use your own checkout. |
| `[modules]` | `source` (`"orbit_provider"` or `"makina"`), `[modules.networks.<name>] source` for one network | From 0.1.9. Unset, or `"orbit_provider"`: new modules come through Orbit's own module provider where Orbit records one for the network and its code is the build Orbit was made for, and from Makina's factory elsewhere. `"makina"` is the opt-out: new modules come from Makina's factory, as before 0.1.9. A wallet that has a module keeps it. Unknown keys refuse the load. `health_check` → `module_sources` shows what each network resolves to. |
| `[owner_targets]` | `enabled` | Owner-added transfer recipients. Off: `add_owner_target` refuses and compose ignores the store. |

## Applying a change: reload or restart

A running Orbit (the acting server, an observing one, and `owner-serve`) checks the content digest of its own config file every `poll_interval_s` and, when it changed, runs the same `apply_refresh` as the `refresh_state` tool (`src/tools/config_watch.rs`). The check skips a tick, rather than waiting, when a setup step, a send or a config write holds its lock. A reload that fails keeps the previous settings and is not retried until the file changes again.

Everything reloads in place, including `[signer]` (the wallet is rebuilt; if the new one fails to build, the previous signer stays and the reply says so), rootfiles (with the pin re-checked) and package records. These need a restart and are reported under `requires_restart`:

| Key | Why |
|---|---|
| `[owner]` | The owner page is a bound listener. |
| `[tenderly]` | The client is built once at startup. |
| `mcp.position_index_db`, `mcp.audit_log` | Open files. |

The comment in `example.config.toml` that lists `[signer]` as restart-only is stale.

A config change made from a shell (`orbit-mcp <tool> …` is its own process) reaches the long-running server through this watcher, not instantly.

## The state directory

`~/.orbit` unless `ORBIT_STATE_DIR` relocates it (an empty value is ignored). Code must resolve paths through `Settings::state_dir()`, never the process-global `settings::state_dir()`, except at process entry points. `scripts/state-dir-isolation.sh` enforces this (see [Build and test](https://docs.orbit.dialectic.com/0.1.9/contributing/build-and-test/)).

| Path | What it holds |
|---|---|
| `positions.db` | SQLite ledger (`src/indexer/store.rs`). Tables: `positions`, `checkpoints`, `snapshots`, `executions`, `events`, `operations`, `operation_attempts`, `bridge_absence`, `policy_spend`, `policy_reservations`, `pending_confirmations`, `mandate_proposals`, `mandate_proposal_metadata`, `mandate_activation_journal`, `bleed_observations`, `breaker_trips`, `token_metadata`, `interface_detection`, `runtime_flags`. `orbit-mcp repair-database [--compact]` rebuilds or compacts it (stop Orbit first). |
| `audit.jsonl` | Append-only audit log. |
| `owner-token` | Owner page bearer token (0600). |
| `keystore/` | `operator.json`, `guardian.json` (encrypted keystores). |
| `mandates/` | `global.toml` (the active mandate), `global-floor.toml` (version floor that outlives a rollback), per-Safe slots. |
| `packages/` | Installed-package registry, one JSON file per Safe. |
| `credentials/` | Curator feed credentials, `<curator>__<safe>.json`. A sibling of `packages/`, never inside it. |
| `calibers/` | Persisted composition source per Safe (`<safe>.json`) with the root it last produced. |
| `integrations/` | Staged integrations catalogs at pinned refs. |
| `quick-setup/`, `onboarding-route/` | Onboarding progress, re-read on every run. |
| `sim-receipts/` | Simulation receipts shared between Orbit processes. |
| `cctp-claims/` | CCTP claim journal. |
| `migrations/` | Migration snapshots and batches. |
| `heartbeats/` | Liveness files read by `health_check`. |
| `module-settings-reviews/`, `subscription-collection/`, `safe-labels/` | Owner-page review drafts, billing collection records, Safe labels. |
| `watchdog-runtime/` | `watchdog.toml` (generated by onboarding), `cycle.json` (last cycle, scopes, health), `runtime.lock`, `startup.lock`. |
| `bin/`, `share/` | Self-update install of binaries and shipped docs and guides. |

### Locks

| File | Purpose |
|---|---|
| `kit.lock` (+ `.kit.lock.guard`) | One acting Orbit per state directory (`src/single_instance.rs`). A second process runs observe-only: no pollers, no CCTP claim signing, no owner page; reads, simulations and CLI calls work. It promotes itself on `health_check` once the holder exits. |
| `owner-endpoint.lock` | The owner page listener. |
| `send.lock` | Cross-process advisory lock taken only around signing and broadcasting, inside the in-process `send_lock`, so a shell one-shot beside a server takes its turn (`src/writes/send_gate.rs`). |
| `policy.lock` | Serialises policy budget reservation across processes. |

## Environment variables

| Variable | Effect |
|---|---|
| `XDG_CONFIG_HOME` | Moves the config to `$XDG_CONFIG_HOME/orbit/config.toml`. |
| `ORBIT_STATE_DIR` | Moves the state directory. |
| `ORBIT__<SECTION>__<KEY>` | Overrides any config key. |
| `ORBIT_KEYSTORE_PASSPHRASE` | Passphrase for `keystore-create` (then piped stdin, then a generated 0600 file on a box with no terminal, else a prompt). |
| `ORBIT_SHARE_DIR` | Where shipped docs and guides are found; otherwise derived from the binary's location. |
| `ORBIT_TX_SERVICE_URL` | Overrides the [Safe transaction service](https://docs.safe.global/core-api/transaction-service-overview) host. Deliberately an env seam, not a config key. |
| `ORBIT_SAFE_SERVICE_TOKEN_FILE`, `ORBIT_SAFE_SERVICE_ORIGIN` | Safe service credentials for this instance. |
| `ORBIT_ACCESS_CODE` | The Orbit access code for `orbit-mcp onboard` / `quick-setup` with no terminal to ask in. A `--access-code` flag wins, but ends up in shell history. |
| `ORBIT_ONBOARDING_CAPABILITIES` | Tells onboarding how the host can reach a browser (advisory). |
| `ORBIT_LOAD_CHECK` | List-only mode: answers `initialize` and `tools/list`, refuses every call, reads no config, takes no lock. |
| `ORBIT_SEVERITY_OVERRIDE` | Dev only; ignored, with a warning, outside `--dev`. |
| `RUST_LOG` | Log filter (logs go to stderr; stdout is the MCP wire). `RUST_LOG=orbit_timing=debug` shows read timings. |

Variables starting `ORBIT_TEST_`, `ORBIT_E2E_` and the Hyperliquid URL overrides are test seams; the Hyperliquid ones accept only loopback URLs.

## The watchdog config

`orbit-watchdog` is a separate binary (write build only) with its own config and its own guardian key. It shares no process, key or config with Orbit. Run it with:

```sh
orbit-watchdog --config /path/to/watchdog.toml
```

Onboarding generates `<state>/watchdog-runtime/watchdog.toml`; `packaging/watchdog.example.toml` is the hand-written template. Schema is `WatchdogConfig` in `src/watchdog_config.rs`, with `deny_unknown_fields`, so a misspelled key is an error.

The shipped `watchdog.example.toml` (`share/` in the release archive) shows the keys; `WatchdogConfig` in `src/watchdog_config.rs` is the complete list. The values in effect are the ones in the watchdog's own config file (`<state>/watchdog-runtime/watchdog.toml` when onboarding generated it); `get_watchdog_settings` reads them.

| Key | Meaning |
|---|---|
| `[rpc_urls]` | Required. Same `Endpoints` semantics as Orbit. |
| `[safes.<name>]` | Required. `chain`, `module`, `safe` only. `[machines.*]` is accepted as a deprecated alias. |
| `[guardian]` | Required. Same signer schema as `[signer]`. The only key material in the file; never the operator key. |
| `[circuit_breaker]` | Should mirror the mandate's `[circuit_breaker]`; see below. |
| `max_window_loss` | Absolute cumulative window loss in human accounting-currency units (not base units). Absent: the cumulative trigger is off; strikes stay armed. The mandate's `max_window_loss_bps_of_nav` does not apply because the watchdog cannot compute NAV. |
| `poll_interval_s` | How often the watchdog checks. |
| `webhook_url` | Receives a JSON trip report `{machine, reason, evidence, pause_tx}` on pause. |
| `supervisor` | `systemd:<unit>` or `launchd:<label>`; declared, never inferred. |
| `state_dir` | State directory for runtime records. |

`[circuit_breaker]` keys are `bleed_threshold` (must be in (0, 1]), `window_cooldown_multiple`, `max_bleeding_actions` and `retrip_escalation_window_s`; the owner's values are in the active mandate's `[circuit_breaker]`. When it trips, the watchdog calls `pause()` on the module with the guardian key.
