feat(#2290): split ensure_runtime — dirs to lifecycle, listeners to mcp_sockets supervisor

- lifecycle::ensure_agent_runtime_dir(name): pure filesystem op, no
  Coordinator dep. Creates /run/hyperhive/agents/<name> without touching
  the MCP listener map.

- workers/mcp_sockets::spawn_poll(coord): 10 s reconcile loop (same shape
  as agent_sockets::spawn_poll). Converges 'agent running => MCP listener
  bound'. First tick is immediate so hive-c0re restarts re-register all
  running agents without waiting a full interval. Fixes the dead-listener-
  after-daemon-restart gap.

- All ensure_runtime() call sites updated:
  - Prebuild/Swap/WriteDropin: Coordinator::agent_dir() (pure, no IO)
  - Reconcile-Start: ensure_agent_runtime_dir + agent_dir (dir may be
    missing after reboot; listener deferred to supervisor)
  - run_create / handle_spawn: ensure_agent_runtime_dir + register_agent
    (eager on first spawn so socket ready before harness first turn)
  - apply_commit / merge_config_pr: ensure_agent_runtime_dir + agent_dir
  - Manager (auto_update): ensure_agent_runtime_dir + agent_dir
    (manager has no MCP listener; socket_server::start_manager owns it)

- ensure_runtime() retained in Coordinator with updated doc pointing at
  the preferred split form. No callers remain outside tests.
This commit is contained in:
atlas 2026-07-08 23:27:48 +02:00
commit 3d919b596f
10 changed files with 147 additions and 30 deletions

View file

@ -545,14 +545,11 @@ impl Coordinator {
}
}
/// Assemble the per-agent filesystem paths for `name`. The caller
/// must supply `agent_dir` (from `ensure_runtime`) since that
/// creates the tmpfs entry on first call. All other paths are
/// derived statically from `name`.
///
/// ```ignore
/// let paths = Coordinator::agent_paths(name, coord.ensure_runtime(name)?);
/// ```
/// Assemble the per-agent filesystem paths for `name`. `agent_dir`
/// is the runtime directory (`/run/hyperhive/agents/<name>`), obtained
/// from `Coordinator::agent_dir(name)` (pure path) or from
/// `lifecycle::ensure_agent_runtime_dir` + `agent_dir` when the dir
/// must be created. All other paths are derived statically from `name`.
#[must_use]
pub fn agent_paths(name: &str, agent_dir: PathBuf) -> AgentPaths {
AgentPaths {
@ -1453,11 +1450,17 @@ impl Coordinator {
Self::agent_dir(name).join("mcp.sock")
}
/// Ensure a runtime dir + (for sub-agents) per-agent socket exists. For
/// the manager, `socket_server::start_manager` owns the socket — just return
/// the dir. For sub-agents this is `register_agent` (creates a fresh
/// listener bound to `socket_path(name)`). Source directory of the
/// `/run/hive/mcp.sock` bind that ends up in `set_nspawn_flags`.
/// Ensure a runtime dir + (for sub-agents) per-agent socket exists.
///
/// **Prefer the split form:**
/// - dir creation → `lifecycle::ensure_agent_runtime_dir(name)`
/// - listener registration → `register_agent(name)` (eagerly, on first
/// spawn) or leave it to `mcp_sockets::spawn_poll` (reconcile within
/// 10 s, safe for the start + rebuild paths where the container
/// takes longer than that to boot).
///
/// This method is kept as a convenience shim for any remaining callers
/// that need the combined semantics in one call.
pub fn ensure_runtime(self: &Arc<Self>, name: &str) -> Result<PathBuf> {
if name == crate::lifecycle::MANAGER_NAME {
let dir = Self::agent_dir(name);