The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): restart parked profiles and report live gateways
lorenzozanee61bd7e302bbd
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.pyindex 850982410c6..100d34f3c1c 100644--- a/hermes_cli/gateway.py+++ b/hermes_cli/gateway.py@@ -5614,12 +5614,12 @@ def _status_host_kind() -> str:def _cmd_status(args):from hermes_cli.gateway_profile_lifecycle import print_parked_status- if print_parked_status():- returndeep = getattr(args, "deep", False)full = getattr(args, "full", False)system = getattr(args, "system", False)snapshot = get_gateway_runtime_snapshot(system=system)+ if print_parked_status() and not snapshot.running:+ returnfrom hermes_cli.profiles import get_active_profile_name, profile_is_standaloneactive_standalone = ((get_active_profile_name() or "default") != "default"diff --git a/hermes_cli/gateway_profile_lifecycle.py b/hermes_cli/gateway_profile_lifecycle.pyindex 11330c5d42d..e2c42bd1d3e 100644--- a/hermes_cli/gateway_profile_lifecycle.py+++ b/hermes_cli/gateway_profile_lifecycle.py@@ -41,6 +41,8 @@ def profile_lifecycle(command: str, args) -> bool:# verbs keep addressing its own gateway process even while a stale host record lists it.return Falsemarker = parked_marker_path(home)+ if command == "restart" and profile_is_parked(home) and not gw.find_gateway_pids():+ command = "start"if command == "start":if not profile_is_parked(home):return Falsediff --git a/tests/hermes_cli/test_gateway_multiplex_lifecycle.py b/tests/hermes_cli/test_gateway_multiplex_lifecycle.pyindex 9153e5a5d88..0ce3349e4fb 100644--- a/tests/hermes_cli/test_gateway_multiplex_lifecycle.py+++ b/tests/hermes_cli/test_gateway_multiplex_lifecycle.py@@ -92,6 +92,57 @@ def test_cli_lifecycle_orders_marker_before_socket(homes, monkeypatch, capsys, v'start': "Profile 'worker' served", 'restart': "Profile 'worker' restarted"}[verb] in output+def test_restart_after_stop_unparks_and_serves_the_profile(homes, monkeypatch, capsys):+ from hermes_cli import gateway as gw+ from gateway import control_socket+ root, secondary = homes+ marker = secondary / 'gateway.parked'+ marker.touch()+ owner = SimpleNamespace(home=root, profile_label='default', profiles=('default',),+ describe=lambda: 'test host')+ monkeypatch.setenv('HERMES_HOME', str(secondary))+ monkeypatch.setattr(gw, '_current_profile_name', lambda: 'worker')+ monkeypatch.setattr(gw, '_refuse_from_inside_gateway', lambda *a: None)+ monkeypatch.setattr(gw, 'find_gateway_pids', lambda **kw: [])+ monkeypatch.setattr(gw, '_served_by_another_host_gateway', lambda *a: None)+ monkeypatch.setattr(gw, 'named_profile_served_by_running_multiplexer', lambda *a: False)+ monkeypatch.setattr(gw, '_host_multiplexer_for_all_verb', lambda: owner)+ calls = []++ def serve(home, name):+ assert home == root and name == 'worker' and not marker.exists()+ calls.append('serve')+ return {'served': name, 'served_profiles': ['default', name]}++ def standalone(*args, **kwargs):+ raise AssertionError('restart fell through to the standalone gateway path')++ monkeypatch.setattr(control_socket, 'request_serve_profile_hot', serve)+ monkeypatch.setattr(gw, '_guard_named_profile_under_multiplexer', standalone)+ gw._cmd_restart(SimpleNamespace())+ assert calls == ['serve']+ assert not marker.exists()+ assert "Profile 'worker' served by the host gateway." in capsys.readouterr().out+++def test_force_restart_keeps_parked_profile_gateway_ownership(homes, monkeypatch):+ from hermes_cli import gateway as gw+ _, secondary = homes+ (secondary / 'gateway.parked').touch()+ monkeypatch.setenv('HERMES_HOME', str(secondary))+ monkeypatch.setattr(gw, '_current_profile_name', lambda: 'worker')++ def host_restart(*args, **kwargs):+ raise AssertionError('forced gateway restart was routed through the host')++ monkeypatch.setattr(gw, '_served_by_another_host_gateway', lambda *args: None)+ monkeypatch.setattr(gw, 'named_profile_served_by_running_multiplexer', lambda: False)+ monkeypatch.setattr(gw, '_host_multiplexer_for_all_verb', host_restart)+ monkeypatch.setattr(gw, 'find_gateway_pids', lambda **kwargs: [4242])+ from hermes_cli.gateway_profile_lifecycle import profile_lifecycle+ assert profile_lifecycle('restart', SimpleNamespace()) is False++def test_parked_status_and_topology_keep_roster(homes, monkeypatch, capsys):from hermes_cli import gateway as gw, profilesfrom hermes_cli.web_server_gateway import _collect_profile_gateway_topology@@ -184,3 +235,20 @@ def test_default_status_distinguishes_served_and_parked(homes, monkeypatch, capsoutput = capsys.readouterr().outassert 'Served profiles: default' in outputassert "Profile 'worker': parked" in output+++def test_parked_status_still_reports_a_forced_gateway(homes, monkeypatch, capsys):+ from hermes_cli import gateway as gw, profiles+ root, secondary = homes+ (secondary / 'gateway.parked').touch()+ monkeypatch.setenv('HERMES_HOME', str(secondary))+ monkeypatch.setattr(gw, '_current_profile_name', lambda: 'worker')+ monkeypatch.setattr(profiles, 'get_active_profile_name', lambda: 'worker')+ monkeypatch.setattr(gw, 'get_gateway_runtime_snapshot', lambda system=False: gw.GatewayRuntimeSnapshot(+ manager='manual', gateway_pids=(4242,)))+ monkeypatch.setattr(gw, 'named_profile_served_by_running_multiplexer', lambda: False)+ monkeypatch.setattr(gw, '_installed_service_kind_for', lambda _check: None)+ gw._cmd_status(SimpleNamespace())+ output = capsys.readouterr().out+ assert 'parked (hermes -p worker gateway start)' in output+ assert 'Gateway is running (PID: 4242)' in output