Skip to content

The agent that grows with you

fix(tools): publish a same-name schema on explicit reload

Adrian Bolinger021e7abb9352
diff --git a/tests/tools/test_compaction_tool_refresh.py b/tests/tools/test_compaction_tool_refresh.py
index a7cb74ee5f3..c8f94386472 100644
--- a/tests/tools/test_compaction_tool_refresh.py
+++ b/tests/tools/test_compaction_tool_refresh.py
@@ -5,7 +5,7 @@ the only boundary where the prompt cache is already broken, so it is the
one sanctioned point for a tool-snapshot rebuild. These tests pin:
- refresh_agent_mcp_tools(content_aware=True) swaps on CONTENT change under
a stable name set (the dynamic-schema case its name-only diff missed)
-- content_aware=False keeps the old no-churn behavior (MCP-reload callers)
+- preserve_prefix=True keeps the schema already sent (between-turns refresh)
"""
import os
import sys
@@ -51,10 +51,10 @@ class TestContentAwareRefresh(unittest.TestCase):
self.assertIn("new capabilities",
agent.tools[0]["function"]["description"])
- def test_content_change_ignored_when_name_only(self):
- """MCP-reload callers keep the historical no-churn contract."""
+ def test_content_change_ignored_when_prefix_preserved(self):
+ """Between-turns refresh keeps the schema already sent."""
agent = self._agent_with("old capabilities text")
- self._refresh(agent, "new capabilities text", content_aware=False)
+ self._refresh(agent, "new capabilities text", preserve_prefix=True)
self.assertIn("old capabilities",
agent.tools[0]["function"]["description"])
diff --git a/tests/tools/test_refresh_agent_mcp_tools.py b/tests/tools/test_refresh_agent_mcp_tools.py
index e96d7f4775c..96767278b0e 100644
--- a/tests/tools/test_refresh_agent_mcp_tools.py
+++ b/tests/tools/test_refresh_agent_mcp_tools.py
@@ -279,6 +279,26 @@ def test_preserve_prefix_appends_late_arrivals_at_the_tail(monkeypatch):
]
+def test_explicit_reload_replaces_a_same_name_schema(monkeypatch):
+ """``/reload-mcp`` takes the fresh schema when the tool name stays the same.
+
+ Between-turns refresh freezes the bytes already sent. Reload is the other
+ path (``preserve_prefix`` off): the user already accepted a cache break, so
+ a new description on ``read_file`` has to be what the next request sends.
+ """
+ agent = _agent(["read_file"])
+ agent.tools[0]["function"]["description"] = "Read a file. schema v1"
+
+ fresh = _tool("read_file")
+ fresh["function"]["description"] = "Read a file. schema v2"
+ _serve(monkeypatch, [fresh])
+ _registered(monkeypatch, ["read_file"])
+
+ _mcp_agent.refresh_agent_mcp_tools(agent)
+
+ assert agent.tools[0]["function"]["description"] == "Read a file. schema v2"
+
+
def test_preserve_prefix_keeps_the_bridge_tools_byte_identical(monkeypatch):
"""``tool_search``'s description is derived from the session at build time: the
deferred-tool count, the embedded listing, and whether ``manage_connections`` was
diff --git a/tools/mcp_tool_agent.py b/tools/mcp_tool_agent.py
index d6954fce05e..26ccb24d36a 100644
--- a/tools/mcp_tool_agent.py
+++ b/tools/mcp_tool_agent.py
@@ -81,8 +81,8 @@ def _publish_tool_snapshot(
new_defs, new_names = _drop_session_tools(agent, new_defs, new_names)
# Record the generation even when unchanged so an in-flight older caller can't clobber.
agent._tool_snapshot_generation = max(published_gen, snapshot_generation)
- # Same NAME set: no change for MCP-reload callers. Content-aware callers
- # (compaction boundary) also diff serialized bytes.
+ # Same name set and unchanged bytes: nothing to publish. content_aware
+ # (explicit reload, compaction) also diffs serialized schema bytes.
if new_names == current and not (content_aware and _tool_defs_content_changed(agent, new_defs)):
return None
agent.tools = new_defs
@@ -111,7 +111,11 @@ def refresh_agent_mcp_tools(
request prefix and any moved byte re-prefills the whole history — existing tools keep their
slot (schemas still refresh), a still-registered tool whose ``check_fn`` merely flapped is
carried forward (``check_fn`` gates exposure, never invocation), a deregistered tool is
- dropped, new tools append at the tail. The caller owns the prompt-cache contract."""
+ dropped, new tools append at the tail. The caller owns the prompt-cache contract.
+
+ With ``preserve_prefix`` off (explicit ``/reload-mcp``, and a rebuild before the
+ first turn) a same-name schema change is published. The caller has already
+ accepted the cache break, or nothing has been cached yet."""
from model_tools import get_tool_definitions
from tools.registry import registry
enabled, disabled = _resolve_refresh_toolsets(agent, enabled_override, disabled_override)
@@ -131,6 +135,10 @@ def refresh_agent_mcp_tools(
prefix_registered = {entry.name for entry in registry.get_all_entries()}
except Exception:
pass # fail open to the plain rebuild
+ else:
+ # Explicit reload and pre-first-turn rebuild. A same-name description
+ # change has to publish; between-turns refresh keeps preserve_prefix.
+ content_aware = True
added = _publish_tool_snapshot(
agent, new_defs, new_names, snapshot_generation=snapshot_generation,
staged_engine_names=staged_engine_names, content_aware=content_aware, prefix_registered=prefix_registered)