liminal_server/error.rs
1use std::net::SocketAddr;
2
3use crate::server::participant::ParticipantServiceFatal;
4
5/// Error taxonomy for standalone liminal server deployment failures.
6#[derive(Debug, thiserror::Error)]
7pub enum ServerError {
8 /// The configuration file could not be read or parsed.
9 #[error("configuration load failed: {message}")]
10 ConfigLoad { message: String },
11
12 /// The configuration file was read but failed semantic validation.
13 #[error("configuration validation failed: {message}")]
14 ConfigValidation { message: String },
15
16 /// The server could not bind its configured listener address.
17 #[error("listener bind failed for {address}: {source}")]
18 ListenerBind {
19 /// Address the server attempted to bind.
20 address: SocketAddr,
21 /// Underlying operating-system bind failure.
22 #[source]
23 source: std::io::Error,
24 },
25
26 /// The server listener failed while accepting an inbound connection.
27 #[error("listener accept failed: {message}")]
28 ListenerAccept { message: String },
29
30 /// Durable participant-incarnation startup or allocation failed before its
31 /// result could be published.
32 #[error("participant incarnation {phase} failed: {message}")]
33 ParticipantIncarnation {
34 /// Exact server seam that failed.
35 phase: &'static str,
36 /// Underlying durable or bounded-bridge diagnostic.
37 message: String,
38 },
39
40 /// A durable connection-fate Open could not be completed in this process.
41 ///
42 /// The normal runtime shutdown path returns this typed fatal only after it has
43 /// stopped both listeners and run the ordinary connection drain/flush sequence.
44 #[error("participant service fatal: {fatal}")]
45 ParticipantServiceFatal {
46 /// First process-wide post-Open failure; later failures cannot replace it.
47 fatal: ParticipantServiceFatal,
48 },
49
50 /// Startup found durable connection-fate work that the Decision A/C producer must complete
51 /// before listener or semantic-service publication.
52 #[error(
53 "participant startup requires recovery of {open_count} connection-fate Opens beginning at sequence {first_open_sequence}"
54 )]
55 ConnectionFateRecoveryRequired {
56 /// Number of replay-validated unmatched Opens.
57 open_count: usize,
58 /// Lowest unmatched Open sequence.
59 first_open_sequence: u64,
60 },
61
62 /// The durable server-incarnation namespace has no successor.
63 #[error("participant server-incarnation namespace is exhausted")]
64 ServerIncarnationExhausted,
65
66 /// Production participant startup restore failed: the durable
67 /// conversation streams could not be scanned or replayed, so the
68 /// server-scope capacity ledger cannot be made exact and the server
69 /// refuses to start over state it cannot account for.
70 #[error("participant startup restore failed: {message}")]
71 ParticipantStartupRestore {
72 /// Underlying durable, replay, or bridge diagnostic.
73 message: String,
74 },
75
76 /// The current durable server incarnation has no collision-free connection
77 /// ordinal left, so the accepted socket was not admitted.
78 #[error(
79 "connection incarnation exhausted for server incarnation {attempted_server_incarnation}"
80 )]
81 ConnectionIncarnationExhausted {
82 /// Server incarnation whose complete ordinal suffix was examined.
83 attempted_server_incarnation: u64,
84 },
85
86 /// A connection registration found a record already present under its pid.
87 /// Enforces the pids-fresh-per-spawn supervision invariant loudly: a silent
88 /// replace would drop the displaced record's teardown-held fd guard outside
89 /// the single record-removal funnel (orphaning a live connection's stream)
90 /// and increment the `liminal_connections_active` gauge a second time with
91 /// no paired decrement. The whole registration is refused instead, leaving
92 /// the prior record — and its teardown route — intact.
93 #[error("connection registration refused: pid {pid} already has a live registry record")]
94 ConnectionPidCollision {
95 /// The connection pid that already owned a registry record.
96 pid: u64,
97 },
98
99 /// A frame requested an operation the configured services profile does not
100 /// serve (e.g. ordinary publish/subscribe/conversation traffic against the
101 /// capability-scoped worker front door). Server-internal taxonomy, not wire
102 /// vocabulary: the connection process renders it as the operation's existing
103 /// typed error frame with this error's text as the message.
104 #[error("{operation} is not supported by the {profile} services profile")]
105 UnsupportedOperation {
106 /// Human-readable description of the refused operation.
107 operation: String,
108 /// The configured services profile that refused it.
109 profile: &'static str,
110 },
111
112 /// A server→client push reply slot was dropped before a correlated reply
113 /// arrived — the connection closed (the prompt worker-death signal). Distinct
114 /// from [`Self::PushReplyTimeout`] so consumers can tell a worker that DIED
115 /// (fast failover) from one that is merely SLOW, by type rather than message.
116 #[error(
117 "push correlation {correlation_id} did not complete: the connection closed before sending a correlated push reply"
118 )]
119 PushReplyDisconnected {
120 /// Correlation id of the push whose reply will never arrive.
121 correlation_id: u64,
122 },
123
124 /// A server→client push reply did not arrive within the awaiter's timeout —
125 /// the worker is still connected but did not reply in this wait quantum. This
126 /// is BENIGN: the reply slot survives untouched and the caller may re-arm
127 /// [`PushReplyAwaiter::receive`](crate::server::connection::PushReplyAwaiter::receive)
128 /// indefinitely. It is not a worker-death signal.
129 #[error(
130 "push correlation {correlation_id} did not complete: no correlated push reply arrived within the timeout"
131 )]
132 PushReplyTimeout {
133 /// Correlation id of the push whose wait quantum elapsed.
134 correlation_id: u64,
135 },
136
137 /// A server→client push carrying an explicit reply deadline (via
138 /// [`push_to_connection_with_deadline`](crate::server::connection::ConnectionSupervisor::push_to_connection_with_deadline))
139 /// reached that deadline before a correlated reply arrived. Unlike
140 /// [`Self::PushReplyTimeout`] this is TERMINAL: the reply slot has been
141 /// removed and its §5 `max_pending_pushes_per_connection` cap admission
142 /// released. Returned PROMPTLY once the deadline is due — a `receive` call
143 /// does not hold a due expiry until its caller's quantum ends, so the
144 /// terminal outcome is independent of how the caller polls. Distinct
145 /// variant so callers classify by type, not message.
146 #[error(
147 "push correlation {correlation_id} did not complete: its reply deadline passed before a correlated push reply arrived"
148 )]
149 PushReplyExpired {
150 /// Correlation id of the push whose reply deadline passed.
151 correlation_id: u64,
152 },
153
154 /// The server could not join the configured beamr distribution cluster.
155 #[error("cluster join failed: {message}")]
156 ClusterJoin { message: String },
157
158 /// Cluster state propagation through beamr distribution failed.
159 #[error("cluster sync failed: {message}")]
160 ClusterSync { message: String },
161
162 /// Graceful shutdown did not drain within the configured timeout.
163 #[error("shutdown timed out: {message}")]
164 ShutdownTimeout { message: String },
165
166 /// Durable state could not be flushed during graceful shutdown.
167 #[error("shutdown flush failed: {message}")]
168 ShutdownFlush { message: String },
169
170 /// The health endpoint failed to start or serve requests.
171 #[error("health endpoint failed: {message}")]
172 HealthEndpoint { message: String },
173
174 /// A new connection was refused because the configured `max_connections`
175 /// cap (§5) is already reached. The listener drops the freshly accepted
176 /// stream, refusing the connection, rather than admitting an unbounded fleet.
177 #[error(
178 "connection refused: the configured max_connections limit of {limit} live connections is reached"
179 )]
180 ConnectionLimitReached {
181 /// The configured `max_connections` cap that was hit.
182 limit: usize,
183 },
184
185 /// An admission-time per-connection cap (§5) refused an operation: too many
186 /// subscriptions, conversations, in-flight pushes, or pending conversation
187 /// replies on one connection. The connection process renders it as the
188 /// operation's existing typed error frame with this text as the message.
189 #[error("{operation} refused: the per-connection {cap} limit of {limit} is reached")]
190 ConnectionCapReached {
191 /// Human-readable description of the refused operation.
192 operation: String,
193 /// The name of the cap that refused it (a `limits.*` config key).
194 cap: &'static str,
195 /// The configured cap value that was hit.
196 limit: usize,
197 },
198}