The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: HERMES_HOME argv values containing a space still identify their own gateway (review follow-up)
teknium19cb5c8ae09e2
diff --git a/gateway/status.py b/gateway/status.pyindex 71ca5be41cd..5654de09fb8 100644--- a/gateway/status.py+++ b/gateway/status.py@@ -575,6 +575,16 @@ def hermes_home_assignments(command: str) -> list[str]:]+def command_line_names_hermes_home(command_lc: str, home_lc: str) -> bool:+ """True when ``command_lc`` carries ``HERMES_HOME=<home_lc>`` (both lowercased, ``/``-separated,+ no trailing separator). Argv reaches us space-joined, so an unquoted value with a space in it+ (``HERMES_HOME=C:/Users/John Doe/.hermes``) is cut at the space by the token parser; a+ token-bounded literal match of the whole home recovers that spelling."""+ if home_lc in hermes_home_assignments(command_lc):+ return True+ return re.search(rf"(?:^|\s)hermes_home={re.escape(home_lc)}/?(?=\s|$)", command_lc) is not None++def _command_line_belongs_to_profile(command: str, profile_home: Path) -> bool:"""True when a gateway command line belongs to ``profile_home`` (mirrors``hermes_cli.gateway._matches_current_profile``): a stale state file can record a PID recycled@@ -586,15 +596,14 @@ def _command_line_belongs_to_profile(command: str, profile_home: Path) -> bool:if profile_name is not None and profile_name != "default":if profile_flag_value(command_lc) == profile_name.lower():return True- return home_lc in hermes_home_assignments(command_lc)+ return command_line_names_hermes_home(command_lc, home_lc)# Default profile: accept unless argv names another profile (any spelling the CLI pre-parser# accepts, ``--profile=ops`` included -- a substring test let that gateway pass as the default's)# or a conflicting explicit HERMES_HOME= (its absence is not disqualifying -- HERMES_HOME usually# arrives via the env).if profile_flag_value(command_lc) is not None:return False- assignments = hermes_home_assignments(command_lc)- return not (assignments and home_lc not in assignments)+ return not hermes_home_assignments(command_lc) or command_line_names_hermes_home(command_lc, home_lc)def _record_matches_live_gateway_pid(diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.pyindex 7aefa83a7ca..1682e8424d8 100644--- a/hermes_cli/gateway.py+++ b/hermes_cli/gateway.py@@ -578,6 +578,7 @@ def _scan_gateway_pids(looks_like_gateway_runtime_command_line,profile_flag_value,hermes_home_assignments,+ command_line_names_hermes_home,)current_home = str(get_hermes_home().resolve())# Forward slashes on both sides of the HERMES_HOME= match (mirrors gateway.status), and no@@ -594,7 +595,7 @@ def _scan_gateway_pids(# Token equality, not substring: `-p ops` must not claim (or SIGTERM) an `-p ops-2` gateway.if profile_flag_value(command_lc) == current_profile_name_lc:return True- return current_home_lc in hermes_home_assignments(command_lc)+ return command_line_names_hermes_home(command_lc, current_home_lc)# Default profile: accept unless argv advertises another profile in any spelling the CLI# pre-parser accepts (``--profile=ops`` slipped past a substring test, so a default-profile@@ -602,8 +603,8 @@ def _scan_gateway_pids(# wmic/CIM), so only a non-matching explicit HERMES_HOME= disqualifies.if profile_flag_value(command_lc) is not None:return False- assignments = hermes_home_assignments(command_lc)- return not (assignments and current_home_lc not in assignments)+ return (not hermes_home_assignments(command_lc)+ or command_line_names_hermes_home(command_lc, current_home_lc))def _consider(pid: int, command: str) -> None:matches_runtime = looks_like_gateway_command_line(command) or (diff --git a/tests/gateway/test_status.py b/tests/gateway/test_status.pyindex a4c5f2c428e..f60225df503 100644--- a/tests/gateway/test_status.py+++ b/tests/gateway/test_status.py@@ -408,6 +408,14 @@ class TestGatewayRuntimeStatus:home = Path("/opt/data/profiles/coder with space")assert status._command_line_belongs_to_profile('hermes_home="/opt/data/profiles/coder with space" hermes gateway run', home)+ # /proc and psutil hand argv back space-joined, so an unquoted value with a space is cut at+ # the space by the token parser; the whole-home literal match must still claim it.+ assert status._command_line_belongs_to_profile(+ "HERMES_HOME=/opt/data/profiles/coder with space hermes gateway run", home)+ assert status._command_line_belongs_to_profile(+ r"HERMES_HOME=C:\Users\John Doe\.hermes hermes gateway run", Path(r"C:\Users\John Doe\.hermes"))+ assert not status._command_line_belongs_to_profile(+ "HERMES_HOME=/opt/data/profiles/coder with spaces hermes gateway run", home)home = Path("/fixture/profiles/ops")assert status._command_line_belongs_to_profile("HERMES_HOME=/fixture/profiles/ops/ hermes gateway run", home)assert status._command_line_belongs_to_profile("HERMES_HOME=/opt/hermes-data/ hermes gateway run", Path("/opt/hermes-data"))