The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): multiplex cron fire URL uses the default profile's listener port
berg357062f39e29
diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.pyindex cb5add9112b..1a1344c364b 100644--- a/hermes_cli/web_server.py+++ b/hermes_cli/web_server.py@@ -13519,35 +13519,62 @@ def _gateway_fire_endpoint(profile: str, home: Path) -> str:"""Resolve the loopback URL of the gateway api_server's cron-fire route.Port resolution mirrors gateway/config.py's api_server load order for the- TARGET profile: ``platforms.api_server.extra.port`` in the profile's- config.yaml, then ``API_SERVER_PORT`` (process env for the active profile,- the profile's own .env otherwise), then the adapter default 8642. The bind- host is the adapter's loopback default — the dashboard and gateway share a- network namespace in every supported deployment (same host process tree,- or the same container under s6).+ LISTENER-OWNER profile: ``platforms.api_server.extra.port`` in that+ profile's config.yaml, then ``API_SERVER_PORT`` (process env for the+ active profile, the profile's own .env otherwise), then the adapter+ default 8642. The bind host is the adapter's loopback default — the+ dashboard and gateway share a network namespace in every supported+ deployment (same host process tree, or the same container under s6).Multiplex mode (one gateway serving several profiles) exposes per-profilemirrors under ``/p/<profile>/…``, so a non-default profile routes through- the default gateway's port with that prefix; per-profile-gateway mode- (each profile its own process/port) uses the bare path on the profile's- own port.+ the default gateway's port with that prefix — only the DEFAULT profile's+ api_server is bound in that mode, so the port must be read from the+ default home, never the target profile's (a secondary's own+ ``API_SERVER_PORT`` is a port nothing listens on). Per-profile-gateway+ mode (each profile its own process/port) uses the bare path on the+ profile's own port."""import os as _os+ multiplex = False+ try:+ from gateway.config import _env_multiplex_profiles_override++ cfg = load_config()+ multiplex = bool(cfg_get(cfg, "gateway", "multiplex_profiles", default=False))+ env_flag = _env_multiplex_profiles_override()+ if env_flag is not None:+ multiplex = env_flag+ except Exception:+ _log.debug("cron fire: multiplex detection failed; assuming single-profile", exc_info=True)++ listener_profile, listener_home = profile, home+ if multiplex and profile != "default":+ from hermes_constants import get_default_hermes_root++ listener_profile, listener_home = "default", get_default_hermes_root()+ _log.info(+ "cron fire: multiplex gateway — resolving api_server port for %s "+ "from the default profile's listener (%s)",+ profile,+ listener_home,+ )+port = 0try:# Profile-scoped read through the CANONICAL loader (managed-scope# overlay, ${ENV_VAR} expansion, profile pathing) — never a raw# yaml.safe_load of config.yaml (tests/hermes_cli/# test_config_read_guard.py). The HERMES_HOME override scopes- # get_config_path() to the TARGET profile, same pattern the+ # get_config_path() to the LISTENER-OWNER profile, same pattern the# deprecated _fire_cron_job_for_profile used for its store scope.from hermes_constants import (reset_hermes_home_override,set_hermes_home_override,)- token = set_hermes_home_override(str(home))+ token = set_hermes_home_override(str(listener_home))try:profile_cfg = load_config()finally:@@ -13562,8 +13589,8 @@ def _gateway_fire_endpoint(profile: str, home: Path) -> str:if not port:raw = (_os.getenv("API_SERVER_PORT", "")- if profile == _cron_default_profile()- else _profile_env_value(home, "API_SERVER_PORT")+ if listener_profile == _cron_default_profile()+ else _profile_env_value(listener_home, "API_SERVER_PORT"))try:port = int(raw) if raw else 0@@ -13572,18 +13599,6 @@ def _gateway_fire_endpoint(profile: str, home: Path) -> str:if not port:port = 8642- multiplex = False- try:- cfg = load_config()- multiplex = bool(cfg_get(cfg, "gateway", "multiplex_profiles", default=False))- env_flag = _os.getenv("GATEWAY_MULTIPLEX_PROFILES", "").strip().lower()- if env_flag in {"1", "true", "yes", "on"}:- multiplex = True- elif env_flag in {"0", "false", "no", "off"}:- multiplex = False- except Exception:- pass-if multiplex and profile != "default":return f"http://127.0.0.1:{port}/p/{profile}/api/cron/fire"return f"http://127.0.0.1:{port}/api/cron/fire"diff --git a/tests/hermes_cli/test_cron_fire_dashboard.py b/tests/hermes_cli/test_cron_fire_dashboard.pyindex aa898bf78ef..d6d406398d3 100644--- a/tests/hermes_cli/test_cron_fire_dashboard.py+++ b/tests/hermes_cli/test_cron_fire_dashboard.py@@ -250,6 +250,41 @@ def test_fire_endpoint_multiplex_profile_prefix(tmp_path, monkeypatch):assert url == "http://127.0.0.1:8642/p/worker_alpha/api/cron/fire"+def test_fire_endpoint_multiplex_reads_port_from_default_listener(tmp_path, monkeypatch):+ """Multiplex mode: only the DEFAULT profile's api_server is bound, so a+ secondary's fire URL must use the default home's port — not the+ secondary's own config.yaml/.env port, which nothing listens on+ (PR #84755). Real config files, real load_config()."""+ default_home = tmp_path / "root"+ worker_home = default_home / "profiles" / "worker_alpha"+ default_home.mkdir()+ worker_home.mkdir(parents=True)+ (default_home / "config.yaml").write_text(+ "gateway:\n multiplex_profiles: true\n"+ "platforms:\n api_server:\n extra:\n port: 8650\n",+ encoding="utf-8",+ )+ (worker_home / "config.yaml").write_text(+ "platforms:\n api_server:\n enabled: false\n extra:\n port: 8702\n",+ encoding="utf-8",+ )+ (worker_home / ".env").write_text("API_SERVER_PORT=8701\n", encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(default_home))+ monkeypatch.delenv("API_SERVER_PORT", raising=False)+ monkeypatch.delenv("GATEWAY_MULTIPLEX_PROFILES", raising=False)+ monkeypatch.setattr(web_server, "_cron_default_profile", lambda: "default")++ url = web_server._gateway_fire_endpoint("worker_alpha", worker_home)++ assert url == "http://127.0.0.1:8650/p/worker_alpha/api/cron/fire"+ # The GATEWAY_MULTIPLEX_PROFILES env override is still honored (parity+ # with gateway/config.py): forcing it off restores per-profile routing.+ monkeypatch.setenv("GATEWAY_MULTIPLEX_PROFILES", "0")+ assert web_server._gateway_fire_endpoint("worker_alpha", worker_home) == (+ "http://127.0.0.1:8702/api/cron/fire"+ )++# ── OOF-266: intentional-stop drop + Retry-After on transient 503 ─────────