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 /// A server→client push was never queued for the wire: its encoded frame is
155 /// larger than the WHOLE of the connection's bounded outbound buffer, so no
156 /// amount of draining could ever make room for it. TERMINAL and CERTAIN — the
157 /// reply slot is removed, its §5 `max_pending_pushes_per_connection` admission
158 /// released, and the client never saw a `Push` frame for this correlation id.
159 ///
160 /// Deliberately NARROW. A frame that would fit an empty buffer but not the
161 /// current free space is CONGESTION, not a size defect: it keeps the
162 /// connection-teardown path and its retryable
163 /// [`Self::PushReplyDisconnected`] reading, because waiting is the correct
164 /// answer there. Sharing one outcome between the certain case and the
165 /// recoverable one would leave the caller unable to tell them apart — which
166 /// is the exact fault this variant exists to end. Distinct variant so callers
167 /// classify by type, not message.
168 ///
169 /// The WORDS carry the bound's value and say the bound was chosen, because a
170 /// reader who meets this without that context blames the server for a number
171 /// an operator set. Since every outbound bound now comes from
172 /// [`max_connection_outbound_bytes`](crate::config::types::LimitsConfig::max_connection_outbound_bytes),
173 /// that sentence is true on every occurrence rather than usually.
174 #[error(
175 "push correlation {correlation_id} was never sent: its {needed}-byte frame exceeds this \
176 connection's whole outbound buffer of {capacity} bytes, which is operator-set by \
177 `limits.max_connection_outbound_bytes`"
178 )]
179 PushFrameExceedsOutboundCapacity {
180 /// Correlation id of the push that could not be queued.
181 correlation_id: u64,
182 /// Encoded size of the rejected frame. Exceeds `capacity` on its own.
183 needed: usize,
184 /// The outbound buffer's whole capacity, which `needed` exceeds.
185 capacity: usize,
186 /// Bytes already queued when the frame was rejected. Context for the log
187 /// only: the decision is `needed` against `capacity` alone, so this frame
188 /// would not have fitted an empty buffer either.
189 queued: usize,
190 },
191
192 /// The server could not join the configured beamr distribution cluster.
193 #[error("cluster join failed: {message}")]
194 ClusterJoin { message: String },
195
196 /// Cluster state propagation through beamr distribution failed.
197 #[error("cluster sync failed: {message}")]
198 ClusterSync { message: String },
199
200 /// Graceful shutdown did not drain within the configured timeout.
201 #[error("shutdown timed out: {message}")]
202 ShutdownTimeout { message: String },
203
204 /// Durable state could not be flushed during graceful shutdown.
205 #[error("shutdown flush failed: {message}")]
206 ShutdownFlush { message: String },
207
208 /// The health endpoint failed to start or serve requests.
209 #[error("health endpoint failed: {message}")]
210 HealthEndpoint { message: String },
211
212 /// A new connection was refused because the configured `max_connections`
213 /// cap (§5) is already reached. The listener drops the freshly accepted
214 /// stream, refusing the connection, rather than admitting an unbounded fleet.
215 #[error(
216 "connection refused: the configured max_connections limit of {limit} live connections is reached"
217 )]
218 ConnectionLimitReached {
219 /// The configured `max_connections` cap that was hit.
220 limit: usize,
221 },
222
223 /// An admission-time per-connection cap (§5) refused an operation: too many
224 /// subscriptions, conversations, in-flight pushes, or pending conversation
225 /// replies on one connection. The connection process renders it as the
226 /// operation's existing typed error frame with this text as the message.
227 #[error("{operation} refused: the per-connection {cap} limit of {limit} is reached")]
228 ConnectionCapReached {
229 /// Human-readable description of the refused operation.
230 operation: String,
231 /// The name of the cap that refused it (a `limits.*` config key).
232 cap: &'static str,
233 /// The configured cap value that was hit.
234 limit: usize,
235 },
236}