Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(socket): publish `status` in one vocabulary across the namespace

M3gA-Mind4e06f9b1e7e4
diff --git a/src/openhuman/platform/socket/schemas.rs b/src/openhuman/platform/socket/schemas.rs
index 5cc912bd58..7be91cffbf 100644
--- a/src/openhuman/platform/socket/schemas.rs
+++ b/src/openhuman/platform/socket/schemas.rs
@@ -6,6 +6,7 @@ use crate::core::all::{ControllerFuture, RegisteredController};
use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
use super::manager::global_socket_manager;
+use crate::api::models::socket::{ConnectionStatus, SocketState};
// ---------------------------------------------------------------------------
// Schema catalog
@@ -159,6 +160,29 @@ fn require_manager() -> Result<&'static std::sync::Arc<super::SocketManager>, St
.ok_or_else(|| "SocketManager not initialized — runtime not bootstrapped".to_string())
}
+/// Serialise a [`ConnectionStatus`] the way every other surface publishes it.
+///
+/// `socket_state` (`serde_json::to_value(state)`) and `connectivity_diag` both go through
+/// `ConnectionStatus`' `#[serde(rename_all = "lowercase")]`, so the lifecycle handlers below use
+/// the same encoding instead of `format!("{:?}", …)` (#6111). `Debug` and serde disagree —
+/// `"Disconnected"` vs `"disconnected"` — and one namespace publishing a field two ways is a
+/// contract a caller cannot rely on.
+fn status_payload(state: &SocketState) -> Value {
+ json!({ "status": Value::String(status_slug(state.status)) })
+}
+
+/// The serde spelling of `status`, as a plain string.
+///
+/// Goes through `serde_json::to_value` rather than a hand-written match so the mapping cannot
+/// drift from the `rename_all` attribute that `socket_state` relies on. `ConnectionStatus` is a
+/// unit-variant enum, so this cannot fail; the fallback keeps the function total.
+fn status_slug(status: ConnectionStatus) -> String {
+ serde_json::to_value(status)
+ .ok()
+ .and_then(|v| v.as_str().map(str::to_string))
+ .unwrap_or_else(|| format!("{status:?}").to_lowercase())
+}
+
fn handle_connect(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let mgr = require_manager()?;
@@ -172,7 +196,7 @@ fn handle_connect(params: Map<String, Value>) -> ControllerFuture {
.ok_or("missing required param 'token'")?;
let state = super::ops::connect_static(mgr, url, token).await?;
- Ok(json!({ "status": format!("{:?}", state.status) }))
+ Ok(status_payload(&state))
})
}
@@ -180,7 +204,7 @@ fn handle_disconnect(_params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let mgr = require_manager()?;
let state = super::ops::disconnect(mgr).await?;
- Ok(json!({ "status": format!("{:?}", state.status) }))
+ Ok(status_payload(&state))
})
}
@@ -212,7 +236,7 @@ fn handle_connect_with_session(_params: Map<String, Value>) -> ControllerFuture
Box::pin(async move {
let mgr = require_manager()?;
let state = super::ops::connect_with_session(mgr).await?;
- Ok(json!({ "status": format!("{:?}", state.status) }))
+ Ok(status_payload(&state))
})
}
diff --git a/src/openhuman/platform/socket/schemas_tests.rs b/src/openhuman/platform/socket/schemas_tests.rs
index b10fdd8c20..7957959d96 100644
--- a/src/openhuman/platform/socket/schemas_tests.rs
+++ b/src/openhuman/platform/socket/schemas_tests.rs
@@ -128,3 +128,68 @@ async fn handlers_error_without_initialized_manager() {
let err = handle_emit(Map::new()).await.unwrap_err();
assert!(err.contains("SocketManager not initialized"));
}
+
+/// #6111 — the lifecycle handlers and `socket_state` must publish `status` in one vocabulary.
+///
+/// The three lifecycle handlers used to build their payload with `format!("{:?}", status)` while
+/// `socket_state` went through `ConnectionStatus`' `#[serde(rename_all = "lowercase")]`, so one
+/// namespace answered `"Disconnected"` and `"disconnected"` for the same field. This pins the
+/// decided direction (serde) against the source of truth — the serde encoding itself — rather
+/// than against a hand-written list that could drift with it.
+#[test]
+fn status_payload_matches_the_serde_encoding_for_every_variant() {
+ for status in [
+ ConnectionStatus::Disconnected,
+ ConnectionStatus::Connecting,
+ ConnectionStatus::Connected,
+ ConnectionStatus::Reconnecting,
+ ConnectionStatus::Error,
+ ] {
+ let state = SocketState {
+ status,
+ socket_id: None,
+ error: None,
+ };
+
+ // What `socket_state` publishes for this status.
+ let from_state = serde_json::to_value(&state).expect("serialize SocketState");
+ let expected = from_state
+ .get("status")
+ .and_then(Value::as_str)
+ .expect("SocketState serialises a status field");
+
+ // What the lifecycle handlers publish for the same status.
+ let payload = status_payload(&state);
+ assert_eq!(
+ payload.get("status").and_then(Value::as_str),
+ Some(expected),
+ "lifecycle handlers and socket_state must agree on {status:?}"
+ );
+ assert_ne!(
+ payload.get("status").and_then(Value::as_str),
+ Some(format!("{status:?}").as_str()),
+ "{status:?} must not be published in Rust's Debug spelling"
+ );
+ }
+}
+
+/// The slug is lowercase for every variant — the property `connectivity_diag` and the frontend's
+/// lowercase comparisons rely on.
+#[test]
+fn status_slug_is_lowercase_for_every_variant() {
+ for status in [
+ ConnectionStatus::Disconnected,
+ ConnectionStatus::Connecting,
+ ConnectionStatus::Connected,
+ ConnectionStatus::Reconnecting,
+ ConnectionStatus::Error,
+ ] {
+ let slug = status_slug(status);
+ assert!(!slug.is_empty(), "{status:?} produced an empty slug");
+ assert_eq!(
+ slug,
+ slug.to_lowercase(),
+ "{status:?} slug is not lowercase"
+ );
+ }
+}
diff --git a/tests/raw_coverage/channel_socket_e2e.rs b/tests/raw_coverage/channel_socket_e2e.rs
index bc357b2f4b..d1b5fd4d2f 100644
--- a/tests/raw_coverage/channel_socket_e2e.rs
+++ b/tests/raw_coverage/channel_socket_e2e.rs
@@ -411,19 +411,19 @@ async fn socket_connect_then_disconnect_round_trips_state() {
let result = peel(assert_no_jsonrpc_error(&connected, "socket_connect"));
assert_eq!(
result.get("status").and_then(Value::as_str),
- Some("Connecting"),
- "connect returns as soon as the loop is spawned, in the Connecting state. NOTE the \
- capitalisation: this handler formats the status with `{{:?}}` while `socket_state` \
- serialises it through serde (lowercase `connecting`). See \
- bugs/e2e-wave-socket-status-casing-split.md: {result}"
+ Some("connecting"),
+ "connect returns as soon as the loop is spawned, in the Connecting state. The spelling \
+ is the serde one (`rename_all = \"lowercase\"`), the same encoding `socket_state` and \
+ `connectivity_diag` publish — this handler used to emit Rust's `Debug` \
+ (`\"Connecting\"`) and the split was #6111: {result}"
);
let disconnected = post_json_rpc(&h.rpc_base, 8102, "openhuman.socket_disconnect", json!({})).await;
let result = peel(assert_no_jsonrpc_error(&disconnected, "socket_disconnect"));
assert_eq!(
result.get("status").and_then(Value::as_str),
- Some("Disconnected"),
- "disconnect must report the manager back at rest: {result}"
+ Some("disconnected"),
+ "disconnect must report the manager back at rest, in the serde spelling (#6111): {result}"
);
let state = post_json_rpc(&h.rpc_base, 8103, "openhuman.socket_state", json!({})).await;
@@ -431,7 +431,8 @@ async fn socket_connect_then_disconnect_round_trips_state() {
assert_eq!(
result.get("status").and_then(Value::as_str),
Some("disconnected"),
- "state must agree with disconnect's own report (modulo the casing split): {result}"
+ "state must agree with disconnect's own report exactly — one namespace, one status \
+ vocabulary (#6111): {result}"
);
assert!(
result.get("socket_id").map(Value::is_null).unwrap_or(false),
@@ -500,8 +501,9 @@ async fn socket_connect_with_session_requires_a_stored_session() {
));
assert_eq!(
result.get("status").and_then(Value::as_str),
- Some("Connecting"),
- "a stored session must get past the guard and start the loop: {result}"
+ Some("connecting"),
+ "a stored session must get past the guard and start the loop, reporting the serde \
+ spelling (#6111): {result}"
);
let stopped = post_json_rpc(&h.rpc_base, 8205, "openhuman.socket_disconnect", json!({})).await;
@@ -509,7 +511,7 @@ async fn socket_connect_with_session_requires_a_stored_session() {
peel(assert_no_jsonrpc_error(&stopped, "socket_disconnect"))
.get("status")
.and_then(Value::as_str),
- Some("Disconnected")
+ Some("disconnected")
);
manager.disconnect().await.expect("teardown disconnect");