The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: discover private gateway sockets across native temp roots
Tekniumde66df140032
diff --git a/hermes_cli/gateway_runtime_discovery.py b/hermes_cli/gateway_runtime_discovery.pyindex 3d82590aed9..756822617f3 100644--- a/hermes_cli/gateway_runtime_discovery.py+++ b/hermes_cli/gateway_runtime_discovery.py@@ -47,8 +47,11 @@ def _socket_path(home: Path) -> Path:target = Path(data.decode("utf-8").strip())if not target.is_absolute():raise DiscoveryError("invalid_control_pointer")- from gateway.control_socket import _fallback_socket_path- if target != _fallback_socket_path(home):+ from gateway.control_socket import _home_hash+ # The owner may have a different TMPDIR (notably launchd/native apps).+ # Authenticate its private pointer and profile-specific directory, not our+ # process-local temporary-root preference.+ if target.name != "control.sock" or target.parent.name != f"hermes-gw-{_home_hash(home)}":raise DiscoveryError("invalid_control_pointer")directory = _private_node(target.parent, kind="directory")if directory.st_mode & 0o077:diff --git a/tests/hermes_cli/test_gateway_runtime_discovery.py b/tests/hermes_cli/test_gateway_runtime_discovery.pynew file mode 100644index 00000000000..7ea5105c70b--- /dev/null+++ b/tests/hermes_cli/test_gateway_runtime_discovery.py@@ -0,0 +1,55 @@+"""Private discovery must not assume another process shares its temp root."""+import json+import socket+import tempfile+import threading+from pathlib import Path++import pytest++from gateway.control_socket import _home_hash+from hermes_cli.gateway_runtime_discovery import DiscoveryError, query_identify++[email protected]_only+def test_fallback_pointer_uses_owner_location_and_keeps_identity_checks(tmp_path):+ home = tmp_path / 'profile'+ home.mkdir(mode=0o700)+ # The owner has a distinct TMPDIR, as a service or native app commonly does.+ with tempfile.TemporaryDirectory(prefix='h-owner-') as root:+ directory = Path(root) / f'hermes-gw-{_home_hash(home)}'+ directory.mkdir(mode=0o700)+ target = directory / 'control.sock'+ pointer = home / 'gateway.sock.path'+ pointer.write_text(str(target), encoding='utf-8')+ pointer.chmod(0o600)+ with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as server:+ server.bind(str(target))+ target.chmod(0o600)+ server.listen(1)+ server.settimeout(3)+ requests = []++ def respond():+ try:+ peer, _ = server.accept()+ with peer:+ requests.append(peer.recv(4096))+ peer.sendall(b'{"ok":true,"protocol":1,"id":1,"result":{"state":"ready"}}\n')+ except TimeoutError:+ return++ thread = threading.Thread(target=respond)+ thread.start()+ try:+ assert query_identify(home, timeout=2) == {'state': 'ready'}+ finally:+ thread.join(timeout=4)+ assert json.loads(requests[0])['verb'] == 'identify'+ pointer.write_text(str(directory.with_name('hermes-gw-wrong') / 'control.sock'), encoding='utf-8')+ with pytest.raises(DiscoveryError, match='invalid_control_pointer'):+ query_identify(home, timeout=2)+ pointer.write_text(str(target), encoding='utf-8')+ directory.chmod(0o755)+ with pytest.raises(DiscoveryError, match='unsafe_control_permissions'):+ query_identify(home, timeout=2)