Skip to content

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

fix(socket): date an outage from the start of the first failed attempt

Shanu994de4df283e
diff --git a/crates/openhuman-core/src/platform/connectivity/README.md b/crates/openhuman-core/src/platform/connectivity/README.md
index cc6214685b..c65071f0b8 100644
--- a/crates/openhuman-core/src/platform/connectivity/README.md
+++ b/crates/openhuman-core/src/platform/connectivity/README.md
@@ -1,10 +1,10 @@
# connectivity
-Diagnostics for the local core's reachability and the live backend Socket.IO state, plus the listen-port selection logic the core uses when it boots its embedded HTTP listener. The frontend has three independent connectivity channels — browser internet, backend Socket.IO websocket, and the local core HTTP — and issue #1527 split them in the UI so users see *which* channel is broken instead of one conflated "Disconnected" pill. This module exposes a cheap `openhuman.connectivity_diag` RPC that snapshots in-memory backend-socket state plus the local core's PID and listening port (no I/O beyond a single TCP probe), suitable for poll-based health checks.
+Diagnostics for the local core's reachability and the live backend Socket.IO state, plus the listen-port selection logic the core uses when it boots its embedded HTTP listener. The frontend has four independent connectivity channels — browser internet, the local core HTTP, the renderer's Socket.IO link to that core, and (via this module's diag snapshot, #6256) the core's own Socket.IO link to the hosted backend — and issue #1527 split them in the UI so users see *which* channel is broken instead of one conflated "Disconnected" pill. This module exposes a cheap `openhuman.connectivity_diag` RPC that snapshots in-memory backend-socket state plus the local core's PID and listening port (no I/O beyond a single TCP probe), suitable for poll-based health checks.
## Responsibilities
-- Answer `openhuman.connectivity_diag` with a flat snapshot: backend socket state, last websocket error, sidecar PID, configured listen port, and whether that port currently has a listener bound.
+- Answer `openhuman.connectivity_diag` with a flat snapshot: backend socket state, last websocket error, whether the backend reconnect loop is running and whether it stopped on a terminal failure (`socket_loop_active` / `socket_loop_stopped_on_failure`, #6270), sidecar PID, configured listen port, and whether that port currently has a listener bound.
- Resolve the configured core RPC port from the environment (`OPENHUMAN_CORE_RPC_URL` then `OPENHUMAN_CORE_PORT`, defaulting to `7788`).
- Snapshot the backend Socket.IO connection state from the global `SocketManager` (reports `"uninitialized"` when the manager singleton isn't registered yet).
- Probe whether a TCP port on loopback is already bound (`is_port_in_use`).
diff --git a/crates/openhuman-core/src/platform/socket/ws_loop/connect.rs b/crates/openhuman-core/src/platform/socket/ws_loop/connect.rs
index 3c76bb45cb..b58bb7c05f 100644
--- a/crates/openhuman-core/src/platform/socket/ws_loop/connect.rs
+++ b/crates/openhuman-core/src/platform/socket/ws_loop/connect.rs
@@ -53,8 +53,9 @@ pub(super) const CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
#[derive(Clone, Copy, Debug, Default)]
pub(super) struct ReconnectContext {
/// When the outage began: the moment the previous connection was lost,
- /// or the first failed attempt if there was no connection yet. `None`
- /// on a first connect that has not failed.
+ /// or the moment the first failed attempt *started* if there was no
+ /// connection yet — so a dial that stalled for the whole connect deadline
+ /// is counted. `None` on a first connect that has not failed.
pub(super) outage_started: Option<Instant>,
/// Whether a live connection preceded this outage — distinguishes
/// "reconnected" from "connected after initial failures" in the log.
diff --git a/crates/openhuman-core/src/platform/socket/ws_loop/reconnect.rs b/crates/openhuman-core/src/platform/socket/ws_loop/reconnect.rs
index 9dcca032eb..4183675b44 100644
--- a/crates/openhuman-core/src/platform/socket/ws_loop/reconnect.rs
+++ b/crates/openhuman-core/src/platform/socket/ws_loop/reconnect.rs
@@ -166,6 +166,11 @@ pub(crate) async fn ws_loop(
*shared.status.write() = ConnectionStatus::Connecting;
emit_state_change(&shared);
+ // Taken before the attempt so a stalled first dial counts toward the
+ // outage it starts: `Failed` lands only after the connect deadline has
+ // run out, and dating the outage from then would hide that whole wait
+ // from the `Connected after …` line (Codex review on #6270).
+ let attempt_started = Instant::now();
let outcome = run_connection(
&mut ws_url,
&token,
@@ -220,7 +225,7 @@ pub(crate) async fn ws_loop(
}
ConnectionOutcome::Failed(_) => {
if reconnect.outage_started.is_none() {
- reconnect.outage_started = Some(Instant::now());
+ reconnect.outage_started = Some(attempt_started);
}
reconnect.failed_attempts = reconnect.failed_attempts.saturating_add(1);
}