The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): report the original dashboard argv from a failed respawn
liuhao10242ab313e625fc
diff --git a/hermes_cli/main_dashboard.py b/hermes_cli/main_dashboard.pyindex d06e0dc7437..1ea281054b0 100644--- a/hermes_cli/main_dashboard.py+++ b/hermes_cli/main_dashboard.py@@ -412,43 +412,46 @@ def _respawn_dashboard_processes(commands: list[list[str]]) -> list[list[str]]:"""from hermes_constants import get_hermes_homerespawned: list[list[str]] = []- spawned: list[tuple[list[str], "subprocess.Popen"]] = []- failed: list[tuple[list[str], str]] = []+ spawned: list[tuple[list[str], list[str], "subprocess.Popen"]] = []+ failed: list[tuple[list[str], list[str], str]] = []log_path = get_hermes_home() / "logs" / "dashboard-restart.log"with contextlib.suppress(OSError):log_path.parent.mkdir(parents=True, exist_ok=True)- for command in commands:+ for original in commands:+ command = _respawnable_command_for_current_install(original)+ # Keep restarted dashboards headless; reopening a browser after a+ # background update is noisy and fails in SSH/headless sessions.+ if "dashboard" in command and "--no-open" not in command:+ command = [*command, "--no-open"]try:- command = _respawnable_command_for_current_install(command)- # Keep restarted dashboards headless; reopening a browser after a- # background update is noisy and fails in SSH/headless sessions.- if "dashboard" in command and "--no-open" not in command:- command = [*command, "--no-open"]with open(log_path, "ab") as log_f:proc = subprocess.Popen(command, stdin=subprocess.DEVNULL, stdout=log_f, stderr=subprocess.STDOUT,start_new_session=True, close_fds=True)- spawned.append((command, proc))+ spawned.append((original, command, proc))except (OSError, ValueError) as exc:- failed.append((command, str(exc)))+ failed.append((original, command, str(exc)))# A respawned backend is a resident server: one that exits within the grace# window died at startup (SyntaxError on a stale argv, port already bound,# ...) and must surface as a failure, not as ``✓ restarted`` (#124778).- time.sleep(_RESPAWN_LIVENESS_GRACE_SECONDS)- for command, proc in spawned:+ if spawned:+ time.sleep(_RESPAWN_LIVENESS_GRACE_SECONDS)+ for original, command, proc in spawned:if proc.poll() is None:respawned.append(command)else:- failed.append((command, f"child exited during the first "- f"{_RESPAWN_LIVENESS_GRACE_SECONDS:.0f}s (code {proc.returncode})"))+ failed.append((original, command, f"child exited during the first "+ f"{_RESPAWN_LIVENESS_GRACE_SECONDS:.0f}s (code {proc.returncode})"))for command in respawned:print(f" ✓ restarted: {shlex.join(command)}")- for command, err_msg in failed:+ for _, command, err_msg in failed:print(f" ✗ failed to restart ({shlex.join(command)}): {err_msg}")- return [command for command, _ in failed]+ # The caller's argv, not the spawned one: callers match it against the stopped PID's+ # captured cmdline to book the runtime as not brought back (#109290).+ return [original for original, _, _ in failed]class _UpdateOutputStream:diff --git a/tests/hermes_cli/test_update_stale_dashboard.py b/tests/hermes_cli/test_update_stale_dashboard.pyindex d7175824b46..7c2e7c7e753 100644--- a/tests/hermes_cli/test_update_stale_dashboard.py+++ b/tests/hermes_cli/test_update_stale_dashboard.py@@ -552,7 +552,8 @@ class TestManualBackendRespawn:def test_child_exiting_within_the_grace_window_is_a_reported_failure(self, tmp_path, monkeypatch, capsys):"""A respawn that dies at once (parse error on a stale argv, port already bound)- must surface as a failure, never as ``✓ restarted`` (#124778)."""+ must surface as a failure, never as ``✓ restarted`` (#124778), reported with the+ caller's argv so it matches the stopped PID's cmdline (#109290)."""live = self._live()monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))@@ -570,31 +571,10 @@ class TestManualBackendRespawn:failed = live._respawn_dashboard_processes([["hermes", "dashboard", "--port", "8300"]])out = capsys.readouterr().out- assert failed == [["hermes", "dashboard", "--port", "8300", "--no-open"]]+ assert failed == [["hermes", "dashboard", "--port", "8300"]]assert "✓ restarted" not in outassert "✗ failed to restart" in out- def test_python_dash_m_argv_shape_replays_unchanged(self, tmp_path, monkeypatch):- """``[python, -m, hermes_cli.main, ...]`` is not an interpreter+launcher pair;- only that pair is rebuilt, so module-shaped argvs keep replaying verbatim."""- live = self._live()- monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes"))- spawned: list[list[str]] = []-- class _FakePopen:- def __init__(self, cmd, **kwargs):- spawned.append(list(cmd))-- def poll(self):- return None-- captured = ["python", "-m", "hermes_cli.main", "serve", "--port", "8400"]- with patch.object(live.subprocess, "Popen", _FakePopen), \- patch.object(live.time, "sleep"):- live._respawn_dashboard_processes([captured])-- assert spawned == [captured]-class TestFilterDashboardRespawnCandidates:"""Unit tests for respawn filtering / dedupe / orphan skip (#78821)."""