Skip to content

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

feat(runtime): distinguish takeover from fallback when port is occupied

Steven Enamakelf6b292bc53bc
diff --git a/crates/openhuman-core/src/core/runtime/builder.rs b/crates/openhuman-core/src/core/runtime/builder.rs
index ec0fba9e13..bdbb2b6559 100644
--- a/crates/openhuman-core/src/core/runtime/builder.rs
+++ b/crates/openhuman-core/src/core/runtime/builder.rs
@@ -883,9 +883,19 @@ impl CoreRuntime {
let preferred_port = resolved_port;
let host = resolved_host;
- let pick = crate::platform::connectivity::rpc::pick_listen_port_for_host(
+ // The desktop shell hands in `ready_tx` and owns the stale-listener
+ // takeover (#1130) for its own leftover core. A headless `serve` has
+ // nothing to take over: another live core on the port (the desktop
+ // app's, another checkout's) is a neighbour, so move to a free port.
+ let occupied_by_core = if ready_tx.is_some() {
+ crate::platform::connectivity::rpc::OccupiedByCore::Takeover
+ } else {
+ crate::platform::connectivity::rpc::OccupiedByCore::Fallback
+ };
+ let pick = crate::platform::connectivity::rpc::pick_listen_port_for_host_with(
host.as_str(),
preferred_port,
+ occupied_by_core,
)
.await
.map_err(|err| {
diff --git a/crates/openhuman-core/src/platform/connectivity/README.md b/crates/openhuman-core/src/platform/connectivity/README.md
index c65071f0b8..c85e2a6563 100644
--- a/crates/openhuman-core/src/platform/connectivity/README.md
+++ b/crates/openhuman-core/src/platform/connectivity/README.md
@@ -8,7 +8,7 @@ Diagnostics for the local core's reachability and the live backend Socket.IO sta
- 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`).
-- Pick a listen port for the embedded core HTTP listener (`pick_listen_port` / `pick_listen_port_for_host`): try preferred, retry transient `AddrInUse` races, request stale-listener takeover when another OpenHuman core owns the port (#1130), otherwise fall back to a port pool.
+- Pick a listen port for the embedded core HTTP listener (`pick_listen_port` / `pick_listen_port_for_host`): try preferred, retry transient `AddrInUse` races, request stale-listener takeover when another OpenHuman core owns the port (#1130) — the embedded desktop path; headless `serve` passes `OccupiedByCore::Fallback` to `pick_listen_port_for_host_with` and moves on instead — otherwise fall back to a port pool.
- Handle Windows OS-excluded port ranges (`WSAEACCES` / os error 10013, Sentry OPENHUMAN-TAURI-500) by routing straight to fallback ports instead of failing.
## Key files