aion_server/config/sections.rs
1//! Typed `[section]` sub-configurations that make up [`ServerConfig`].
2//!
3//! Each struct/enum here maps one `[section]` (or nested value) of the server
4//! TOML surface, with its `serde` attributes, `Default` impl, and the small
5//! amount of per-section validation that belongs with the type
6//! ([`WebSocketConfig::validate`]). They are re-exported from the `config`
7//! module so every existing `crate::config::X` path resolves identically.
8//!
9//! [`ServerConfig`]: super::ServerConfig
10
11use std::{net::SocketAddr, path::PathBuf, time::Duration};
12
13use serde::Deserialize;
14
15use crate::error::ServerError;
16
17use super::{
18 config_error,
19 defaults::{
20 CLUSTER_BROADCAST_CAPACITY_REQUIRED, DEFAULT_GRPC_ADDRESS, DEFAULT_HTTP_ADDRESS,
21 DEFAULT_MAX_IN_FLIGHT_ACTIVITIES, DEFAULT_OBSERVABILITY_MAX_EVENT_BYTES,
22 DEFAULT_OBSERVABILITY_MAX_STREAM_EVENTS, EVENT_BROADCAST_CAPACITY_REQUIRED,
23 OBSERVABILITY_MAX_EVENT_BYTES_REQUIRED, OBSERVABILITY_MAX_STREAM_EVENTS_REQUIRED,
24 },
25};
26
27/// Public transport listener addresses from `[server]`.
28#[derive(Clone, Debug, Deserialize)]
29#[serde(default, deny_unknown_fields)]
30pub struct ServerSection {
31 /// HTTP/JSON and dashboard listener.
32 pub listen_address: SocketAddr,
33 /// gRPC API and worker-protocol listener.
34 pub grpc_address: SocketAddr,
35 /// Browser origins allowed to make cross-origin (CORS) requests to the
36 /// public HTTP API. Empty (the default) is the SECURE default: no
37 /// cross-origin request is permitted and no `CorsLayer` is installed, so a
38 /// same-origin deployment behaves byte-identically to before this field
39 /// existed. When set, each entry is an exact origin (scheme + host + port,
40 /// e.g. `http://localhost:5173`) the browser dashboard is served from; the
41 /// router then answers preflight and emits `Access-Control-Allow-Origin`
42 /// for exactly those origins. There is no wildcard/allow-all default
43 /// (ADR-001): cross-origin access is an explicit operator decision, and the
44 /// layer never pairs `Any` with credentials.
45 #[serde(default)]
46 pub cors_allowed_origins: Vec<String>,
47}
48
49/// Supported event-store backend names.
50#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
51#[serde(rename_all = "lowercase")]
52pub enum StoreBackend {
53 /// In-memory store for local development.
54 Memory,
55 /// libSQL durable store.
56 LibSql,
57 /// haematite durable store (single-node, shardable).
58 Haematite,
59}
60
61/// Event-store backend configuration from `[store]`.
62#[derive(Clone, Debug, Deserialize)]
63#[serde(default, deny_unknown_fields)]
64pub struct StoreConfig {
65 /// Selected backing store implementation.
66 pub backend: StoreBackend,
67 /// Backend URL/path. For libSQL this is the embedded database path; for memory it is ignored.
68 pub url: Option<String>,
69 /// Static distribution-shard assignment for this node (multi-shard
70 /// active-active). When empty (the default) the node owns ALL shards — the
71 /// single-node default, byte-identical to today. When set, the engine boot
72 /// path scopes recovery and enumeration to exactly these shards. Single-shard
73 /// backends (memory, libSQL) ignore the assignment; it is meaningful only for
74 /// a sharded backend. No election is performed: assignment is static config.
75 pub owned_shards: Vec<usize>,
76 /// Filesystem data directory for the haematite backend. Required when
77 /// `backend = haematite`; ignored by every other backend. The directory is
78 /// opened if it already holds a haematite database, otherwise created.
79 pub data_dir: Option<String>,
80 /// Number of haematite shards to create on a fresh database. Defaults to 64.
81 ///
82 /// This is an IMMUTABLE virtual-shard count: nodes own shard *ranges* and
83 /// routing is `BLAKE3(key) % shard_count` with no reshard path, so a
84 /// single-node deployment can later grow into a cluster WITHOUT a data
85 /// migration — but only up to `shard_count` nodes, and the value is fixed
86 /// at create.
87 ///
88 /// The default was briefly 4096 on the premise that lazy shard-actor
89 /// materialization (haematite >= 0.4.0) made a high count ~free. That
90 /// premise fails in practice (#187): aion-server's boot restores
91 /// packages/routes/namespaces via full-prefix scans, which materialize
92 /// EVERY shard, and haematite 0.4.0 then fans each commit out to every
93 /// materialized shard with an unconditional fsync — ~2 fsyncs x 4096 per
94 /// logical commit — blowing the 5s shard-actor timeout and bricking
95 /// deploy/start/timers/outbox on a fresh server. Re-raise only after
96 /// haematite makes commit O(dirty shards) and the scaffold e2es pass at
97 /// the new default. Set explicitly (config or `AION_STORE_SHARD_COUNT`)
98 /// to override. Ignored by every other backend, and ignored when opening
99 /// an existing haematite database (the on-disk shard count wins).
100 pub shard_count: usize,
101 /// Optional distributed-cluster membership for the haematite backend (SS-2).
102 ///
103 /// Absent (the default) selects the SINGLE-NODE haematite path, byte-identical
104 /// to today: no endpoint is bound, no shard is elected, the store owns
105 /// everything locally. Present selects the DISTRIBUTED path: the boot path
106 /// binds a replication endpoint, builds a quorum membership from `members` +
107 /// `peers`, and the engine boot path elects (`acquire_shard_and_serve`) this
108 /// node's `owned_shards` before recovery. Ignored by every non-haematite
109 /// backend.
110 pub cluster: Option<ClusterConfig>,
111}
112
113/// Distributed-cluster membership for the haematite backend, from `[store.cluster]`.
114///
115/// This is the minimal, well-defaulted seam that turns the single-node haematite
116/// store into a distributed one (SS-2). A "cluster of one" — `node_id` set,
117/// `members` either empty or naming only `node_id`, and no `peers` — is a valid,
118/// non-flaky configuration: election self-quorums (quorum denominator 1) and the
119/// node boots through the production builder as the fenced owner of its shards.
120#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
121#[serde(deny_unknown_fields)]
122pub struct ClusterConfig {
123 /// This node's globally-unique distribution name (e.g. `node-0@127.0.0.1`).
124 /// Used as the local endpoint name and the local membership identity.
125 pub node_id: String,
126 /// The replication endpoint listen address this node binds for peer
127 /// quorum/election traffic (e.g. `127.0.0.1:7000`).
128 pub bind_address: SocketAddr,
129 /// The FULL cluster membership by node id — the quorum DENOMINATOR. Never the
130 /// reachable subset. May be empty or omit peers for a cluster of one, in which
131 /// case it is treated as `[node_id]` (denominator 1). `node_id` is always
132 /// counted in the denominator whether or not it appears here.
133 #[serde(default)]
134 pub members: Vec<String>,
135 /// Dialable peers (name + address) this node connects to for replication. A
136 /// cluster of one leaves this empty. Peers not in `members` do not inflate the
137 /// quorum denominator.
138 #[serde(default)]
139 pub peers: Vec<ClusterPeer>,
140 /// SS-5b automatic-failover poll interval in milliseconds: how often the
141 /// cluster supervisor checks each watched peer's replication liveness.
142 /// Defaults to [`DEFAULT_FAILOVER_POLL_INTERVAL_MS`] when omitted.
143 ///
144 /// [`DEFAULT_FAILOVER_POLL_INTERVAL_MS`]: super::DEFAULT_FAILOVER_POLL_INTERVAL_MS
145 #[serde(default)]
146 pub failover_poll_interval_ms: Option<u64>,
147 /// SS-5b debounce: the number of CONSECUTIVE polls a peer must be observed
148 /// disconnected before its shards are adopted, so a transient blip does not
149 /// trigger a disruptive failover. Defaults to
150 /// [`DEFAULT_FAILOVER_CONFIRMATIONS`] when omitted; must be at least one.
151 ///
152 /// [`DEFAULT_FAILOVER_CONFIRMATIONS`]: super::DEFAULT_FAILOVER_CONFIRMATIONS
153 #[serde(default)]
154 pub failover_confirmations: Option<u32>,
155}
156
157/// One dialable cluster peer: its distribution name and replication address.
158#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
159#[serde(deny_unknown_fields)]
160pub struct ClusterPeer {
161 /// The peer's globally-unique distribution name (matches its `node_id`).
162 pub name: String,
163 /// The peer's replication endpoint address to dial.
164 pub address: SocketAddr,
165 /// The peer's gRPC client-API address, for request forwarding (R-2/R-3).
166 /// This is DISTINCT from `address` (the replication/quorum endpoint): a
167 /// forwarded client `signal`/`query`/`cancel` is dialed here, not on the
168 /// replication port. Absent (the default) means the peer is not
169 /// forwardable — its shards still resolve to a remote owner, but routing
170 /// falls back to returning the typed `NotOwner` instead of forwarding (R-3).
171 #[serde(default)]
172 pub grpc_address: Option<SocketAddr>,
173 /// The distribution shards this peer owns. Empty (the default) means the
174 /// operator did not declare the peer's shards, so the SS-5b cluster
175 /// supervisor cannot adopt them automatically when the peer dies — automatic
176 /// failover for a peer requires its `owned_shards` to be declared here so the
177 /// survivor knows exactly which shards to elect + resume. Declaring them does
178 /// not change replication or quorum; it only tells the supervisor what to
179 /// adopt on this peer's death.
180 #[serde(default)]
181 pub owned_shards: Vec<usize>,
182}
183
184/// Engine runtime settings from `[runtime]`.
185#[derive(Clone, Debug, Deserialize)]
186#[serde(default, deny_unknown_fields)]
187pub struct RuntimeSection {
188 /// Number of scheduler worker threads.
189 pub scheduler_threads: usize,
190 /// Engine reply deadline for workflow queries, in milliseconds.
191 /// REQUIRED — the server always mounts `/workflows/query`, so the query
192 /// reply deadline must be an explicit operator decision; there is no
193 /// default. The engine builder is equally explicit-no-default.
194 pub query_timeout_ms: Option<u64>,
195}
196
197/// Graceful drain settings from `[drain]`.
198#[derive(Clone, Debug, Deserialize)]
199#[serde(default, deny_unknown_fields)]
200pub struct DrainConfig {
201 /// Maximum drain duration in seconds.
202 pub timeout_seconds: u64,
203}
204
205/// Authentication configuration applied at adapter boundaries.
206#[derive(Clone, Debug, Deserialize)]
207#[serde(default, deny_unknown_fields)]
208pub struct AuthConfig {
209 /// Whether authentication is enabled.
210 pub enabled: bool,
211 /// JWKS URL used by AO-006 auth validation.
212 pub jwks_url: Option<String>,
213 /// JWKS refresh interval in seconds.
214 pub jwks_refresh_seconds: u64,
215}
216
217/// Metrics endpoint settings from `[metrics]`.
218#[derive(Clone, Debug, Deserialize)]
219#[serde(default, deny_unknown_fields)]
220pub struct MetricsConfig {
221 /// Whether metrics are exposed.
222 pub enabled: bool,
223}
224
225/// Namespace defaults from `[namespaces]`.
226#[derive(Clone, Debug, Deserialize)]
227#[serde(default, deny_unknown_fields)]
228pub struct NamespacesConfig {
229 /// Default namespace used for local callers and worker dispatch.
230 pub default: String,
231 /// Minted-on-use policy: whether referencing an unseen namespace at worker
232 /// registration durably mints it ([`AutoCreate::Open`], the zero-config
233 /// default) or is rejected ([`AutoCreate::Closed`]).
234 pub auto_create: AutoCreate,
235 /// Platform-wide default for a namespace's **cluster-wide** concurrent
236 /// in-flight-activity ceiling, applied when a namespace record carries no
237 /// explicit `max_in_flight_activities` override (Control-Plane Phase 2,
238 /// P2-Q1). This is the GENEROUS platform default, NOT a low hard cap: it is
239 /// a cluster-wide tenant contract (never "per-node × N"), so a tenant is
240 /// promised ≈this many concurrent activities across the whole cluster.
241 /// Defaults to [`DEFAULT_MAX_IN_FLIGHT_ACTIVITIES`].
242 ///
243 /// **Stored-only in this slice.** Nothing enforces it yet — the outbox
244 /// dispatcher's keyed backpressure (P2-Q2) consults it in a later slice.
245 ///
246 /// [`DEFAULT_MAX_IN_FLIGHT_ACTIVITIES`]: super::DEFAULT_MAX_IN_FLIGHT_ACTIVITIES
247 pub max_in_flight_activities: u32,
248}
249
250/// Minted-on-use namespace policy (Control-Plane Phase 1).
251///
252/// Governs what happens when a worker registers for a namespace that has no
253/// durable registry record. Defaults to [`AutoCreate::Open`] to preserve the
254/// zero-ceremony, no-pre-provision model: a namespace comes into being on first
255/// reference.
256#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Eq)]
257#[serde(rename_all = "snake_case")]
258pub enum AutoCreate {
259 /// A worker registering for an unseen namespace durably mints it (an
260 /// idempotent upsert through the registry). Zero-config default.
261 #[default]
262 Open,
263 /// A worker registering for a namespace with no durable registry record is
264 /// rejected; the namespace is never created at the registration hook. The
265 /// escape hatch for locked-down deployments is an explicit create
266 /// (`POST /namespaces`).
267 Closed,
268}
269
270/// Public transport listener addresses retained for existing adapter code.
271#[derive(Clone, Debug, Deserialize)]
272#[serde(default, deny_unknown_fields)]
273pub struct ListenConfig {
274 /// gRPC API and worker-protocol listener.
275 pub grpc: SocketAddr,
276 /// HTTP/JSON and dashboard listener.
277 pub http: SocketAddr,
278}
279
280/// TLS certificate and private-key material.
281#[derive(Clone, Debug, Deserialize)]
282#[serde(deny_unknown_fields)]
283pub struct TlsConfig {
284 /// Certificate chain path supplied by the operator.
285 pub certificate_chain_path: PathBuf,
286 /// Private-key path supplied by the operator.
287 pub private_key_path: PathBuf,
288}
289
290/// Static ops-console asset configuration.
291#[derive(Clone, Debug, Deserialize)]
292#[serde(default, deny_unknown_fields)]
293pub struct OpsConsoleConfig {
294 /// Operator-selected bundle source.
295 pub source: OpsConsoleAssetSource,
296}
297
298/// Static ops-console bundle source.
299#[derive(Clone, Debug, Deserialize)]
300pub enum OpsConsoleAssetSource {
301 /// Serve the built bundle from an operator-supplied directory.
302 FileSystem {
303 /// Directory containing `index.html` and built asset files.
304 asset_path: PathBuf,
305 },
306 /// Serve the compile-time embedded bundle.
307 Embedded,
308}
309
310/// Namespace resolver construction mode.
311#[derive(Clone, Debug, Deserialize)]
312#[serde(default, deny_unknown_fields)]
313pub struct NamespaceConfig {
314 /// Deployment-selected namespace mapping mode.
315 pub mode: NamespaceMode,
316}
317
318/// Supported namespace mapping modes.
319#[derive(Clone, Debug, Deserialize)]
320pub enum NamespaceMode {
321 /// All authorized namespaces share the configured engine instance.
322 SharedEngine,
323 /// Namespace authorization is disabled only for single-tenant deployments.
324 SingleTenant {
325 /// The only namespace accepted by the deployment.
326 namespace: String,
327 },
328}
329
330/// Remote worker heartbeat configuration.
331#[derive(Clone, Debug, Deserialize)]
332#[serde(default, deny_unknown_fields)]
333pub struct WorkerConfig {
334 /// Window after which a silent worker is considered lost.
335 #[serde(with = "duration_millis")]
336 pub heartbeat_window: Duration,
337}
338
339/// WebSocket stream configuration.
340#[derive(Clone, Debug, Deserialize)]
341#[serde(default, deny_unknown_fields)]
342pub struct WebSocketConfig {
343 /// Per-connection outbound buffer bound.
344 pub outbound_buffer_bound: usize,
345 /// Capacity of the engine-global event broadcast channel that backs
346 /// `/events/stream`. REQUIRED — the server always mounts the streaming
347 /// endpoint, so streaming capacity must be an explicit operator decision;
348 /// there is no default. Lag is filter-blind, so size this for global event
349 /// volume across all namespaces, not per-subscription volume.
350 pub event_broadcast_capacity: Option<usize>,
351 /// Capacity of the deployment-global cluster topology/ownership broadcast
352 /// channel that backs the WS3 `cluster` subscription on `/events/stream`.
353 /// REQUIRED with the same non-zero startup guard as
354 /// [`Self::event_broadcast_capacity`]: the cluster channel uses the same
355 /// lag -> one-error-frame -> close contract, which has no defined buffer to
356 /// lag against unless a capacity is configured. Cluster events are low-rate
357 /// (peer/shard/worker topology deltas), so this is typically far smaller
358 /// than the workflow event capacity.
359 pub cluster_broadcast_capacity: Option<usize>,
360}
361
362impl WebSocketConfig {
363 /// Validate the three unconditionally-mounted WebSocket seams: the
364 /// per-connection buffer bound, the workflow event broadcast capacity, and
365 /// the WS3 cluster broadcast capacity. The two broadcast capacities are
366 /// explicit-no-default with a non-zero guard, since both back a lag ->
367 /// one-error-frame -> close contract that needs a defined buffer to lag
368 /// against.
369 pub(super) fn validate(&self) -> Result<(), ServerError> {
370 if self.outbound_buffer_bound == 0 {
371 return config_error("websocket.outbound_buffer_bound must be greater than zero");
372 }
373 match self.event_broadcast_capacity {
374 None | Some(0) => return config_error(EVENT_BROADCAST_CAPACITY_REQUIRED),
375 Some(_) => {}
376 }
377 match self.cluster_broadcast_capacity {
378 None | Some(0) => return config_error(CLUSTER_BROADCAST_CAPACITY_REQUIRED),
379 Some(_) => {}
380 }
381 Ok(())
382 }
383}
384
385/// Agent-observability transcript retention bounds from `[observability]`.
386///
387/// Both knobs default (a minimal/empty config boots) and both guard the durable
388/// `O` keyspace against unbounded growth: `max_event_bytes` truncates one
389/// oversized transcript event before it is persisted, and `max_stream_events`
390/// caps how many events one `(workflow, activity, attempt)` stream retains
391/// (one marker record is persisted at the cap; live streaming continues).
392#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq)]
393#[serde(default, deny_unknown_fields)]
394pub struct ObservabilityConfig {
395 /// Ceiling on one persisted transcript event's serialized size, bytes.
396 pub max_event_bytes: usize,
397 /// Ceiling on retained events per `(workflow, activity, attempt)` stream.
398 pub max_stream_events: u64,
399}
400
401impl ObservabilityConfig {
402 /// Validate the retention bounds: both must be positive — a zero event
403 /// ceiling truncates every event to nothing and a zero stream cap retains
404 /// no transcript at all, so each is a genuine misconfiguration caught at
405 /// startup with an operator-facing message (the `WebSocketConfig` pattern).
406 pub(super) fn validate(&self) -> Result<(), ServerError> {
407 if self.max_event_bytes == 0 {
408 return config_error(OBSERVABILITY_MAX_EVENT_BYTES_REQUIRED);
409 }
410 if self.max_stream_events == 0 {
411 return config_error(OBSERVABILITY_MAX_STREAM_EVENTS_REQUIRED);
412 }
413 Ok(())
414 }
415}
416
417impl Default for ObservabilityConfig {
418 fn default() -> Self {
419 Self {
420 max_event_bytes: DEFAULT_OBSERVABILITY_MAX_EVENT_BYTES,
421 max_stream_events: DEFAULT_OBSERVABILITY_MAX_STREAM_EVENTS,
422 }
423 }
424}
425
426/// Operator deploy API settings from `[deploy]`.
427///
428/// The deploy surface is dark by default: with `enabled = false` (or the
429/// section absent) neither the `/deploy/*` HTTP routes nor the gRPC
430/// `DeployService` are mounted, so a workflow server that is not a deploy
431/// target exposes no deploy attack surface at all.
432#[derive(Clone, Debug, Default, Deserialize)]
433#[serde(default, deny_unknown_fields)]
434pub struct DeployConfig {
435 /// Whether the deploy surface is mounted. Defaults to false.
436 pub enabled: bool,
437 /// Upload-size ceiling for `.aion` archives, in bytes. Defaults to
438 /// [`DEFAULT_DEPLOY_MAX_ARCHIVE_BYTES`] when omitted and `enabled = true`,
439 /// so turning deploy on does not force sizing a security ceiling; the
440 /// operator overrides it for their packages.
441 ///
442 /// [`DEFAULT_DEPLOY_MAX_ARCHIVE_BYTES`]: super::DEFAULT_DEPLOY_MAX_ARCHIVE_BYTES
443 pub max_archive_bytes: Option<u64>,
444 /// Inflate ceiling for uploaded archive contents, in bytes: the total
445 /// decompressed size of all archive entries an upload may extract to
446 /// (DEFLATE bombs inflate ~1000:1 past `max_archive_bytes`). Defaults to
447 /// [`DEFAULT_DEPLOY_MAX_INFLATED_BYTES`] when omitted and `enabled = true`;
448 /// must be at least `max_archive_bytes`.
449 ///
450 /// [`DEFAULT_DEPLOY_MAX_INFLATED_BYTES`]: super::DEFAULT_DEPLOY_MAX_INFLATED_BYTES
451 pub max_inflated_bytes: Option<u64>,
452}
453
454/// Local dev-server surface settings from `[dev]`.
455///
456/// The dev surface is dark by default, gated on `enabled`: with it false (the
457/// section absent or `enabled = false`) the `/dev/*` routes are not mounted,
458/// the engine installs the bare production activity dispatcher (no mocking
459/// decorator), and nothing dev-specific is ever reachable. Setting `enabled =
460/// true` mounts the dev endpoints and installs the per-run activity-mock
461/// decorator — a development affordance, never on in production. It adds no
462/// arbitrary defaults (ADR-001): the only knob is the on/off gate.
463#[derive(Clone, Debug, Default, Deserialize)]
464#[serde(default, deny_unknown_fields)]
465pub struct DevConfig {
466 /// Whether the local dev-server surface is mounted. Defaults to false.
467 pub enabled: bool,
468}
469
470/// Durable-outbox fan-out dispatcher settings from `[outbox]`.
471///
472/// The outbox dispatcher is dark by default, gated on `enabled`: with it false
473/// (the section absent or `enabled = false`) the non-replayed background task
474/// that claims pending outbox rows and dispatches them to connected workers is
475/// never spawned, so default server behaviour is unchanged and the live
476/// workflow dispatch path is the only dispatch path. Setting `enabled = true`
477/// commissions the dispatcher; its operational knobs below — poll interval,
478/// claim batch size, retry budget, and the backoff curve — are pure tuning, so
479/// each resolves to a sane default when omitted rather than forcing the
480/// operator to hand-author tuning values just to turn the feature on. An
481/// explicitly set value (including a misconfigured `0`) is still validated.
482///
483/// Scope: this Phase-2 dispatcher dispatches claimed rows and marks each row's
484/// terminal outbox state (done / retry / failed). Routing the worker completion
485/// back into workflow history through the Recorder is Phase 3 and is not wired
486/// here; with the flag off there is no behavioural difference at all.
487#[derive(Clone, Debug, Default, Deserialize)]
488#[serde(default, deny_unknown_fields)]
489pub struct OutboxConfig {
490 /// Whether the outbox dispatcher background task is spawned. Defaults to
491 /// false, leaving the dispatcher dark and server behaviour unchanged.
492 pub enabled: bool,
493 /// Interval between successive claim sweeps, in milliseconds. Defaults to
494 /// [`DEFAULT_OUTBOX_POLL_INTERVAL_MS`] when omitted and `enabled = true`;
495 /// override to size the poll cadence for fan-out volume and latency budget.
496 ///
497 /// [`DEFAULT_OUTBOX_POLL_INTERVAL_MS`]: super::DEFAULT_OUTBOX_POLL_INTERVAL_MS
498 pub poll_interval_ms: Option<u64>,
499 /// Maximum number of pending rows claimed per sweep. Defaults to
500 /// [`DEFAULT_OUTBOX_BATCH_SIZE`] when omitted and `enabled = true`.
501 ///
502 /// [`DEFAULT_OUTBOX_BATCH_SIZE`]: super::DEFAULT_OUTBOX_BATCH_SIZE
503 pub batch_size: Option<u32>,
504 /// Dispatch attempts before a row is dead-lettered to `failed`. Defaults to
505 /// [`DEFAULT_OUTBOX_MAX_ATTEMPTS`] when omitted and `enabled = true`. Must
506 /// be at least one.
507 ///
508 /// [`DEFAULT_OUTBOX_MAX_ATTEMPTS`]: super::DEFAULT_OUTBOX_MAX_ATTEMPTS
509 pub max_attempts: Option<u32>,
510 /// Base retry backoff applied to the first retry, in milliseconds. Defaults
511 /// to [`DEFAULT_OUTBOX_BACKOFF_BASE_MS`] when omitted and `enabled = true`.
512 /// Successive retries multiply this by `backoff_multiplier` raised to the
513 /// prior-attempt count, capped at `backoff_max_ms`.
514 ///
515 /// [`DEFAULT_OUTBOX_BACKOFF_BASE_MS`]: super::DEFAULT_OUTBOX_BACKOFF_BASE_MS
516 pub backoff_base_ms: Option<u64>,
517 /// Geometric growth factor applied to the backoff per prior attempt.
518 /// Defaults to [`DEFAULT_OUTBOX_BACKOFF_MULTIPLIER`] when omitted and
519 /// `enabled = true`. Must be at least one so backoff never shrinks.
520 ///
521 /// [`DEFAULT_OUTBOX_BACKOFF_MULTIPLIER`]: super::DEFAULT_OUTBOX_BACKOFF_MULTIPLIER
522 pub backoff_multiplier: Option<u32>,
523 /// Upper bound on a single retry's backoff, in milliseconds. Defaults to
524 /// [`DEFAULT_OUTBOX_BACKOFF_MAX_MS`] when omitted and `enabled = true`. Must
525 /// be at least `backoff_base_ms`.
526 ///
527 /// [`DEFAULT_OUTBOX_BACKOFF_MAX_MS`]: super::DEFAULT_OUTBOX_BACKOFF_MAX_MS
528 pub backoff_max_ms: Option<u64>,
529 /// Interval between live stale-claim reconciliation sweeps, in milliseconds. When both
530 /// reconciliation knobs are absent the live sweep remains dark; setting either knob opts into
531 /// reconciliation and requires both values to be positive.
532 pub reconcile_interval_ms: Option<u64>,
533 /// Age after which a durable `claimed` outbox row is considered stranded, in milliseconds. The
534 /// reconciler re-arms only rows with `claimed_at` older than this threshold, preserving their
535 /// attempt count.
536 pub reconcile_stale_after_ms: Option<u64>,
537 /// Wire transport the dispatcher uses to place a claimed row with a worker.
538 /// Defaults to [`OutboxTransport::Liminal`] whenever the `liminal-transport`
539 /// Cargo feature is compiled (the default ablative-stack build), so an
540 /// outbox-enabled server uses the liminal cross-node transport out of the box;
541 /// a slim build without that feature defaults to [`OutboxTransport::Grpc`].
542 /// Selecting `liminal` in a build without the feature is a configuration error
543 /// surfaced at spawn. The transport only matters when `outbox.enabled = true`.
544 pub transport: OutboxTransport,
545 /// Address (`host:port`) the aion-server LISTENS on for inbound liminal
546 /// worker connections, used only when `transport = liminal`. REQUIRED in that
547 /// mode; ignored otherwise.
548 ///
549 /// The aion-server HOSTS the liminal listener: a remote `LiminalActivityWorker`
550 /// connects IN to this address and self-registers in-band, so the server's
551 /// [`ConnectionSupervisor`](liminal_server::server::connection::ConnectionSupervisor)
552 /// owns the worker's connection and can push a dispatch out on it
553 /// (`push_to_connection`). This replaces the superseded 13-0 spike's
554 /// client-connect address: the dispatcher no longer *connects out* to publish
555 /// to a channel — it pushes to a connected worker the server already owns.
556 ///
557 /// The dispatch *channel* is not configured here: it is derived per-row from
558 /// each row's durable `(namespace, task_queue)` via `dispatch_channel_name`
559 /// (NSTQ-5), so one listener fans different worker pools out by selection.
560 pub liminal_listen_address: Option<String>,
561}
562
563/// Wire transport selected for outbox dispatch.
564///
565/// `liminal` (the default whenever the `liminal-transport` feature is compiled —
566/// which it is in the default ablative-stack build) routes the dispatch over the
567/// liminal cross-node bus. `grpc` keeps the connected-worker registry path. A
568/// slim build compiled WITHOUT `liminal-transport` falls back to `grpc` as the
569/// default so the default is always constructible under the active feature set.
570#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Deserialize)]
571#[serde(rename_all = "lowercase")]
572pub enum OutboxTransport {
573 /// Dispatch over the in-process connected-worker gRPC registry. The default
574 /// in a slim build compiled WITHOUT `liminal-transport`, which cannot
575 /// construct the liminal path.
576 // The default variant is feature-selected: gRPC when the liminal transport is
577 // absent (it is the only constructible path), liminal otherwise.
578 #[cfg_attr(not(feature = "liminal-transport"), default)]
579 Grpc,
580 /// Dispatch over the liminal cross-node bus (requires `liminal-transport`).
581 /// The out-of-box default whenever `liminal-transport` is compiled (the
582 /// default ablative-stack feature set), so an outbox-enabled server uses the
583 /// ablative messaging transport without extra configuration.
584 #[cfg_attr(feature = "liminal-transport", default)]
585 Liminal,
586}
587
588/// Server-side authoring settings from `[authoring]`.
589///
590/// The AWL studio is on by default, rooted at `<AION_HOME>/authoring`, so a
591/// stock `aion server` provides its document, layout, check, deploy, revision,
592/// run, and scaffold surfaces without preliminary configuration. Operators can
593/// override it explicitly.
594///
595/// Only the separate Gleam authoring loop remains dark by default: without
596/// `gleam_path`, `/authoring/*` is not mounted and nothing invokes `gleam`
597/// (CN7). Setting `gleam_path` commissions that loop and makes `project_root`
598/// required.
599#[derive(Clone, Debug, Default, Deserialize)]
600#[serde(default, deny_unknown_fields)]
601pub struct AuthoringConfig {
602 /// Path to the external `gleam` binary the toolchain spawns. `None`
603 /// (the default) leaves only the Gleam authoring loop dark; setting it gates
604 /// the `/authoring/*` endpoints on. There is no default binary — the
605 /// operator names it explicitly.
606 pub gleam_path: Option<PathBuf>,
607 /// Built Gleam workflow project root submitted source is written into and
608 /// packaged from. REQUIRED when `gleam_path` is set; no default (house
609 /// rule) — a Gleam project needs `gleam.toml`, the `aion_flow` dependency,
610 /// `workflow.toml`, and `schemas/`, so the operator provisions and names
611 /// the project root.
612 pub project_root: Option<PathBuf>,
613 /// Root directory exposed by the full AWL studio surface. The merged server
614 /// loader defaults this to `<AION_HOME>/authoring` after config and
615 /// environment overlays. `authoring.workspace_dir` or
616 /// `AION_AUTHORING_WORKSPACE_DIR` therefore overrides it explicitly.
617 pub workspace_dir: Option<PathBuf>,
618}
619
620impl Default for ServerSection {
621 fn default() -> Self {
622 Self {
623 listen_address: DEFAULT_HTTP_ADDRESS,
624 grpc_address: DEFAULT_GRPC_ADDRESS,
625 cors_allowed_origins: Vec::new(),
626 }
627 }
628}
629
630impl Default for StoreConfig {
631 fn default() -> Self {
632 Self {
633 // The ablative stack is the out-of-box durable default: an empty
634 // config selects the haematite backend. The merged loader fills
635 // `<AION_HOME>/data`; `memory` (ephemeral) and `libsql`
636 // (lightweight, opt-in) remain explicit operator choices.
637 backend: StoreBackend::Haematite,
638 url: None,
639 owned_shards: Vec::new(),
640 data_dir: None,
641 // 64, NOT 4096 (#187): raising the default to 4096 bricked every
642 // fresh server — engine boot's scan_prefix materializes every
643 // shard, then each haematite 0.4.0 commit fans out one thread +
644 // fsync PER MATERIALIZED SHARD (~8k fsyncs/commit), blowing the
645 // 5s shard-actor timeout on deploy/start/timers/outbox. Re-raise
646 // only after haematite makes commit O(dirty shards) and the
647 // scaffold e2es pass at the new default (see #187 fix plan).
648 shard_count: 64,
649 cluster: None,
650 }
651 }
652}
653
654impl Default for RuntimeSection {
655 fn default() -> Self {
656 Self {
657 scheduler_threads: 1,
658 // Deliberately absent: validation fails loudly until the operator
659 // sets the workflow query reply deadline for the deployment.
660 query_timeout_ms: None,
661 }
662 }
663}
664
665impl Default for DrainConfig {
666 fn default() -> Self {
667 Self {
668 timeout_seconds: 30,
669 }
670 }
671}
672
673impl Default for AuthConfig {
674 fn default() -> Self {
675 Self {
676 enabled: false,
677 jwks_url: None,
678 jwks_refresh_seconds: 300,
679 }
680 }
681}
682
683impl Default for MetricsConfig {
684 fn default() -> Self {
685 Self { enabled: true }
686 }
687}
688
689impl Default for NamespacesConfig {
690 fn default() -> Self {
691 Self {
692 default: "default".to_owned(),
693 auto_create: AutoCreate::default(),
694 max_in_flight_activities: DEFAULT_MAX_IN_FLIGHT_ACTIVITIES,
695 }
696 }
697}
698
699impl Default for ListenConfig {
700 fn default() -> Self {
701 Self {
702 grpc: DEFAULT_GRPC_ADDRESS,
703 http: DEFAULT_HTTP_ADDRESS,
704 }
705 }
706}
707
708impl Default for OpsConsoleConfig {
709 fn default() -> Self {
710 Self {
711 source: OpsConsoleAssetSource::Embedded,
712 }
713 }
714}
715
716impl Default for NamespaceConfig {
717 fn default() -> Self {
718 Self {
719 mode: NamespaceMode::SharedEngine,
720 }
721 }
722}
723
724impl Default for WorkerConfig {
725 fn default() -> Self {
726 Self {
727 heartbeat_window: Duration::from_secs(30),
728 }
729 }
730}
731
732impl Default for WebSocketConfig {
733 fn default() -> Self {
734 Self {
735 outbound_buffer_bound: 32,
736 // Deliberately absent: validation fails loudly until the operator
737 // sizes the engine-global broadcast channel for the deployment.
738 event_broadcast_capacity: None,
739 // Deliberately absent for the same reason: the cluster channel has
740 // no defined lag buffer until sized.
741 cluster_broadcast_capacity: None,
742 }
743 }
744}
745
746mod duration_millis {
747 use std::time::Duration;
748
749 use serde::{Deserialize, Deserializer};
750
751 pub(super) fn deserialize<'de, D>(deserializer: D) -> Result<Duration, D::Error>
752 where
753 D: Deserializer<'de>,
754 {
755 let millis = u64::deserialize(deserializer)?;
756 Ok(Duration::from_millis(millis))
757 }
758}