Skip to content

The agent that grows with you

fix(relay): read the opt-out through the loader's own YAML reader

Ben Barclay6f5dda1aee02
diff --git a/gateway/config_loader.py b/gateway/config_loader.py
index dd638e4b96a..fd276eb431d 100644
--- a/gateway/config_loader.py
+++ b/gateway/config_loader.py
@@ -335,10 +335,14 @@ def bridge_core_env_settings(yaml_cfg: dict, platforms_data: dict) -> None:
os.environ["SIGNAL_REQUIRE_MENTION"] = str(signal_cfg["require_mention"]).lower()
-def load_yaml_layer(home: Path, gw_data: dict) -> None:
- """Overlay ``config.yaml`` + managed YAML onto *gw_data* in place. Raises on a malformed user
- file (caller warns + falls back). An ABSENT user file is an empty layer, not a reason to skip
- the administrator's values: a fleet host with no ``config.yaml`` must still honor them.
+def read_yaml_layers(home: Path) -> dict:
+ """User ``config.yaml`` with the managed overlay applied — the YAML the gateway loader sees.
+
+ Raises on a malformed user file (the loader then falls back to env + gateway.json WITHOUT the
+ managed layer). An ABSENT user file is an empty layer, not a reason to skip the administrator's
+ values: a fleet host with no ``config.yaml`` must still honor them. Any pre-activation predicate
+ (``gateway.relay.relay_explicitly_disabled``) reads through here so it cannot disagree with
+ ``load_gateway_config()`` on which files count.
"""
import yaml
@@ -351,7 +355,12 @@ def load_yaml_layer(home: Path, gw_data: dict) -> None:
# Managed scope: overlay administrator-pinned values (this loader bypasses
# hermes_cli.config.load_config, so managed quick_commands / stt would otherwise be ignored).
from hermes_cli import managed_scope
- yaml_cfg = managed_scope.apply_managed_overlay(yaml_cfg)
+ return managed_scope.apply_managed_overlay(yaml_cfg)
+
+
+def load_yaml_layer(home: Path, gw_data: dict) -> None:
+ """Overlay ``read_yaml_layers`` onto *gw_data* in place. Raises on any failure (caller warns + falls back)."""
+ yaml_cfg = read_yaml_layers(home)
if not yaml_cfg:
return
diff --git a/gateway/relay/__init__.py b/gateway/relay/__init__.py
index 148715a65a5..34722d34b1c 100644
--- a/gateway/relay/__init__.py
+++ b/gateway/relay/__init__.py
@@ -73,18 +73,23 @@ def _env_or_cfg_url(env_var: str, cfg_key: str) -> Optional[str]:
def relay_explicitly_disabled() -> bool:
"""``platforms.relay.enabled: false`` in the profile's YAML (user or managed).
- Same merge and boolean normalization as the gateway loader, minus its env/plugin
- side effects, so a standalone scheduler can ask without bootstrapping the gateway.
+ Same files, merge and boolean normalization as the gateway loader (a malformed user
+ file drops the whole YAML layer there too), minus its env/plugin side effects, so a
+ standalone scheduler can ask without bootstrapping the gateway.
Mirrors the loader's ``_enabled_explicit`` rule: only a YAML ``enabled`` key is
authoritative — a legacy ``gateway.json`` block is advisory for relay exactly as it
is for every other platform, and an absent key keeps URL-only activation.
"""
from gateway.config import Platform, PlatformConfig
- from gateway.config_loader import bridge_platform_shared_keys, merge_platform_sections
- from hermes_cli.config import read_raw_config
- from hermes_cli.managed_scope import apply_managed_overlay
+ from gateway.config_loader import bridge_platform_shared_keys, merge_platform_sections, read_yaml_layers
+ from hermes_constants import get_hermes_home
- cfg = apply_managed_overlay(read_raw_config())
+ try:
+ cfg = read_yaml_layers(get_hermes_home())
+ except Exception: # noqa: BLE001 - same fallback as load_gateway_config: no YAML layer at all
+ return False
+ if not isinstance(cfg, dict):
+ return False
gateway = cfg.get("gateway") if isinstance(cfg.get("gateway"), dict) else {}
platforms = merge_platform_sections(cfg, gateway, {})
bridge_platform_shared_keys(cfg, gateway.get("platforms"), {}, platforms, [Platform.RELAY])
diff --git a/tests/gateway/relay/test_explicit_disable.py b/tests/gateway/relay/test_explicit_disable.py
index 609f86cfcc0..fb3114b264a 100644
--- a/tests/gateway/relay/test_explicit_disable.py
+++ b/tests/gateway/relay/test_explicit_disable.py
@@ -128,3 +128,16 @@ def test_legacy_json_disable_is_advisory_like_other_platforms(profile, monkeypat
assert relay.relay_explicitly_disabled() is False
assert config.platforms[Platform.RELAY].enabled is True
assert config.platforms[Platform.TELEGRAM].enabled is True
+
+
+def test_malformed_user_yaml_drops_the_yaml_layer_for_both_readers(profile, monkeypatch):
+ """The loader falls back to env + gateway.json WITHOUT the managed layer on a malformed user
+ file; the predicate must fall back the same way or startup suppresses native adapters for a
+ relay it then refuses to register."""
+ (profile / "config.yaml").write_text("platforms: [\n")
+ write_disable(profile, "managed", monkeypatch)
+ config = load_gateway_config()
+
+ assert relay.relay_explicitly_disabled() is False
+ assert config.platforms[Platform.RELAY].enabled is True
+ assert relay.relay_url() == URL
diff --git a/website/docs/user-guide/messaging/relay.md b/website/docs/user-guide/messaging/relay.md
index e2b548a2abb..4ef23c6f609 100644
--- a/website/docs/user-guide/messaging/relay.md
+++ b/website/docs/user-guide/messaging/relay.md
@@ -115,8 +115,8 @@ platforms:
a connector URL. A `gateway.json` `enabled: false` is advisory, as for every
other platform; put the opt-out in `config.yaml` (user or managed).
-The verdict is read once at startup from the same merged platform configuration
-the gateway uses (top-level or `gateway.platforms` block, managed overlay).
+The verdict comes from the same files and merge the gateway loader uses (top-level
+or `gateway.platforms` block, managed overlay) and is applied at activation time.
Restart the gateway after changing it; an open relay socket is not torn down.
`hermes gateway enroll` remains available while runtime relay is disabled.