Algostream_data_ingestion.Connection_supervisorPer-connection state machine: connect attempts, exponential backoff with jitter, circuit breaker, liveness tracking, and rate-limited Risk_alert emission.
The mutable state is owned by a single Lwt fiber, so every function here except mirror is NOT thread-safe across Domains. Observers on another Domain — a monitoring dashboard, say — must use mirror, which reads an immutable record published on each transition.
val create :
config:Algostream_common_config.Exchange_config.t ->
bus:Algostream_infrastructure_event_bus.Event_bus.t ->
unit ->
tval exchange : t -> stringval config : t -> Algostream_common_config.Exchange_config.tval note_attempt : t -> unitval note_connected : t -> unitval note_failure : t -> reason:string -> ?symbol:string -> unit -> unitRecords a failure and transitions to Reconnecting (or Open_circuit when the breaker trips). Optionally fires a Risk_alert with deduplication keyed on (code, symbol).
val note_message : t -> unitval time_since_last_message_ns : t -> int64Time since the last successful frame read, in nanoseconds. Int64.max_int before the first message.
val is_ready_to_attempt : t -> boolWhether a connect attempt may be made now — false during open-circuit. Pure, so it is safe to call from anywhere, including an observer.
val poll_ready_to_attempt : t -> boolAs is_ready_to_attempt, but advances the state machine: an Open_circuit whose timer has expired is closed and returns to Connecting. This is the reconnect loop's entry point; use is_ready_to_attempt to observe without side effects.
val next_attempt_delay_ns : t -> int64How long to sleep before the next attempt; 0 if ready now.
val read_timed_out : t -> boolReturns true if there has been no inbound traffic for read_timeout_ms. Used to force a reconnect when the exchange goes silent.
val consecutive_failures : t -> intNumber of consecutive failures since the last successful connection.
val critical_drops : t -> int64Counts of dropped Critical-band alerts since the supervisor started — exposed for stats.
val note_critical_drop : t -> unitRecord a Critical-band publish failure that occurred outside this module. Connector_runtime calls it when a Data_gap is dropped — exactly the loss critical_drops exists to surface.
type mirror = {exchange : string;state : state;consecutive_failures : int;critical_drops : int64;time_since_last_message_ns : int64;}Cross-Domain-safe view of the connection.
state, consecutive_failures and critical_drops come from an immutable record republished on every transition; time_since_last_message_ns is computed at call time and is Int64.max_int before the first message.