Skip to content

The agent that grows with you

fix: reject FIFO gateway metadata without blocking discovery

Teknium5b0f0276eb21
diff --git a/hermes_cli/gateway_runtime_discovery.py b/hermes_cli/gateway_runtime_discovery.py
index 648ba48a100..12735b3f5d3 100644
--- a/hermes_cli/gateway_runtime_discovery.py
+++ b/hermes_cli/gateway_runtime_discovery.py
@@ -35,7 +35,9 @@ def _socket_path(home: Path) -> Path:
_private_node(direct, kind="socket")
return direct
pointer = home / "gateway.sock.path"
- with os.fdopen(os.open(pointer, os.O_RDONLY | os.O_NOFOLLOW), "rb") as stream: # windows-footgun: ok — binary POSIX descriptor
+ # Reject non-regular metadata before a FIFO can wait for a writer.
+ flags = os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK # windows-footgun: ok — POSIX socket discovery only
+ with os.fdopen(os.open(pointer, flags), "rb") as stream: # windows-footgun: ok — binary POSIX descriptor
metadata = os.fstat(stream.fileno())
if (not stat.S_ISREG(metadata.st_mode) or metadata.st_uid != os.getuid() # windows-footgun: ok — POSIX pointer only
or stat.S_IMODE(metadata.st_mode) & 0o077):
diff --git a/tests/hermes_cli/test_gateway_runtime.py b/tests/hermes_cli/test_gateway_runtime.py
index c3aecc97ba0..0b497abc24e 100644
--- a/tests/hermes_cli/test_gateway_runtime.py
+++ b/tests/hermes_cli/test_gateway_runtime.py
@@ -75,6 +75,33 @@ def test_live_discovery_does_not_treat_an_unusable_owner_as_absent(tmp_path):
asyncio.run(probe())
+def test_fifo_control_pointer_is_rejected_without_a_writer(tmp_path):
+ import os
+ import subprocess
+ import sys
+
+ home = tmp_path / 'fifo-profile'
+ home.mkdir(mode=0o700)
+ os.mkfifo(home / 'gateway.sock.path', 0o600)
+ code = (
+ 'import sys; from pathlib import Path; '
+ 'from hermes_cli.gateway_runtime import discover_gateway_endpoint; '
+ 'r = discover_gateway_endpoint(Path(sys.argv[1]), timeout=0.1); '
+ 'print(r.state, r.reason_code)'
+ )
+ try:
+ result = subprocess.run(
+ [sys.executable, '-c', code, str(home)],
+ cwd=Path(__file__).resolve().parents[2], stdin=subprocess.DEVNULL,
+ capture_output=True, text=True, timeout=3,
+ )
+ except subprocess.TimeoutExpired:
+ pytest.fail('discovery blocked on a FIFO instead of rejecting its file type')
+ assert result.returncode == 0, result.stderr
+ assert result.stdout.strip() == 'inaccessible unsafe_control_pointer'
+
+
def test_start_decisions_do_not_turn_uncertainty_into_another_owner():
from gateway.runtime_contract import RuntimeObservation, next_start_action