The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: key the check_fn cache by the same served-profile predicate as the MCP registry scope
teknium15117e3b3a09b
diff --git a/agent/secret_scope.py b/agent/secret_scope.pyindex 58c80a143ce..8ac01a67e68 100644--- a/agent/secret_scope.py+++ b/agent/secret_scope.py@@ -34,6 +34,18 @@ def is_multiplex_active() -> bool:return _MULTIPLEX_ACTIVE+def serves_routed_profile() -> bool:+ """True when the current task runs for a profile other than the process's own: always under+ multiplexing, else when a HERMES_HOME override names another home (dashboard/desktop backend,+ per-profile cron ticker). The MCP registry scope and the check_fn cache key both follow this+ predicate so a served profile's view never aliases the launch profile's (#111151)."""+ if is_multiplex_active():+ return True+ from hermes_constants import get_hermes_home_override, get_process_hermes_home, hermes_home_key+ override = get_hermes_home_override()+ return override is not None and hermes_home_key(override) != hermes_home_key(get_process_hermes_home())++_SECRET_SCOPE: ContextVar[Optional[Mapping[str, str]]] = ContextVar("_SECRET_SCOPE", default=None)diff --git a/tests/tools/test_mcp_multiplex_connection_keys.py b/tests/tools/test_mcp_multiplex_connection_keys.pyindex c535eb5401f..50c9a0c8f26 100644--- a/tests/tools/test_mcp_multiplex_connection_keys.py+++ b/tests/tools/test_mcp_multiplex_connection_keys.py@@ -272,3 +272,31 @@ def test_served_profile_without_multiplex_flag_gets_its_own_connection(two_profiwith patch("hermes_constants.get_hermes_home_override", return_value=None):assert core._mcp_registry_scope() is Noneassert _server_key("x") == "x"+++def test_served_profile_check_fn_verdict_does_not_shadow_launch_profile(two_profiles, monkeypatch):+ """With multiplex off, a served profile's (correct) "not my connection" verdict must not sit in+ the process-wide check_fn cache under the launch profile's key: the cache scope has to follow+ the same served-profile predicate as the registry scope, or the owner loses its live tools."""+ import tools.registry as registry_mod+ from tools import mcp_tool_discovery as disc+ from tools import mcp_tool_registration as reg+ from tools.registry import registry++ monkeypatch.setattr("agent.secret_scope.is_multiplex_active", lambda: False)+ cfg_a = {"url": "https://mcp.example/x", "headers": {"Authorization": "Bearer A"}}+ srv_a = _server("x", cfg_a)+ with patch("hermes_constants.get_hermes_home_override", return_value=None):+ disc._adopt_server("x", srv_a)+ srv_a._registered_tool_names = reg._register_server_tools("x", srv_a, cfg_a)+ entry = registry._tools["mcp__x__t"]+ registry_mod.invalidate_check_fn_cache()+ try:+ two_profiles("b")+ assert registry_mod.check_fn_cache_scope() is not None+ assert registry_mod._check_fn_cached(entry.check_fn) is False+ with patch("hermes_constants.get_hermes_home_override", return_value=None):+ assert registry_mod._check_fn_cached(entry.check_fn) is True+ finally:+ registry.deregister("mcp__x__t")+ registry_mod.invalidate_check_fn_cache()diff --git a/tools/mcp_tool.py b/tools/mcp_tool.pyindex 326b1f4b365..f0dd90813fb 100644--- a/tools/mcp_tool.py+++ b/tools/mcp_tool.py@@ -643,12 +643,9 @@ def _mcp_registry_scope() -> Optional[str]:ticker) is a multiplexer too, even with the flag off — keying its connections by the bare namewould hand one profile's credentialed connection to every other served profile (#111151).Single-profile processes (no override, or an override naming their own home) keep bare names."""- from agent.secret_scope import is_multiplex_active- from hermes_constants import get_hermes_home_override, get_process_hermes_home, hermes_home_key- if not is_multiplex_active():- override = get_hermes_home_override()- if override is None or hermes_home_key(override) == hermes_home_key(get_process_hermes_home()):- return None+ from agent.secret_scope import serves_routed_profile+ if not serves_routed_profile():+ return Nonefrom tools.registry import registryreturn registry.current_scope_key()diff --git a/tools/registry.py b/tools/registry.pyindex 26257fccc25..60d8026f07a 100644--- a/tools/registry.py+++ b/tools/registry.py@@ -270,9 +270,9 @@ def check_fn_cache_scope() -> Optional[str]:except Exception:passtry:- from agent.secret_scope import is_multiplex_active+ from agent.secret_scope import serves_routed_profilefrom hermes_constants import get_hermes_home_override- if not is_multiplex_active():+ if not serves_routed_profile():return Noneoverride = get_hermes_home_override()return str(Path(override).expanduser().resolve()) if override else CHECK_FN_CACHE_BYPASS