gateway: hot-reload agents.conf at runtime (#869)

Replace eval-time per-agent nginx location baking with a runtime
include file. c0re writes /var/lib/hyperhive/agents.conf (nginx
location blocks, UDS or TCP per agent) on every topology change and
on the 10s marker poll. The gateway container bind-mounts
/var/lib/hyperhive/ at /run/hive-state/ and nginx includes
/run/hive-state/agents.conf. A systemd path unit inside the container
watches the file for changes and fires `nginx -s reload` on each
atomic rename from c0re — no nixos-rebuild switch needed when agents
start, stop, or flip useUnixSocket.

  - new hive-c0re/src/gateway_nginx.rs: write() + render()
  - lib.rs + meta.rs + agent_sockets::spawn_poll: hook in write()
  - hive-gateway.nix: drop agentPortsTable/agentSocketsTable/
    agentUpstreamFor/lib.mapAttrs', add /run/hive-state bind-mount,
    include directive, systemd path unit + reload service, tmpfiles
    for /var/lib/hyperhive + agents.conf seed
  - docs/gateway.md: update vhost table + Per-agent UDS section
This commit is contained in:
atlas 2026-05-31 20:12:00 +02:00 committed by mara
commit 07434e8f50
7 changed files with 337 additions and 173 deletions

View file

@ -1,9 +1,11 @@
//! `/var/lib/hyperhive/agent-ports.json` writer. Legacy TCP map for
//! per-agent `/agent/<name>/` routing — the unix-socket replacement
//! lives in `agent_sockets.rs`. The gateway reads this JSON at
//! request-handling time rather than at gateway build time, so a
//! `nixos-container update` of the gateway isn't needed every time
//! an agent spawns / moves / destroys.
//! `/var/lib/hyperhive/agent-ports.json` writer. Port map for
//! per-agent `/agent/<name>/` TCP routing. Written alongside
//! `agents.conf` (see `gateway_nginx.rs`) on every topology change;
//! `gateway_nginx::render` reads it indirectly via
//! `lifecycle::agent_web_port` to populate TCP upstreams for agents
//! that haven't opted in to unix-socket mode yet. Also kept as a
//! human-readable audit file — `cat agent-ports.json` shows every
//! registered sub-agent and its deterministic port assignment.
//!
//! Shape (flat object keyed by logical agent name → web port):
//!