The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(docker): boot a gateway.standalone profile's own s6 slot at container start (#120524, salvage #120525)
John Paul Soliva8e9d1b90c9aa
diff --git a/hermes_cli/container_boot.py b/hermes_cli/container_boot.pyindex 7b8a37ee641..b2ffc0a8a6e 100644--- a/hermes_cli/container_boot.py+++ b/hermes_cli/container_boot.py@@ -98,8 +98,9 @@ def reconcile_profile_gateways(review)."""actions: list[ReconcileAction] = []- # ONE gateway per container: named slots are registered (so `hermes -p X gateway start` has a- # target and `s6-svstat` can report them) but are NEVER booted from their persisted run intent.+ # ONE multiplexing gateway per container: named slots are registered (so `hermes -p X gateway+ # start` has a target and `s6-svstat` can report them) but are never booted from their persisted+ # run intent, except a `gateway.standalone` profile's (below).# This is the s6 leg of the multiplex-only convergence: an image upgraded from a release that# booted N per-profile slots comes back up with one multiplexing root gateway and no manual# step, instead of N processes fighting over the same profiles.@@ -108,6 +109,10 @@ def reconcile_profile_gateways(# the slots anyway — the container shipped the opt-out topology by accident. The key is retired# as a topology switch (hermes_cli/gateway_multiplex_mode.py), so there is nothing to read.named = [(name, entry, _read_desired_state(entry)) for name, entry in _named_profile_dirs(hermes_home)]+ # The exception is a `gateway.standalone` profile: the root multiplexer never serves it+ # (profiles_to_serve excludes it), so it boots its own slot from its own intent, beside the root.+ from hermes_cli.profiles import profile_is_standalone+ standalone = {name for name, entry, _prior in named if profile_is_standalone(entry)}# A legacy `gateway run` container with no state yet seeds `running` (pre-s6 behavior).legacy_default_state = _maybe_migrate_legacy_gateway_run_state(@@ -118,7 +123,8 @@ def reconcile_profile_gateways(# booted with ZERO gateways: it has no root state (or "stopped"), every named slot is now# registered down unconditionally, and every action reported "registered" — a container that# looks healthy while nothing is listening.- fold = fold_named_slot_intent(default_prior_state, ((name, prior) for name, _dir, prior in named))+ fold = fold_named_slot_intent(+ default_prior_state, ((name, prior) for name, _dir, prior in named if name not in standalone))folded, default_should_start = list(fold.folded), fold.root_should_startif folded and default_prior_state not in _AUTOSTART_STATES:log.warning("%s", boot_notice(folded))@@ -129,8 +135,8 @@ def reconcile_profile_gateways(folded_into_root=bool(folded)))for name, entry, prior_state in named:- # Registered down, always: a started named slot IS a second gateway on this host.- should_start = False+ # Registered down unless standalone: any other started named slot IS a second gateway on this host.+ should_start = name in standalone and prior_state in _AUTOSTART_STATESif not dry_run:_cleanup_stale_runtime_files(entry)_register_service(scandir, name, start=should_start)@@ -144,7 +150,7 @@ def reconcile_profile_gateways(def boot_notice(folded: Sequence[str]) -> str:"""One line naming the profiles whose autostart intent the root slot took over."""return ("reconcile: profile gateway(s) " + ", ".join(sorted(folded)) +- " asked to autostart; one gateway per container serves every profile, so the ROOT "+ " asked to autostart; one gateway per container serves every non-standalone profile, so the ROOT ""slot (gateway-default) was started instead and multiplexes them.")diff --git a/tests/hermes_cli/test_container_boot.py b/tests/hermes_cli/test_container_boot.pyindex 63e495e4063..6e243990e88 100644--- a/tests/hermes_cli/test_container_boot.py+++ b/tests/hermes_cli/test_container_boot.py@@ -323,6 +323,26 @@ def test_a_named_slots_autostart_intent_boots_the_root_slot(tmp_path: Path) -> Nassert by_profile["coder"].action == "registered" and by_profile["coder"].folded_into_root is True+def test_a_standalone_profile_boots_its_own_slot_instead_of_folding_into_root(tmp_path: Path) -> None:+ """The root multiplexer never serves a `gateway.standalone` profile, so folding its intent into+ the root leaves it dark after every container restart. It boots its own slot; a non-standalone+ profile's intent still folds into the root."""+ hermes_home = tmp_path / "data"+ hermes_home.mkdir()+ _seed_default_root(hermes_home, state="stopped")+ solo = _make_profile(hermes_home, "solo", state=None, desired_state="running")+ (solo / "config.yaml").write_text("gateway:\n standalone: true\n")+ _make_profile(hermes_home, "coder", state=None, desired_state="running")++ actions = reconcile_profile_gateways(+ hermes_home=hermes_home, scandir=tmp_path / "svc", dry_run=True, container_argv=())++ by_profile = {a.profile: a for a in actions}+ assert by_profile["solo"].action == "started" and by_profile["solo"].folded_into_root is False+ assert by_profile["coder"].action == "registered" and by_profile["coder"].folded_into_root is True+ assert by_profile["default"].action == "started"++def test_a_stopped_fleet_still_boots_nothing(tmp_path: Path) -> None:"""Control: no autostart intent anywhere means no gateway is started — the crash-loop guardand the operator's `gateway stop` both keep working."""diff --git a/website/docs/user-guide/multi-profile-gateways.md b/website/docs/user-guide/multi-profile-gateways.mdindex bb82a5fba9d..df72fdd0c49 100644--- a/website/docs/user-guide/multi-profile-gateways.md+++ b/website/docs/user-guide/multi-profile-gateways.md@@ -327,7 +327,10 @@ A standalone profile's adapters, cron, webhook ingress and Kanbannotifications run only while its own gateway runs, not under the hostmultiplexer or `hermes serve`. Point webhook clients at the standalonegateway's own listener; the host's `/p/<profile>/` ingress no longer serves-it. The cron destination picker still lists standalone profiles as+it. That listener resolves its port from the profile's own `.env` or+`config.yaml`, so when both it and the host gateway enable the API server or+webhook ingress, give the profile its own `API_SERVER_PORT` / `WEBHOOK_PORT`;+two gateways left on the defaults both try to bind them. The cron destination picker still lists standalone profiles as`bot-chat:<name>` targets, but the host cannot deliver to those targets.`hermes -p coder gateway status` prints `standalone by config@@ -1256,7 +1259,8 @@ single failed apply so that no profile is left without a gateway.Not covered automatically: s6-supervised containers — they converge on the nextcontainer start (the per-profile slots are registered down and the root gateway-multiplexes). Windows Scheduled Tasks are folded by the command. The dashboard's+multiplexes; a `gateway.standalone: true` profile boots its own slot from its own+run intent instead). Windows Scheduled Tasks are folded by the command. The dashboard'sSystem page offers the same migration as a button when the preflight finds aneligible install.