The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): detached runtime works headless and keeps secrets out of its stdio log
teknium19fa7c0bc2e71
diff --git a/gateway/run.py b/gateway/run.pyindex 9e00d1594d7..c4ea44d521f 100644--- a/gateway/run.py+++ b/gateway/run.py@@ -969,7 +969,18 @@ def _warm_turn_machinery_sync() -> int:import run_agent # noqa: F401 # heavy import graph, cached in sys.modulesimport model_tools- tool_defs = model_tools.get_tool_definitions(quiet_mode=True)+ # Warm the schemas the turn will actually build: the profile's own toolsets (`video`, `image_gen`+ # and friends rebuild their schema from a vendor catalog over the network; ``None`` = every+ # registered tool, which dials OpenRouter/DeepInfra for profiles that never enabled them).+ enabled_toolsets = None+ try:+ from hermes_cli.config import load_config_readonly+ from hermes_cli.tools_config import _get_platform_tools++ enabled_toolsets = sorted(_get_platform_tools(load_config_readonly(), "cli"))+ except Exception:+ logger.debug("platform toolset resolution failed; warming the full tool surface", exc_info=True)+ tool_defs = model_tools.get_tool_definitions(enabled_toolsets=enabled_toolsets, quiet_mode=True)from hermes_cli.config import load_config_readonlyagent_cfg = load_config_readonly().get("agent")diff --git a/gateway/session_a2a.py b/gateway/session_a2a.pyindex 7cbb89206c1..e0c6d975f35 100644--- a/gateway/session_a2a.py+++ b/gateway/session_a2a.py@@ -114,7 +114,9 @@ async def forward_to_owner(home, *, agent, tenant, peer, context_id, input_id, tticket = await asyncio.to_thread(_session_ticket, home, ready.endpoint)url = ready.endpoint.api_origin.replace('https:', 'wss:').replace('http:', 'ws:') + '/api/ws'protocols = ['hermes-gateway-v1', 'hermes-gateway-ticket.' + ticket]- async with connect(url, subprotocols=protocols, open_timeout=10, max_size=8 * 1024 * 1024) as ws:+ # Loopback authority dial: never through HTTP(S)_PROXY (websockets>=14 honours it by default).+ async with connect(url, subprotocols=protocols, open_timeout=10, max_size=8 * 1024 * 1024,+ proxy=None) as ws:if ws.subprotocol != protocols[0]:raise GatewayClientError('gateway_protocol_mismatch')async with GatewayClient(ws) as client:diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.pyindex ae92cc20c30..5c23c47498b 100644--- a/hermes_cli/gateway.py+++ b/hermes_cli/gateway.py@@ -3811,6 +3811,11 @@ def _guard_supervised_gateway_conflict(force: bool = False) -> None:"""if force or _running_under_gateway_supervisor():return+ # Every entrypoint now ensures a detached gateway, so this runs on hosts with no service at+ # all (headless runners with no user bus). Without an installed unit/plist/task there is+ # nothing to conflict with; probing the manager anyway is the only systemctl call left.+ if not _is_service_installed():+ returntry:snapshot = get_gateway_runtime_snapshot()except Exception:@@ -4042,6 +4047,9 @@ def run_gateway(verbose: int = 0, quiet: bool = False, replace: bool = False, foexcept Exception:pass # best-effort; don't block gateway startup+ if _gateway_detached_env():+ from hermes_logging import redact_detached_stdio+ redact_detached_stdio()from gateway.run import start_gatewayprint("┌─────────────────────────────────────────────────────────┐")print("│ ☤ Hermes Gateway Starting... │")diff --git a/hermes_cli/gateway_client.py b/hermes_cli/gateway_client.pyindex c8cb7732548..e561a05f302 100644--- a/hermes_cli/gateway_client.py+++ b/hermes_cli/gateway_client.py@@ -131,7 +131,11 @@ async def connect_gateway():url = endpoint.api_origin.replace("https:", "wss:").replace("http:", "ws:") + "/api/ws"protocols = ["hermes-gateway-v1", "hermes-gateway-ticket." + ticket]try:- async with connect(url, subprotocols=protocols, open_timeout=10, max_size=8 * 1024 * 1024) as ws:+ # The gateway is a loopback (or explicitly named) peer, never something to route through the+ # user's HTTP(S) proxy; websockets>=14 reads HTTP_PROXY/HTTPS_PROXY by default and a proxy that+ # cannot reach 127.0.0.1 turns every launch into a 10 s open timeout.+ async with connect(url, subprotocols=protocols, open_timeout=10, max_size=8 * 1024 * 1024,+ proxy=None) as ws:if protocols and ws.subprotocol != "hermes-gateway-v1":raise GatewayClientError("Gateway protocol mismatch; update/restart required")async with GatewayClient(ws) as client:diff --git a/hermes_logging.py b/hermes_logging.pyindex 78db2d9ed4a..d5340665eb9 100644--- a/hermes_logging.py+++ b/hermes_logging.py@@ -104,6 +104,30 @@ def _safe_stderr(): # type: ignore[return]return stream # best-effort: no buffer / wrapping failed -> original stream+class _RedactingStdio:+ """Text stream proxy that redacts each write: a detached gateway's stdout/stderr IS a+ persisted log (``logs/gateway-stdio.log``), and agent status lines (provider error echoes)+ reach it through ``print``, never through ``RedactingFormatter``."""++ def __init__(self, stream):+ self._stream = stream++ def write(self, text):+ from agent.redact import redact_sensitive_text+ return self._stream.write(redact_sensitive_text(text) if isinstance(text, str) else text)++ def __getattr__(self, name):+ return getattr(self._stream, name)+++def redact_detached_stdio() -> None:+ """Route a detached process's stdout/stderr through secret redaction (idempotent)."""+ for name in ("stdout", "stderr"):+ stream = getattr(sys, name)+ if stream is not None and not isinstance(stream, _RedactingStdio):+ setattr(sys, name, _RedactingStdio(stream))++def _is_windows_concurrent_log_lock_timeout(exc: BaseException | None) -> bool:"""True for concurrent-log-handler's Windows lock timeout.diff --git a/tools/bot_live_delivery.py b/tools/bot_live_delivery.pyindex 8da2846f824..09909182b88 100644--- a/tools/bot_live_delivery.py+++ b/tools/bot_live_delivery.py@@ -77,8 +77,9 @@ def authority_delivery(home, params):endpoint = discovery.endpointticket = await asyncio.to_thread(_session_ticket, home, endpoint)url = endpoint.api_origin.replace('http:', 'ws:').replace('https:', 'wss:') + '/api/ws'+ # Loopback authority dial: never through HTTP(S)_PROXY (websockets>=14 honours it by default).async with connect(url, subprotocols=['hermes-gateway-v1', 'hermes-gateway-ticket.' + ticket],- open_timeout=10) as ws:+ open_timeout=10, proxy=None) as ws:if ws.subprotocol != 'hermes-gateway-v1':raise ValueError('authority protocol mismatch')async with GatewayClient(ws) as client: