The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: defer editor MCP schema changes until a new session
Tekniumbe748101302d
diff --git a/tests/acp/test_session_mcp_frozen.py b/tests/acp/test_session_mcp_frozen.pynew file mode 100644index 00000000000..828dc60754a--- /dev/null+++ b/tests/acp/test_session_mcp_frozen.py@@ -0,0 +1,56 @@+"""Selected editor schemas never refresh inside an execution or escape discovery."""+import json+import sys+import time++import pytest++from gateway.session_policy import policy_scope+from hermes_state_runtime import RuntimeStoreError+from tests.acp.test_session_mcp_policy import owner, policy, server_spec # noqa: F401+++def test_editor_manifest_stays_frozen_across_live_refresh(server_spec, tmp_path):+ from tools.registry import registry+ from tools.mcp_tool import _servers+ from tools.mcp_tool_loop import _run_on_mcp_loop+ authority = owner()+ p = policy(authority, 'freeze', server_spec, tmp_path)+ with policy_scope(p, authority=authority):+ names = [n for n in registry.get_all_tool_names() if n.startswith('mcp__')]+ schemas = {n: registry.get_schema(n) for n in names}+ server = next(s for n, s in _servers.items() if n.startswith('editor_'))+ # The real refresh re-reads the stdio peer. A changed in-memory discovery+ # response is not allowed to republish schemas even when explicitly refreshed.+ server._tools[0].description = 'changed after first discovery'+ from tools.mcp_tool_registration import _register_server_tools+ with pytest.raises(RuntimeStoreError, match='acp_mcp_schema_changed'):+ _register_server_tools(server.name, server, server._config)+ assert schemas == {n: registry.get_schema(n) for n in names}+ _run_on_mcp_loop(server._refresh_tools, timeout=10)+ assert schemas == {n: registry.get_schema(n) for n in names}+ # Changing the actual server program preserves the transport fingerprint,+ # but must not replace the session's selected schema on the next execution.+ script = tmp_path / 'owned_mcp.py'+ script.write_text(script.read_text().replace('owned echo', 'changed live schema'))+ with pytest.raises(RuntimeStoreError, match='acp_mcp_schema_changed'):+ with policy_scope(p, authority=authority):+ pass+++def test_silent_editor_discovery_is_bounded_and_reaps_only_itself(server_spec, tmp_path):+ from tools.registry import registry+ authority = owner()+ healthy = policy(authority, 'healthy', server_spec, tmp_path)+ silent = {'name': 'same-editor-name', 'command': sys.executable,+ 'args': ['-c', 'import time; time.sleep(120)'], 'env': []}+ with policy_scope(healthy, authority=authority):+ started = time.monotonic()+ with pytest.raises(RuntimeStoreError, match='acp_mcp_discovery_failed'):+ policy(authority, 'silent', silent, tmp_path)+ assert time.monotonic() - started < 25+ names = [n for n in registry.get_all_tool_names() if n.startswith('mcp__')]+ assert len(names) == 1+ assert 'PRIVATE_A' in registry.dispatch(names[0], {})+ from tools.mcp_tool import _servers+ assert not any(n.startswith('editor_') for n in _servers)diff --git a/tools/mcp_tool_health.py b/tools/mcp_tool_health.pyindex 1b328cfedaf..afb92d3bb65 100644--- a/tools/mcp_tool_health.py+++ b/tools/mcp_tool_health.py@@ -134,6 +134,8 @@ class MCPServerHealthMixin:async def _refresh_tools(self):"""Re-fetch tools on ``tools/list_changed`` and update the registry. The lock serializes rapid-firenotifications; after the list_tools ``await`` all mutations are synchronous — atomic on the event loop."""+ if getattr(self, '_editor_frozen_manifest', None) is not None:+ return # Editor tool policy changes apply only to a new canonical session.if not self._advertises_tools():return # tools/list would raise MCPError(-32601)async with self._refresh_lock:diff --git a/tools/mcp_tool_registration.py b/tools/mcp_tool_registration.pyindex 8850234c689..e43e8df0015 100644--- a/tools/mcp_tool_registration.py+++ b/tools/mcp_tool_registration.py@@ -294,6 +294,14 @@ def _register_server_tools(name: str, server: "MCPServerTask", config: dict) ->_record_tool_trust_metadata(name, config, server._tools)candidates = _tool_candidates(name, server._tools, should_register, server.tool_timeout)candidates += _utility_candidates(name, _select_utility_schemas(name, server, config), server.tool_timeout)+ if (_core._server_registry_scope(name) or '').startswith('editor-session:'):+ import json+ from hermes_state_runtime import RuntimeStoreError+ manifest = json.dumps({c.registry_name: c.schema for c in candidates}, sort_keys=True)+ frozen = getattr(server, '_editor_frozen_manifest', manifest)+ if manifest != frozen:+ raise RuntimeStoreError('acp_mcp_schema_changed')+ server._editor_frozen_manifest = frozenregistered = _register_candidates(name, _resolve_name_collisions(name, candidates),check_fn=_make_check_fn(name), scope=lambda: _core._server_registry_scope(name), lazy=False)