Skip to content

The agent that grows with you

fix: RoomLink catalog names the served profile and reads its policy from that profile

teknium13917c7dd6af4
diff --git a/gateway/hosted_room_execution_policy.py b/gateway/hosted_room_execution_policy.py
index c91cb7b54f2..f6a745d2f49 100644
--- a/gateway/hosted_room_execution_policy.py
+++ b/gateway/hosted_room_execution_policy.py
@@ -68,11 +68,30 @@ class RoomExecutionPolicy:
return {**asdict(self), "enabled_toolsets": list(self.enabled_toolsets)}
+def _served_profile_scope(target_profile: str):
+ """Runtime scope of the SERVED profile: a no-op when it is the active home, else the profile's
+ own home + secret scope (fail closed on an unknown profile). The advertised policy is signed
+ for ``target_profile``, so its config and credentials must be read there, never from the
+ launch profile's env or whatever home happens to be active (#116900)."""
+ from contextlib import nullcontext
+ from hermes_cli.profiles import get_profile_dir, normalize_profile_name, profile_exists, profile_matches_home
+ # "default" is the launch home (a `-p x` multiplexer hosts it too), never a switch to ~/.hermes.
+ if normalize_profile_name(target_profile) == "default" or profile_matches_home(target_profile):
+ return nullcontext()
+ if not profile_exists(target_profile):
+ raise RoomExecutionPolicyError(f"target_profile {target_profile!r} is not a live profile")
+ from gateway.run import _profile_runtime_scope
+ return _profile_runtime_scope(get_profile_dir(target_profile))
+
+
def execution_policy_mapping(*, target_profile: str, config: Mapping[str, Any] | None = None) -> dict[str, Any]:
- """Resolve the effective API-server policy from the target's own config."""
+ """Resolve the effective API-server policy from the served ``target_profile``'s own config."""
+ target_profile = _identifier(target_profile, field="target_profile")
if config is None:
from gateway.run import _load_gateway_config
- config = _load_gateway_config()
+ with _served_profile_scope(target_profile):
+ config = _load_gateway_config()
+ return execution_policy_mapping(target_profile=target_profile, config=config)
if not isinstance(config, Mapping):
raise RoomExecutionPolicyError("gateway config is invalid")
from hermes_cli.config import resolve_turn_limit
diff --git a/gateway/hosted_room_peer.py b/gateway/hosted_room_peer.py
index 39195a8d7b4..03da792c6c2 100644
--- a/gateway/hosted_room_peer.py
+++ b/gateway/hosted_room_peer.py
@@ -244,14 +244,19 @@ class GatewayRoomCatalog:
def catalog_mapping(
*, installation_id: str, protocol_versions: Iterable[int] = (PROTOCOL_VERSION,),
link_modes: Iterable[LinkMode] = ("direct", "pull"), persistent_process: bool, text: bool = True,
- attachments: bool = False, endpoint: Mapping[str, Any] | None = None, target_profile: str | None = None,
+ attachments: bool = False, endpoint: Mapping[str, Any] | None = None, target_profile: str,
execution_policy: Mapping[str, Any] | None = None) -> dict[str, Any]:
- """Build a canonical catalog mapping with its digest."""
+ """Build a canonical catalog mapping with its digest for the SERVED ``target_profile``.
+
+ The profile is the session's, never the process's: a multiplexed gateway advertises one
+ catalog per served profile, so there is no env (``HERMES_PROFILE``) fallback (#116900)."""
# A Desktop-managed gateway exits with the app: the caller's flag is only an upper bound.
persistent_process = bool(persistent_process and os.getenv("HERMES_DESKTOP") != "1")
- profile = str(target_profile or "").strip() or (os.getenv("HERMES_PROFILE") or "default").strip() or "default"
+ profile = _identifier(target_profile, field="target_profile")
checked_policy = RoomExecutionPolicy.from_mapping(
execution_policy or execution_policy_mapping(target_profile=profile))
+ if checked_policy.target_profile != profile:
+ raise HostedRoomPeerError("execution_policy target_profile does not match the catalog target_profile")
# A RoomLink run is initiated by another installation. Process-wide YOLO mode bypasses the scoped
# approval ContextVar, so rewriting the advertised policy cannot make it safe: refuse.
if checked_policy.approval_mode == "off":
diff --git a/tests/gateway/test_api_server_room_grants.py b/tests/gateway/test_api_server_room_grants.py
index 0b91945f2e2..2b490323c83 100644
--- a/tests/gateway/test_api_server_room_grants.py
+++ b/tests/gateway/test_api_server_room_grants.py
@@ -127,6 +127,7 @@ def test_superseded_room_authority_cannot_reuse_its_grant(tmp_path, monkeypatch)
"member_id": "member-reviewer",
"target_install_id": hosted_rooms.local_authority_gateway_id(),
"target_profile": "reviewer",
+ "execution_policy_digest": "d" * 64,
"issued_at": now,
"ttl_seconds": 3600,
}
diff --git a/tests/gateway/test_hosted_room_execution_policy.py b/tests/gateway/test_hosted_room_execution_policy.py
index 45f446208d5..f764ac81dbb 100644
--- a/tests/gateway/test_hosted_room_execution_policy.py
+++ b/tests/gateway/test_hosted_room_execution_policy.py
@@ -231,3 +231,50 @@ def test_policy_drift_requires_reauthorization_without_retry():
assert len(client.dispatches) == 1
assert refreshed == []
assert reauthorization == [True]
+
+
+def _two_profile_homes(tmp_path, monkeypatch) -> None:
+ """alpha is the launch/active home (``HERMES_PROFILE=alpha``); beta is a served sibling."""
+ root = tmp_path / ".hermes"
+ for name, turns in (("alpha", 12), ("beta", 7)):
+ home = root / "profiles" / name
+ home.mkdir(parents=True)
+ (home / "config.yaml").write_text(
+ f"agent:\n max_turns: {turns}\napprovals:\n mode: manual\n"
+ "platform_toolsets:\n api_server: [hermes-api-server, web]\n")
+ (home / ".env").write_text("")
+ from hermes_cli import profiles
+ import gateway.run as gateway_run
+ alpha = root / "profiles" / "alpha"
+ monkeypatch.setattr(profiles, "_get_default_hermes_home", lambda: root)
+ monkeypatch.setattr(gateway_run, "_hermes_home", alpha)
+ monkeypatch.setenv("HERMES_HOME", str(alpha))
+ monkeypatch.setenv("HERMES_PROFILE", "alpha")
+ monkeypatch.delenv("HERMES_YOLO_MODE", raising=False)
+
+
+def test_catalog_policy_comes_from_the_served_profile_not_the_launch_env(tmp_path, monkeypatch):
+ _two_profile_homes(tmp_path, monkeypatch)
+
+ def turns(profile: str) -> int:
+ catalog = catalog_mapping(installation_id="install-peer", persistent_process=True, target_profile=profile)
+ assert catalog["execution_policy"]["target_profile"] == profile
+ return catalog["execution_policy"]["max_iterations"]
+
+ assert turns("alpha") == 12 # control: the active home
+ assert turns("beta") == 7 # precedence: beta's config, not alpha's (env/active)
+ assert turns("alpha") == 12 # A->B->A: no bleed back
+ with pytest.raises(ValueError, match="'ghost' is not a live profile"):
+ execution_policy_mapping(target_profile="ghost")
+
+
+def test_catalog_requires_the_served_profile_and_never_reads_hermes_profile(monkeypatch):
+ monkeypatch.setenv("HERMES_PROFILE", "reviewer")
+ with pytest.raises(TypeError, match="target_profile"):
+ catalog_mapping(installation_id="install-peer", persistent_process=True) # type: ignore[call-arg]
+ with pytest.raises(ValueError, match="target_profile"):
+ catalog_mapping(installation_id="install-peer", persistent_process=True, target_profile="")
+ with pytest.raises(ValueError, match="target_profile does not match"):
+ catalog_mapping(
+ installation_id="install-peer", persistent_process=True, target_profile="other",
+ execution_policy=_policy())
diff --git a/tests/gateway/test_hosted_room_links.py b/tests/gateway/test_hosted_room_links.py
index 7f834641fef..23f418e7932 100644
--- a/tests/gateway/test_hosted_room_links.py
+++ b/tests/gateway/test_hosted_room_links.py
@@ -16,6 +16,7 @@ from gateway.hosted_room_peer import GatewayRoomCatalog, catalog_mapping
def _catalog(installation="install-peer"):
return GatewayRoomCatalog.from_mapping(
catalog_mapping(
+ target_profile="default",
installation_id=installation,
persistent_process=True,
)
diff --git a/tests/gateway/test_hosted_room_peer.py b/tests/gateway/test_hosted_room_peer.py
index 8b4f6c160d0..9400d9b6109 100644
--- a/tests/gateway/test_hosted_room_peer.py
+++ b/tests/gateway/test_hosted_room_peer.py
@@ -28,7 +28,7 @@ from hermes_constants import reset_hermes_home_override, set_hermes_home_overrid
SECRET = b"s" * 32
-EXECUTION_POLICY = execution_policy_mapping(target_profile="reviewer")
+EXECUTION_POLICY = execution_policy_mapping(target_profile="reviewer", config={"approvals": {"mode": "manual"}})
def test_gateway_room_grant_secret_is_private_persistent_and_not_an_api_key(
@@ -197,6 +197,7 @@ def _dispatch(**overrides):
def test_catalog_digest_is_canonical_and_tamper_evident():
value = catalog_mapping(
+ target_profile="default",
installation_id="install-peer",
protocol_versions=(2,),
link_modes=("direct", "pull"),
@@ -294,7 +295,7 @@ def test_local_catalog_is_honest_for_app_managed_process(monkeypatch):
from gateway.hosted_room_peer import local_catalog_mapping
monkeypatch.setenv("HERMES_DESKTOP", "1")
- catalog = local_catalog_mapping(installation_id="install-desktop")
+ catalog = local_catalog_mapping(target_profile="default", installation_id="install-desktop")
assert catalog["persistent_process"] is False
assert catalog["link_modes"] == ["direct"]
@@ -317,7 +318,7 @@ def test_self_advertised_endpoint_is_explicit_and_validated(
monkeypatch.delenv("HERMES_ROOM_LINK_URL", raising=False)
else:
monkeypatch.setenv("HERMES_ROOM_LINK_URL", configured)
- endpoint = local_catalog_mapping(installation_id="install-peer")["endpoint"]
+ endpoint = local_catalog_mapping(target_profile="default", installation_id="install-peer")["endpoint"]
assert endpoint["available"] is available
if reason is not None:
assert endpoint == {"available": False, "reason": reason}
diff --git a/tests/tui_gateway/test_groups_methods.py b/tests/tui_gateway/test_groups_methods.py
index f45a17be50e..f85fcc5ed86 100644
--- a/tests/tui_gateway/test_groups_methods.py
+++ b/tests/tui_gateway/test_groups_methods.py
@@ -89,6 +89,9 @@ def test_capabilities_are_honest_about_the_driver_boundary(home):
def test_capabilities_and_invitation_advertise_scoped_roomlink(home, monkeypatch):
monkeypatch.setenv("API_SERVER_KEY", "gateway-api-key-1234567890")
monkeypatch.setenv("HERMES_PROFILE", "reviewer")
+ # The advertised policy is the SERVED profile's own config, so the profile must exist (#116900).
+ (home / "profiles" / "reviewer").mkdir(parents=True)
+ (home / "profiles" / "reviewer" / "config.yaml").write_text("approvals:\n mode: manual\n")
result = _result(srv._methods["groups.capabilities"](1, {}))
assert result["room_link"]["enabled"] is True
assert result["room_link"]["profile"] == "reviewer"
@@ -326,6 +329,7 @@ def test_register_peer_route_probes_scope_and_persists_via_service(home, monkeyp
from gateway.hosted_rooms import local_authority_gateway_id
catalog = catalog_mapping(
+ target_profile="default",
installation_id="install-peer",
persistent_process=True,
)
@@ -414,6 +418,7 @@ def test_register_requires_roomlink_protocol_v2(home, monkeypatch):
"target_profile": "reviewer",
"grant": "signed.room.grant",
"catalog": catalog_mapping(
+ target_profile="default",
installation_id="install-peer",
protocol_versions=(1,),
persistent_process=True,
diff --git a/tests/tui_gateway/test_hosted_room_peer_http.py b/tests/tui_gateway/test_hosted_room_peer_http.py
index c43e85e287c..a344c0314bf 100644
--- a/tests/tui_gateway/test_hosted_room_peer_http.py
+++ b/tests/tui_gateway/test_hosted_room_peer_http.py
@@ -891,12 +891,14 @@ def test_grant_refresh_rejects_catalog_or_policy_drift(
)
base = GatewayRoomCatalog.from_mapping(
catalog_mapping(
+ target_profile="reviewer",
installation_id="install-peer",
persistent_process=True,
execution_policy=base_policy,
)
)
refreshed = catalog_mapping(
+ target_profile="reviewer",
installation_id="install-peer",
persistent_process=True,
attachments=capability_changed,
@@ -930,6 +932,7 @@ def test_grant_refresh_preserves_unchanged_catalog_and_policy():
from gateway.hosted_room_peer import GatewayRoomCatalog, catalog_mapping
raw_catalog = catalog_mapping(
+ target_profile="default",
installation_id="install-peer",
persistent_process=True,
)
@@ -959,6 +962,7 @@ def test_grant_refresh_retries_old_grant_after_response_loss():
from gateway.hosted_room_peer import GatewayRoomCatalog, catalog_mapping
raw_catalog = catalog_mapping(
+ target_profile="default",
installation_id="install-peer",
persistent_process=True,
)
diff --git a/tests/tui_gateway/test_hosted_room_service.py b/tests/tui_gateway/test_hosted_room_service.py
index 95b4fa11af5..38a5390703a 100644
--- a/tests/tui_gateway/test_hosted_room_service.py
+++ b/tests/tui_gateway/test_hosted_room_service.py
@@ -1132,6 +1132,7 @@ def test_registered_peer_route_rehydrates_after_service_restart(tmp_path: Path):
db = tmp_path / "state.db"
catalog = GatewayRoomCatalog.from_mapping(
catalog_mapping(
+ target_profile="default",
installation_id="install-peer",
persistent_process=True,
)
@@ -1167,7 +1168,7 @@ def test_registered_peer_route_rehydrates_after_service_restart(tmp_path: Path):
def test_one_corrupt_stored_route_does_not_hide_healthy_peers(tmp_path: Path):
db = tmp_path / "state.db"
catalog = GatewayRoomCatalog.from_mapping(
- catalog_mapping(installation_id="install-peer", persistent_process=True)
+ catalog_mapping(target_profile="default", installation_id="install-peer", persistent_process=True)
)
service = HostedRoomService(_server(), db_path=db)
for room_id, member_id in (("room-good", "member-good"), ("room-bad", "member-bad")):
@@ -1209,6 +1210,7 @@ def test_unpublished_roomlink_v1_route_is_quarantined_for_reinvitation(
db = tmp_path / "state.db"
legacy_catalog = GatewayRoomCatalog.from_mapping(
catalog_mapping(
+ target_profile="default",
installation_id="install-peer",
protocol_versions=(1,),
persistent_process=True,
@@ -1284,7 +1286,7 @@ def test_registration_disk_failure_does_not_publish_live_route(
db = tmp_path / "state.db"
service = HostedRoomService(_server(), db_path=db)
catalog = GatewayRoomCatalog.from_mapping(
- catalog_mapping(installation_id="install-peer", persistent_process=True)
+ catalog_mapping(target_profile="default", installation_id="install-peer", persistent_process=True)
)
route = PeerMemberRoute(
home_install_id=hosted_rooms.local_authority_gateway_id(),
@@ -1320,7 +1322,7 @@ def test_room_route_revocation_is_remote_first_and_removes_local_state(
db = tmp_path / "state.db"
catalog = GatewayRoomCatalog.from_mapping(
- catalog_mapping(installation_id="install-peer", persistent_process=True)
+ catalog_mapping(target_profile="default", installation_id="install-peer", persistent_process=True)
)
route = PeerMemberRoute(
home_install_id=hosted_rooms.local_authority_gateway_id(),
@@ -1354,7 +1356,7 @@ def test_failed_remote_revocation_preserves_route_for_retry(tmp_path: Path):
db = tmp_path / "state.db"
catalog = GatewayRoomCatalog.from_mapping(
- catalog_mapping(installation_id="install-peer", persistent_process=True)
+ catalog_mapping(target_profile="default", installation_id="install-peer", persistent_process=True)
)
route = PeerMemberRoute(
home_install_id=hosted_rooms.local_authority_gateway_id(),
@@ -1387,7 +1389,7 @@ def test_expired_remote_grant_no_longer_blocks_room_cleanup(tmp_path: Path):
db = tmp_path / "state.db"
catalog = GatewayRoomCatalog.from_mapping(
- catalog_mapping(installation_id="install-peer", persistent_process=True)
+ catalog_mapping(target_profile="default", installation_id="install-peer", persistent_process=True)
)
route = PeerMemberRoute(
home_install_id=hosted_rooms.local_authority_gateway_id(),
@@ -1420,7 +1422,7 @@ def test_expired_grant_surfaces_needs_reauthorization_without_secret(
):
db = tmp_path / "state.db"
catalog = GatewayRoomCatalog.from_mapping(
- catalog_mapping(installation_id="install-peer", persistent_process=True)
+ catalog_mapping(target_profile="default", installation_id="install-peer", persistent_process=True)
)
route = PeerMemberRoute(
home_install_id=hosted_rooms.local_authority_gateway_id(),
@@ -1518,7 +1520,7 @@ def test_not_admitted_dispatch_persists_unavailable_route_until_success(
):
db = tmp_path / "state.db"
catalog = GatewayRoomCatalog.from_mapping(
- catalog_mapping(installation_id="install-peer", persistent_process=True)
+ catalog_mapping(target_profile="default", installation_id="install-peer", persistent_process=True)
)
route = PeerMemberRoute(
home_install_id=hosted_rooms.local_authority_gateway_id(),
@@ -1610,6 +1612,9 @@ def test_not_admitted_dispatch_persists_unavailable_route_until_success(
def test_dispatch_refresh_persists_before_remote_admission(tmp_path: Path):
now = time.time()
secret = b"s" * 32
+ catalog = GatewayRoomCatalog.from_mapping(
+ catalog_mapping(target_profile="default", installation_id="install-peer", persistent_process=True)
+ )
old_grant = issue_room_grant(
secret,
grant_id="grant-old",
@@ -1620,6 +1625,7 @@ def test_dispatch_refresh_persists_before_remote_admission(tmp_path: Path):
member_id="member-peer",
target_install_id="install-peer",
target_profile="reviewer",
+ execution_policy_digest=catalog.execution_policy.policy_digest,
issued_at=now - 3700,
ttl_seconds=3600,
status_expires_at=now + 10_000,
@@ -1634,13 +1640,11 @@ def test_dispatch_refresh_persists_before_remote_admission(tmp_path: Path):
member_id="member-peer",
target_install_id="install-peer",
target_profile="reviewer",
+ execution_policy_digest=catalog.execution_policy.policy_digest,
issued_at=now,
ttl_seconds=3600,
status_expires_at=now + 10_000,
)
- catalog = GatewayRoomCatalog.from_mapping(
- catalog_mapping(installation_id="install-peer", persistent_process=True)
- )
route = PeerMemberRoute(
home_install_id=hosted_rooms.local_authority_gateway_id(),
member_id="member-peer",
@@ -1745,12 +1749,14 @@ def test_dispatch_refresh_marks_route_for_reauthorization_on_drift(
)
base_catalog = GatewayRoomCatalog.from_mapping(
catalog_mapping(
+ target_profile="reviewer",
installation_id="install-peer",
persistent_process=True,
execution_policy=base_policy,
)
)
refreshed_catalog = catalog_mapping(
+ target_profile="reviewer",
installation_id="install-peer",
persistent_process=True,
attachments=capability_changed,
@@ -1818,7 +1824,7 @@ def test_dispatch_refresh_marks_route_for_reauthorization_on_drift(
def test_peer_approval_is_scoped_visible_and_resolvable(tmp_path: Path):
db = tmp_path / "state.db"
catalog = GatewayRoomCatalog.from_mapping(
- catalog_mapping(installation_id="install-peer", persistent_process=True)
+ catalog_mapping(target_profile="default", installation_id="install-peer", persistent_process=True)
)
route = PeerMemberRoute(
home_install_id=hosted_rooms.local_authority_gateway_id(),
@@ -2012,7 +2018,7 @@ def test_stale_local_approval_cannot_resolve_replacement_request(tmp_path: Path)
def test_peer_recovery_replays_the_same_execution_generation(tmp_path: Path):
db = tmp_path / "state.db"
catalog = GatewayRoomCatalog.from_mapping(
- catalog_mapping(installation_id="install-peer", persistent_process=True)
+ catalog_mapping(target_profile="default", installation_id="install-peer", persistent_process=True)
)
route = PeerMemberRoute(
home_install_id=hosted_rooms.local_authority_gateway_id(),
diff --git a/website/docs/user-guide/multi-profile-gateways.md b/website/docs/user-guide/multi-profile-gateways.md
index 56672bc8f11..654f869d6a5 100644
--- a/website/docs/user-guide/multi-profile-gateways.md
+++ b/website/docs/user-guide/multi-profile-gateways.md
@@ -463,6 +463,7 @@ profile and never shares with the default or any sibling:
| Sandbox credential-file mounts (`terminal.credential_files`), `security.redact_secrets`, `browser.*` engine/headed flags, `lsp.*`, auxiliary-provider health marks, `logs/mcp-stderr.log` | The profile's own `config.yaml` / `.env` | Documented default — never the launch profile's cached value |
| Cloud-SDK credential clients (Bedrock boto3 clients + model discovery, Azure Entra credential), credential-fetched catalogs (DeepInfra, Copilot context limits, Nous reasoning caps, Ramp Router efforts, xAI / OpenRouter image models, custom-endpoint `/models`), Camofox VNC address, computer-use aux-vision routing, skill-sync push, remote-backend probe text, learned image token costs, `display.skin`, guest-mint back-off, banner skills, Yuanbao "active" adapter, Langfuse client | The profile's own `.env` / `config.yaml` / `<home>/cache` | Documented default — never the launch profile's cached value or its credentials |
| Session-search knobs (`sessions.cjk_fts`, `sessions.search_slow_ms`) | The profile's `config.yaml` | Documented default — never the default profile's bridged value |
+| RoomLink capability catalog and the signed execution policy it advertises to a remote Bot (`approvals.mode`, `agent.max_turns`, `platform_toolsets.api_server`) | The served profile named by the request (`/p/<profile>/v1/room-members/...`, the RPC `profile` param); `target_profile` is **required** on every catalog — there is no `HERMES_PROFILE` fallback | Invitation/capabilities fail with the offending `target_profile` named; a profile that does not exist is refused, never resolved from the launch profile's config |
| Platform proxies (`TELEGRAM_PROXY`, `DISCORD_PROXY`, `HTTPS_PROXY`, …) | The profile's own `.env` | Direct connection — never the default profile's proxy |
| MCP discovery in the Desktop/dashboard backend | Once per served profile home | A profile selected after another has already built an agent still discovers its own `mcp_servers` |
| Settings changed from a Desktop / TUI session (`/busy`, `/verbose`, `/approval`, `/cwd`, theme and display toggles) | The `config.yaml` of the profile that owns the session, even when the RPC carries only the session id | The session's own profile is written; the launch profile's `config.yaml` and its `TERMINAL_CWD` are never touched |