fix(cli): report a named profile as running when the default multiplexer serves it
`hermes gateway status`, `hermes gateway list`, `hermes profile list/show` and the dashboard profiles payload keyed liveness off the profile's own gateway.pid / gateway_state.json, so a satellite profile served by the default multiplexer (gateway.multiplex_profiles) showed "not running" even though the multiplexer is its live inbound process. Reuse the single lookup the start guard and cron liveness already share — named_profile_served_by_running_multiplexer() — with an optional profile_name so list surfaces can ask about any profile, and OR it into gateway_running for named profiles. Default profile and unserved named profiles are unchanged. Salvage of #69118 rebased onto the shared helper (which post-dates it). Co-authored-by: Isaac Dobson <isaac@dobsonheadlights.com> Co-authored-by: Mushisushi28 <133449918+Mushisushi28@users.noreply.github.com>
This commit is contained in:
+19
-9
@@ -2219,14 +2219,17 @@ def _gateway_list() -> None:
|
||||
label += " (current)"
|
||||
parts = [f" {marker} {label:<24s}"]
|
||||
if prof.gateway_running:
|
||||
pid = None
|
||||
try:
|
||||
from gateway.status import get_running_pid
|
||||
|
||||
pid = get_running_pid(prof.path / "gateway.pid", cleanup_stale=False)
|
||||
if pid:
|
||||
parts.append(f"PID {pid}")
|
||||
except Exception:
|
||||
pass
|
||||
if pid:
|
||||
parts.append(f"PID {pid}")
|
||||
elif named_profile_served_by_running_multiplexer(prof.name):
|
||||
parts.append("served by the default multiplexer")
|
||||
else:
|
||||
parts.append("not running")
|
||||
print(" — ".join(parts))
|
||||
@@ -6276,18 +6279,20 @@ def _running_under_gateway_supervisor() -> bool:
|
||||
return is_gateway_supervisor_process()
|
||||
|
||||
|
||||
def named_profile_served_by_running_multiplexer() -> bool:
|
||||
def named_profile_served_by_running_multiplexer(profile_name: str | None = None) -> bool:
|
||||
"""True when a live default multiplexer already ticks this named profile.
|
||||
|
||||
Shared by the named-profile start guard and cron liveness: a satellite
|
||||
profile has no gateway.pid of its own, but the default multiplexer's
|
||||
ticker still fires its jobs (#97120).
|
||||
Shared by the named-profile start guard, cron liveness, and the
|
||||
``gateway status`` / ``gateway list`` / ``profile list`` reports: a
|
||||
satellite profile has no gateway.pid of its own, but the default
|
||||
multiplexer's ticker still fires its jobs (#97120) and serves its
|
||||
platforms. ``profile_name`` defaults to the current HERMES_HOME profile.
|
||||
"""
|
||||
try:
|
||||
suffix = _profile_suffix()
|
||||
suffix = profile_name if profile_name is not None else _profile_suffix()
|
||||
except Exception:
|
||||
return False
|
||||
if not suffix:
|
||||
if not suffix or suffix == "default":
|
||||
return False
|
||||
|
||||
try:
|
||||
@@ -9071,7 +9076,12 @@ def _gateway_command_inner(args):
|
||||
from hermes_cli import gateway_windows
|
||||
|
||||
_windows_service_installed = gateway_windows.is_installed()
|
||||
if supports_systemd_services() and (
|
||||
if not snapshot.running and named_profile_served_by_running_multiplexer():
|
||||
# Satellite profile: no gateway.pid / service of its own, but the
|
||||
# default multiplexer is the live inbound process for it.
|
||||
print("✓ Gateway is running via the default-profile multiplexer")
|
||||
print(" Manage it from the default profile: hermes gateway status")
|
||||
elif supports_systemd_services() and (
|
||||
get_systemd_unit_path(system=False).exists()
|
||||
or get_systemd_unit_path(system=True).exists()
|
||||
):
|
||||
|
||||
+2
-1
@@ -11462,6 +11462,7 @@ def cmd_profile(args):
|
||||
profile_exists,
|
||||
_read_config_model,
|
||||
_check_gateway_running,
|
||||
_served_by_running_multiplexer,
|
||||
_count_skills,
|
||||
_read_distribution_meta,
|
||||
_get_wrapper_dir,
|
||||
@@ -11475,7 +11476,7 @@ def cmd_profile(args):
|
||||
sys.exit(1)
|
||||
profile_dir = get_profile_dir(name)
|
||||
model, provider = _read_config_model(profile_dir)
|
||||
gw = _check_gateway_running(profile_dir)
|
||||
gw = _check_gateway_running(profile_dir) or _served_by_running_multiplexer(name)
|
||||
skills = _count_skills(profile_dir)
|
||||
dist_name, dist_version, dist_source = _read_distribution_meta(profile_dir)
|
||||
alias_name = find_alias_for_profile(name)
|
||||
|
||||
+20
-1
@@ -838,6 +838,22 @@ def _check_gateway_running(profile_dir: Path) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _served_by_running_multiplexer(profile_name: str) -> bool:
|
||||
"""True when the live default gateway multiplexes ``profile_name``.
|
||||
|
||||
A served named profile has no gateway.pid of its own, so
|
||||
``_check_gateway_running`` alone reports it stopped while the default
|
||||
multiplexer is actually its inbound process. Single shared lookup with the
|
||||
named-profile start guard and cron liveness (#97120).
|
||||
"""
|
||||
try:
|
||||
from hermes_cli.gateway import named_profile_served_by_running_multiplexer
|
||||
|
||||
return named_profile_served_by_running_multiplexer(profile_name)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
# In-process cache for skill counts. Walking ``skills_dir.rglob("SKILL.md")``
|
||||
# recurses the entire skill tree (each skill carries references/scripts/assets
|
||||
# sub-trees); the default profile alone has ~270 skills, and ``list_profiles``
|
||||
@@ -1084,7 +1100,10 @@ def list_profiles() -> List[ProfileInfo]:
|
||||
name=name,
|
||||
path=entry,
|
||||
is_default=False,
|
||||
gateway_running=_check_gateway_running(entry),
|
||||
gateway_running=(
|
||||
_check_gateway_running(entry)
|
||||
or _served_by_running_multiplexer(name)
|
||||
),
|
||||
model=model,
|
||||
provider=provider,
|
||||
has_env=(entry / ".env").exists(),
|
||||
|
||||
@@ -15142,7 +15142,13 @@ def _fallback_profile_dicts(profiles_mod) -> List[Dict[str, Any]]:
|
||||
"provider": provider,
|
||||
"has_env": _safe(lambda entry=entry_path: (entry / ".env").exists(), False),
|
||||
"skill_count": _safe(lambda entry=entry_path: profiles_mod._count_skills(entry), 0),
|
||||
"gateway_running": _safe(lambda entry=entry_path: profiles_mod._check_gateway_running(entry), False),
|
||||
"gateway_running": _safe(
|
||||
lambda entry=entry_path, name=entry.name: (
|
||||
profiles_mod._check_gateway_running(entry)
|
||||
or profiles_mod._served_by_running_multiplexer(name)
|
||||
),
|
||||
False,
|
||||
),
|
||||
"description": _safe(lambda entry=entry_path: profiles_mod.read_profile_meta(entry).get("description", ""), ""),
|
||||
"description_auto": _safe(lambda entry=entry_path: profiles_mod.read_profile_meta(entry).get("description_auto", False), False),
|
||||
"distribution_name": None,
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
"""PR #69118: a named profile served by the default multiplexer reports as running.
|
||||
|
||||
``hermes gateway status`` / ``gateway list`` / ``profile list`` keyed liveness
|
||||
off the profile's own gateway.pid, so a satellite profile served by the default
|
||||
multiplexer showed "not running" even though the multiplexer was its live
|
||||
inbound process. All three now consult the same
|
||||
``named_profile_served_by_running_multiplexer()`` lookup the start guard and
|
||||
cron liveness use.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import os
|
||||
from contextlib import redirect_stdout
|
||||
from types import SimpleNamespace
|
||||
|
||||
|
||||
def _fake_multiplexer(monkeypatch, tmp_path, *, multiplex: bool):
|
||||
import hermes_constants
|
||||
import gateway.status as status
|
||||
|
||||
(tmp_path / "profiles" / "beta").mkdir(parents=True)
|
||||
(tmp_path / "config.yaml").write_text(
|
||||
f"gateway:\n multiplex_profiles: {'true' if multiplex else 'false'}\n"
|
||||
)
|
||||
(tmp_path / "gateway.pid").write_text(str(os.getpid()))
|
||||
monkeypatch.setenv("HERMES_HOME", str(tmp_path / "profiles" / "beta"))
|
||||
monkeypatch.setattr(hermes_constants, "_default_hermes_root_memo", None)
|
||||
monkeypatch.setattr(status, "_pid_exists", lambda pid: True)
|
||||
|
||||
|
||||
def _run_status():
|
||||
from hermes_cli import gateway as gw
|
||||
|
||||
buf = io.StringIO()
|
||||
with redirect_stdout(buf):
|
||||
gw._gateway_command_inner(
|
||||
SimpleNamespace(gateway_command="status", deep=False, full=False, system=False)
|
||||
)
|
||||
return buf.getvalue().splitlines()[0]
|
||||
|
||||
|
||||
def test_served_named_profile_reports_running(monkeypatch, tmp_path):
|
||||
from hermes_cli.profiles import list_profiles
|
||||
|
||||
_fake_multiplexer(monkeypatch, tmp_path, multiplex=True)
|
||||
|
||||
beta = next(p for p in list_profiles() if p.name == "beta")
|
||||
assert beta.gateway_running is True
|
||||
assert _run_status().startswith("✓ Gateway is running via the default-profile multiplexer")
|
||||
|
||||
|
||||
def test_unserved_named_profile_still_reports_stopped(monkeypatch, tmp_path):
|
||||
from hermes_cli.profiles import list_profiles
|
||||
|
||||
_fake_multiplexer(monkeypatch, tmp_path, multiplex=False)
|
||||
|
||||
beta = next(p for p in list_profiles() if p.name == "beta")
|
||||
assert beta.gateway_running is False
|
||||
assert _run_status().startswith("✗ Gateway is not running")
|
||||
Reference in New Issue
Block a user