The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): the persisted gateway record names its entry point under an inline launcher (#124029, #123151)
teknium1390e6d504c22
diff --git a/gateway/status.py b/gateway/status.pyindex 9094b4ae6b7..4f50d3ee5f5 100644--- a/gateway/status.py+++ b/gateway/status.py@@ -877,9 +877,25 @@ def _record_matches_live_gateway_pid(return expected_home is None or _command_line_belongs_to_profile(live_cmdline, expected_home)+def _record_argv() -> list[str]:+ """``sys.argv`` with the inline-source placeholder replaced by the entry point this process runs.++ The published launcher script (``_launchers._launcher_script``: the POSIX ``bin/hermes`` shell+ launcher and the Windows ``.cmd``) imports ``hermes_cli.main`` inside ``python -I -c <script>``,+ so ``sys.argv`` is ``["-c", "gateway", "run"]`` — a record the argv matcher can never accept+ once the live command line is unreadable (Windows/EACCES fallback in+ ``_record_matches_live_gateway_pid``). Recording the module path follows runpy's ``alter_sys``+ convention, which is what the ``--run-module`` and store-launcher forms already persist."""+ argv = list(sys.argv)+ entry = sys.modules.get("hermes_cli.main")+ if argv[:1] == ["-c"] and getattr(entry, "__file__", None):+ argv[0] = entry.__file__+ return argv++def _build_pid_record() -> dict:return {- "pid": os.getpid(), "kind": _GATEWAY_KIND, "argv": list(sys.argv),+ "pid": os.getpid(), "kind": _GATEWAY_KIND, "argv": _record_argv(),"start_time": _get_process_start_time(os.getpid()),# Scoped locks are machine-global; the owner's home lets a cross-profile# --replace place its takeover marker where the target will read it.diff --git a/tests/gateway/test_status.py b/tests/gateway/test_status.pyindex 0ebb171abdc..d715128431a 100644--- a/tests/gateway/test_status.py+++ b/tests/gateway/test_status.py@@ -1762,6 +1762,21 @@ def test_strict_gateway_identity_rejects_reused_pid(tmp_path, monkeypatch):status.get_running_pid_identity_strict(pid_path)+def test_pid_record_names_the_entry_point_under_an_inline_launcher(tmp_path, monkeypatch):+ """The published launcher script runs `python -I -c <script> gateway run`, so sys.argv[0] is+ "-c"; the persisted record must still read as a gateway when the live cmdline is unreadable+ (#124029, #123151)."""+ import types++ entry = types.SimpleNamespace(__file__="/opt/Hermes Agent/hermes-agent/hermes_cli/main.py")+ monkeypatch.setitem(status.sys.modules, "hermes_cli.main", entry)+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ monkeypatch.setattr(status.sys, "argv", ["-c", "gateway", "run"])+ record = status._build_pid_record()+ assert record["argv"] == [entry.__file__, "gateway", "run"]+ assert status._record_looks_like_gateway(record)++def test_retained_gateway_state_keeps_watchdog_degraded_like_startup_failed():"""A watchdog-stamped ``degraded`` of a dead process is a current failure under the same rule as``startup_failed`` (#113372): kept while the operator wants the gateway running, ``stopped`` once