Skip to content

The agent that grows with you

fix(cron): a routed profile's cron delivery no longer rewrites the launch profile's media policy

kshitijk4pooraeaeba74b7aa
diff --git a/gateway/media_policy.py b/gateway/media_policy.py
index ee7a3c628c8..2994b628d77 100644
--- a/gateway/media_policy.py
+++ b/gateway/media_policy.py
@@ -6,7 +6,8 @@
entrypoint (gateway startup, ``hermes cron run``, ``hermes send``) calls
:func:`apply_media_policy_env` first so standalone paths filter under the gateway's
policy instead of silently dropping attachments in strict/allowlisted deployments.
-An explicitly-set env var WINS over config.yaml, so shell overrides survive.
+An explicitly-set env var WINS over config.yaml, so shell overrides survive. Under a HERMES_HOME
+override (a served profile's turn or cron fire) nothing is bridged: readers load that profile's config.
"""
from __future__ import annotations
@@ -96,8 +97,15 @@ def _allow_dirs_str(allow_dirs: Any) -> str:
def apply_media_policy_env(config: Optional[Dict[str, Any]] = None) -> None:
"""Bridge gateway media-policy settings from config.yaml into the env. Idempotent,
- env-wins, never raises — a bridge failure must not break delivery (validator defaults apply)."""
+ env-wins, never raises — a bridge failure must not break delivery (validator defaults apply).
+
+ No-op under a HERMES_HOME override, the same gate the readers use: there they take the
+ profile's own config (``_routed_gateway_cfg``), and ``os.environ`` is shared — a routed cron
+ fire would hand its allowlist and strictness to the launch profile and its children."""
try:
+ from hermes_constants import get_hermes_home_override
+ if get_hermes_home_override():
+ return
gateway_cfg = _load_gateway_cfg(config)
if not gateway_cfg:
return
diff --git a/tests/gateway/test_multiplex_process_memo_scope.py b/tests/gateway/test_multiplex_process_memo_scope.py
index 356e5af6354..c51b89b9d43 100644
--- a/tests/gateway/test_multiplex_process_memo_scope.py
+++ b/tests/gateway/test_multiplex_process_memo_scope.py
@@ -4,6 +4,7 @@
from __future__ import annotations
import json
+import os
from pathlib import Path
from types import SimpleNamespace
@@ -121,3 +122,29 @@ def test_media_policy_reads_routed_profile_config_not_env(two_homes, monkeypatch
assert _under(b, media_policy.media_delivery_strict) is False
assert _under(b, media_policy.media_delivery_allow_dirs) == "/srv/b"
+
+
+def test_routed_media_policy_bridge_never_writes_the_shared_env(two_homes, monkeypatch):
+ """A routed profile's cron delivery runs the bridge under its override; its policy must not
+ land in os.environ, where the launch profile's own deliveries and children read it."""
+ a, b = two_homes
+ from gateway import media_policy
+ from hermes_cli.config import load_config
+
+ (b / "config.yaml").write_text(yaml.safe_dump(
+ {"gateway": {"strict": False, "media_delivery_allow_dirs": ["/srv/b"]}}), encoding="utf-8")
+ for var in ("HERMES_MEDIA_DELIVERY_STRICT", "HERMES_MEDIA_ALLOW_DIRS", "HERMES_MEDIA_TRUST_RECENT_FILES"):
+ monkeypatch.delenv(var, raising=False)
+
+ _under(b, lambda: media_policy.apply_media_policy_env(load_config()))
+
+ assert not any(os.environ.get(v) for v in (
+ "HERMES_MEDIA_DELIVERY_STRICT", "HERMES_MEDIA_ALLOW_DIRS", "HERMES_MEDIA_TRUST_RECENT_FILES"))
+ assert _under(b, media_policy.media_delivery_allow_dirs) == "/srv/b"
+
+ # The launch profile's own bridge (no override) still runs once the host multiplexes.
+ (a / "config.yaml").write_text(yaml.safe_dump(
+ {"gateway": {"media_delivery_allow_dirs": ["/srv/a"]}}), encoding="utf-8")
+ monkeypatch.setattr("agent.secret_scope._MULTIPLEX_ACTIVE", True)
+ media_policy.apply_media_policy_env(load_config())
+ assert media_policy.media_delivery_allow_dirs() == "/srv/a"