lifecycle: drop manager port special case (#753) — manager hashes into 8100..8999 like every other agent
This commit is contained in:
parent
f9a492f7a9
commit
4526e40a49
11 changed files with 43 additions and 39 deletions
|
|
@ -20,10 +20,13 @@
|
|||
//!
|
||||
//! Ports come from [`crate::lifecycle::agent_web_port`] — pure
|
||||
//! FNV-1a(name) hash so the value is reproducible from the name
|
||||
//! alone. The manager is intentionally excluded: it sits at the
|
||||
//! fixed `MANAGER_PORT` (8000) and the gateway routes `/` straight
|
||||
//! to it without a per-agent prefix (see `nix/modules/hive-gateway.nix`
|
||||
//! upstream config, atlas's #740).
|
||||
//! alone. The manager is intentionally excluded from the map: the
|
||||
//! gateway routes `/` straight to it via the c0re dashboard upstream
|
||||
//! (see `nix/modules/hive-gateway.nix`, atlas's #740) rather than a
|
||||
//! per-agent `/agent/<name>/` prefix. Post-#753 the manager's port
|
||||
//! is computed by the same hash as every other agent, but it still
|
||||
//! doesn't appear here — keeping the routing surface "sub-agents
|
||||
//! only" matches the gateway's current shape.
|
||||
//!
|
||||
//! Atomicity: write to a sibling `.tmp` file + rename so a partial
|
||||
//! write never leaves an unparseable file in place. The gateway's
|
||||
|
|
|
|||
|
|
@ -30,8 +30,6 @@ use crate::container_view::{ContainerView, claude_has_session};
|
|||
use crate::coordinator::Coordinator;
|
||||
use crate::lifecycle::{self, MANAGER_NAME};
|
||||
|
||||
const MANAGER_PORT: u16 = 8000;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState {
|
||||
coord: Arc<Coordinator>,
|
||||
|
|
@ -416,7 +414,7 @@ async fn api_state(headers: HeaderMap, State(state): State<AppState>) -> axum::J
|
|||
axum::Json(StateSnapshot {
|
||||
seq,
|
||||
hostname,
|
||||
manager_port: MANAGER_PORT,
|
||||
manager_port: lifecycle::agent_web_port(MANAGER_NAME),
|
||||
any_stale,
|
||||
containers,
|
||||
transients,
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@ pub const MAX_AGENT_NAME: usize = 9;
|
|||
/// nixosConfiguration (`manager`, not `agent-base`).
|
||||
pub const MANAGER_NAME: &str = "hm1nd";
|
||||
|
||||
/// Web UI port reserved for the manager (sub-agents hash into 8100..8999).
|
||||
pub const MANAGER_PORT: u16 = 8000;
|
||||
|
||||
/// Mount point of the per-agent runtime directory inside the container.
|
||||
pub const CONTAINER_RUNTIME_MOUNT: &str = "/run/hive";
|
||||
|
||||
|
|
@ -57,18 +54,16 @@ const WEB_PORT_RANGE: u16 = 900;
|
|||
const DEFAULT_MEMORY_MAX: &str = "2G";
|
||||
const DEFAULT_CPU_QUOTA: &str = "50%";
|
||||
|
||||
/// Per-agent web UI port. Manager is fixed at `MANAGER_PORT`; every
|
||||
/// sub-agent is `WEB_PORT_BASE + FNV-1a(name) % WEB_PORT_RANGE`,
|
||||
/// pure and reproducible from just the name. Collisions are
|
||||
/// possible (birthday paradox at ~30 agents); the operator resolves
|
||||
/// them by renaming an agent (different hash → different port).
|
||||
/// Stable across hosts, restarts, and dashboard renders — no
|
||||
/// state-file dance.
|
||||
/// Per-agent web UI port — `WEB_PORT_BASE + FNV-1a(name) %
|
||||
/// WEB_PORT_RANGE` for every agent including the manager (#753
|
||||
/// dropped the pre-#753 "manager pinned at 8000" special case so
|
||||
/// the port allocation rule reads the same for every name).
|
||||
/// Collisions are possible (birthday paradox at ~30 agents); the
|
||||
/// operator resolves them by renaming an agent (different hash →
|
||||
/// different port). Stable across hosts, restarts, and dashboard
|
||||
/// renders — no state-file dance.
|
||||
#[must_use]
|
||||
pub fn agent_web_port(name: &str) -> u16 {
|
||||
if name == MANAGER_NAME {
|
||||
return MANAGER_PORT;
|
||||
}
|
||||
let mut hash: u32 = 2_166_136_261;
|
||||
for b in name.bytes() {
|
||||
hash ^= u32::from(b);
|
||||
|
|
|
|||
Loading…
Reference in a new issue