AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(cluster): surface a degraded transport boot in /_cluster/health
xerj-orge22e0f257096
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 121e5b2e8..0b1e56946 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -33,6 +33,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0election with no diagnostic of its own) and `cluster.port` collidingwith this node's own rest/grpc/es_compat port (which degraded the nodeto single-node with green health).+- **A degraded cluster boot was invisible after the first log line**+ (issue [#1171](https://github.com/xerj-org/xerj/issues/1171), remaining+ half) — a configured ring whose TCP transport failed to bind, or whose+ cluster-state storage was unavailable, degraded to single-node with one+ ERROR line at boot and then `status: green` forever on+ `/_cluster/health`: the operator believed the node was clustered and+ no API could say otherwise. The boot outcome is now recorded on the+ application state (`ClusterTransportStatus`: Disabled / Running /+ Degraded) before the first router exists, and health answers from it:+ `status: yellow`, `number_of_nodes: 1` (the node actually serving —+ counting the unreachable configured peers would be the same fabrication+ #1169 removed), and an additive `xerj_cluster_transport: "degraded"`+ marker that says *why* it is yellow, present exactly when true. Waits+ stay honest from the degraded side too (`wait_for_nodes=2` of the one+ serving node → 408 with the real count), and red still outranks the+ degraded-yellow (an unopenable index remains the headline, with the+ transport marker beside it).## [1.0.0-rc.83] - 2026-10-06diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rsindex 207486930..39601125f 100644--- a/engine/crates/xerj-api/src/es_compat.rs+++ b/engine/crates/xerj-api/src/es_compat.rs@@ -423,11 +423,14 @@ async fn cluster_health_inner(// replicated-closed semantics keep the *cluster* status driven by// replicas only. Our tests cover both — we currently only track a single// "closed" flag per index and don't differentiate the closed-replication- // mode.+ // mode. A degraded cluster transport is yellow too (#1171): the node is+ // serving, but not as the clustered node the operator configured.+ let cluster_transport_degraded =+ state.cluster_transport == crate::state::ClusterTransportStatus::Degraded;let unassigned_primaries = selected_failed.len() as u32;let status = if unassigned_primaries > 0 {"red"- } else if unassigned_replicas > 0 {+ } else if unassigned_replicas > 0 || cluster_transport_degraded {"yellow"} else {"green"@@ -539,7 +542,17 @@ async fn cluster_health_inner(// the multinode smoke suite would "converge" on a single node; that// suite now skips with a recorded reason instead of passing against a// fabricated topology (yaml/smoke/smoke_test_multinode/10_basic.yml).- let nodes = configured_node_count(&state.config);+ //+ // A degraded transport (#1171) drops the count to the 1 node actually+ // serving: the configured peers are unreachable by construction — the+ // transport that would reach them failed to bind — so counting them+ // here would be the same fabrication #1169 removed, wearing the+ // degraded state as a topology.+ let nodes = if cluster_transport_degraded {+ 1+ } else {+ configured_node_count(&state.config)+ };let wait_for_nodes_unmet = match wait_for_nodes {NodesWait::AtLeast(n) => nodes < n,NodesWait::AtMost(n) => nodes > n,@@ -564,6 +577,15 @@ async fn cluster_health_inner("task_max_waiting_in_queue_millis": 0,"active_shards_percent_as_number": if idx_count == 0 { 100.0 } else { (active as f64) / (idx_count as f64) * 100.0 },});+ // The one-word reason yellow is yellow when the transport is degraded+ // (#1171): status says *what*, this says *why*, and a client polling+ // health sees the difference between "replicas unassigned" and "you are+ // not clustered at all". Extra fields are additive on this wire — ES+ // clients ignore unknowns — and the ES-YAML assertions are+ // match-shaped, so it appears only when it is true.+ if cluster_transport_degraded {+ resp["xerj_cluster_transport"] = json!("degraded");+ }// `level=indices` or `level=shards` — include a per-index breakdown.let level = params.level.as_deref().unwrap_or("cluster");@@ -45460,4 +45482,108 @@ mod cluster_topology_honesty_tests {let nodes = body["nodes"].as_object().expect("nodes map");assert_eq!(nodes.len(), 1);}++ // ── #1171: the degraded transport must surface in health ────────────+ use crate::state::ClusterTransportStatus;++ /// #1171: a configured ring whose transport failed to bind (or whose+ /// cluster-state storage was unavailable) used to be indistinguishable+ /// from a healthy node — one ERROR line at boot, then `green` forever.+ /// The boot path now records the outcome on `AppState`; health must say+ /// yellow, count only the 1 node actually serving, and carry the+ /// one-word marker that says *why* it is yellow.+ #[tokio::test]+ async fn degraded_transport_health_is_yellow_one_node_and_marked() {+ let mut state = ring3();+ state.cluster_transport = ClusterTransportStatus::Degraded;+ let app = crate::router::build_es_compat_router(state);++ let (status_code, body) = get(&app, "/_cluster/health").await;+ assert_eq!(status_code, StatusCode::OK);+ assert_eq!(body["status"], "yellow");+ // The configured peers are unreachable by construction — the+ // transport that would reach them failed to bind — so counting the+ // configured 3 here would be the same fabrication #1169 removed,+ // wearing the degraded state as a topology.+ assert_eq!(body["number_of_nodes"], 1);+ assert_eq!(body["number_of_data_nodes"], 1);+ assert_eq!(body["xerj_cluster_transport"], "degraded");+ }++ /// A degraded node must not "converge" on the ring it was configured+ /// for: asking 2 nodes of the 1 actually serving times out with the+ /// real count — the honest-wait semantics of #1169, seen from the+ /// degraded side.+ #[tokio::test]+ async fn degraded_transport_waits_time_out_on_the_ring_it_cannot_join() {+ let mut state = ring3();+ state.cluster_transport = ClusterTransportStatus::Degraded;+ let app = crate::router::build_es_compat_router(state);++ let (status_code, body) = get(&app, "/_cluster/health?wait_for_nodes=2").await;+ assert_eq!(status_code, StatusCode::REQUEST_TIMEOUT);+ assert_eq!(body["timed_out"], true);+ assert_eq!(body["number_of_nodes"], 1, "count stays the serving 1");+ assert_eq!(body["xerj_cluster_transport"], "degraded");++ // The serving node alone still satisfies `wait_for_nodes=1`.+ let (status_code, body) = get(&app, "/_cluster/health?wait_for_nodes=1").await;+ assert_eq!(status_code, StatusCode::OK);+ assert_eq!(body["timed_out"], false);+ }++ /// The marker appears only when it is true: a disabled node (green+ /// single-node by design) and a running ring both answer without it —+ /// a client polling for the field sees it exactly when the node is+ /// degraded, never as an always-present `xerj_*` stub.+ #[tokio::test]+ async fn the_degraded_marker_appears_only_when_degraded() {+ for state in [+ state_with_cluster(false, &[], 9300),+ ring3(), // enabled -> Running seed: a configured ring that came up+ ] {+ let app = crate::router::build_es_compat_router(state);+ let (status_code, body) = get(&app, "/_cluster/health").await;+ assert_eq!(status_code, StatusCode::OK);+ assert!(+ body.get("xerj_cluster_transport").is_none(),+ "marker must be absent, got {}",+ body["xerj_cluster_transport"]+ );+ }+ }++ /// Red outranks degraded-yellow: an unopenable index is an unassigned+ /// PRIMARY, strictly worse than serving single-node against a ring. The+ /// failed-index entry is inserted directly — the same+ /// `{name, reason, failed_at_ms}` record boot discovery inserts for a+ /// corrupt-on-disk index — so the precedence of the status chain is+ /// pinned without hand-crafting an unopenable directory.+ #[tokio::test]+ async fn an_unopenable_index_still_outranks_the_degraded_marker() {+ let mut state = ring3();+ state.cluster_transport = ClusterTransportStatus::Degraded;+ state.engine.failed_indices.insert(+ "broken".to_string(),+ xerj_engine::engine::FailedIndex {+ name: "broken".to_string(),+ reason: "manifest unparseable (test fixture)".to_string(),+ failed_at_ms: 0,+ retries: 0,+ },+ );+ let app = crate::router::build_es_compat_router(state);++ let (status_code, body) = get(&app, "/_cluster/health").await;+ assert_eq!(status_code, StatusCode::OK);+ assert_eq!(+ body["status"], "red",+ "an unassigned primary is the worse fact"+ );+ assert_eq!(body["unassigned_primary_shards"], 1);+ // The marker still tells the operator about the transport — red is+ // the headline, not a reason to hide the second problem.+ assert_eq!(body["xerj_cluster_transport"], "degraded");+ assert_eq!(body["number_of_nodes"], 1);+ }}diff --git a/engine/crates/xerj-api/src/state.rs b/engine/crates/xerj-api/src/state.rsindex 73fd7a885..e438421c5 100644--- a/engine/crates/xerj-api/src/state.rs+++ b/engine/crates/xerj-api/src/state.rs@@ -488,6 +488,31 @@ impl MlDatafeed {// AppState// ─────────────────────────────────────────────────────────────────────────────+/// Boot outcome of the cluster transport (#1171) — what *happened*, not what+/// was asked for (`cluster.enabled` in the config is the ask).+///+/// The REST layer cannot infer this from the config: a node configured for a+/// ring whose transport failed to bind serves single-node while the operator+/// believes it is clustered, and before this enum existed that node's+/// `/_cluster/health` stayed green forever — the failure was one ERROR line+/// at boot and then invisible. `xerj-server/src/main.rs` records the real+/// outcome here right after `AppState::new`, before any router exists to+/// read it.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]+pub enum ClusterTransportStatus {+ /// Cluster mode is off: single-node is the *intended* state and health+ /// reports green honestly.+ #[default]+ Disabled,+ /// `cluster.enabled = true` and the transport bound and the Raft runner+ /// started.+ Running,+ /// `cluster.enabled = true` but the transport failed to bind, or+ /// cluster-state storage was unavailable: this node is serving+ /// single-node against a configured ring. Health must say so (#1171).+ Degraded,+}+/// Shared state injected into every request handler via Axum's `State`/// extractor.#[derive(Clone)]@@ -559,6 +584,15 @@ pub struct AppState {/// handler, so every request path that ships a probability reads the same/// fit.pub decide_calibration: Arc<crate::systemone_api::CalibrationCache>,+ /// What the cluster transport boot actually did (#1171) — see+ /// [`ClusterTransportStatus`]. `AppState::new` cannot know a boot+ /// outcome, so it seeds this from the config alone and+ /// `xerj-server/src/main.rs` overwrites it with the truth before the+ /// first router exists; the constructor's `enabled -> Running` seed is+ /// for direct-construction tests modelling a configured ring that came+ /// up, which is also what every handler assumed before the field+ /// existed.+ pub cluster_transport: ClusterTransportStatus,}impl AppState {@@ -599,6 +633,14 @@ impl AppState {));let decide = Arc::new(crate::systemone_api::DecideSettings::from_env());let decide_calibration = Arc::new(crate::systemone_api::CalibrationCache::default());+ // Seeded from the config alone — see the field doc: `xerj-server`'s+ // main overwrites this with the real boot outcome before the first+ // router exists.+ let cluster_transport = if config.cluster.enabled {+ ClusterTransportStatus::Running+ } else {+ ClusterTransportStatus::Disabled+ };Self {rerank,decide,@@ -614,6 +656,7 @@ impl AppState {ml_results: Arc::new(DashMap::new()),ml_datafeed_tasks: Arc::new(DashMap::new()),shares,+ cluster_transport,}}diff --git a/engine/crates/xerj-server/src/main.rs b/engine/crates/xerj-server/src/main.rsindex 1590c5000..1e654caeb 100644--- a/engine/crates/xerj-server/src/main.rs+++ b/engine/crates/xerj-server/src/main.rs@@ -2444,6 +2444,17 @@ async fn async_main() -> Result<()> {let cluster_listen_addr = cfg.socket_addr(cfg.cluster.port);// 8b. Cluster runner (if cluster mode is enabled)+ //+ // The boot outcome is recorded for the REST layer (#1171): a configured+ // ring whose transport cannot bind degrades to single-node with one+ // ERROR line and then nothing — health reports the degraded state+ // instead of green silence. Starts as Degraded for every enabled path+ // and is only upgraded to Running when the runner actually started.+ let mut cluster_transport_outcome = if cfg.cluster.enabled {+ xerj_api::state::ClusterTransportStatus::Degraded+ } else {+ xerj_api::state::ClusterTransportStatus::Disabled+ };let _cluster_shutdown = if cfg.cluster.enabled && storage_available {// Fail closed (issue #75). The cluster port carries Raft control// messages; without a shared secret every frame on it is@@ -2506,6 +2517,7 @@ async fn async_main() -> Result<()> {let mut runner = ClusterRunner::new(node, tick, shutdown_rx);info!(node = %node_id, "Starting cluster runner (Raft mode)");+ cluster_transport_outcome = xerj_api::state::ClusterTransportStatus::Running;tokio::spawn(async move { runner.run().await });}Err(e) => {@@ -2680,6 +2692,15 @@ async fn async_main() -> Result<()> {// 9b. Application statelet mut state = AppState::new(cfg.clone(), engine, metrics);+ // 9b-i. The cluster-transport boot outcome (#1171): `AppState::new`+ // seeds the field from the config alone because it cannot see the+ // boot; overwrite it with what actually happened in step 8b before+ // any router exists to read it. A node whose configured ring failed+ // to bind (or whose cluster-state storage was unavailable) serves+ // single-node while the operator believes it is clustered — this is+ // what lets /_cluster/health say yellow instead of green forever.+ state.cluster_transport = cluster_transport_outcome;+// 9b-iia. Decide-ladder override (#1057): `--decide-mode` /// `--decide-model-dir` flags or XERJ_DECIDE_MODE / XERJ_DECIDE_MODEL_DIR// env (flags win; the flag can fill either half, so `--decide-mode local`