Skip to content

The agent that grows with you

fix(tools): run tool discovery before resolving a legacy name-only pin

unsupportedpastels39661bb10b6a
diff --git a/tests/gateway/test_tui_context_breakdown_scope.py b/tests/gateway/test_tui_context_breakdown_scope.py
index 1c49287ef67..1ca9e30dbeb 100644
--- a/tests/gateway/test_tui_context_breakdown_scope.py
+++ b/tests/gateway/test_tui_context_breakdown_scope.py
@@ -1,5 +1,8 @@
"""``session.context_breakdown`` (Desktop context popover) and TUI ``/context`` measure the compression
tip's model history, and the popover's categories survive a session with no resident agent."""
+import subprocess
+import sys
+from pathlib import Path
from types import SimpleNamespace
import pytest
@@ -79,6 +82,16 @@ async def test_agentless_breakdown_measures_a_legacy_name_only_pin(owner):
assert 'tool_definitions' in {c['id'] for c in actual['categories']}, actual
+def test_a_legacy_pin_resolves_before_any_agent_ran_tool_discovery():
+ """The gateway reads an agentless breakdown before its warm-up imports the tools (or with it off);
+ only a fresh interpreter has that cold registry."""
+ code = ("from tools.mcp_tool_agent import pinned_tool_defs; "
+ "print(sorted(d['function']['name'] for d in pinned_tool_defs(['terminal'])))")
+ out = subprocess.run([sys.executable, '-c', code], cwd=Path(__file__).resolve().parents[2],
+ capture_output=True, text=True, check=True, timeout=120).stdout
+ assert out.strip().splitlines()[-1] == "['terminal']", out
+
+
@pytest.mark.asyncio
async def test_agentless_breakdown_survives_a_swept_tools_pin(owner):
"""A pin hash whose ``system_prompts`` row was swept resolves to the bare hash: no tools, no error."""
diff --git a/tools/mcp_tool_agent.py b/tools/mcp_tool_agent.py
index f62cc381087..f8e3142e670 100644
--- a/tools/mcp_tool_agent.py
+++ b/tools/mcp_tool_agent.py
@@ -251,6 +251,9 @@ def _pinned_tool_defs(saved, fresh, keep_bytes=False) -> tuple:
def pinned_tool_defs(saved) -> list:
"""``saved``'s tool definitions as a fresh agent restores them, for an estimate with no agent built:
pinned definitions keep their bytes, a legacy name list takes each tool's current registry schema."""
+ # With no agent built yet (gateway warm-up off, failed or still running), nothing has run tool
+ # discovery, so the registry would resolve no legacy name.
+ import model_tools
return _pinned_tool_defs(saved, {}, keep_bytes=True)[2]