Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix(api): warn when a deferred tool's definition fails to load (#1731)

evan188199-tech70d65c002901
diff --git a/deeptutor/api/utils/tool_options.py b/deeptutor/api/utils/tool_options.py
index cccac4709..f94c7fe80 100644
--- a/deeptutor/api/utils/tool_options.py
+++ b/deeptutor/api/utils/tool_options.py
@@ -94,7 +94,18 @@ async def build_tool_options(
for tool in registry.deferred_tools():
try:
definition = tool.get_definition()
- except Exception:
+ except Exception as exc:
+ # The definition is the only place a deferred tool's name lives,
+ # so identify the failure by provider and adapter class instead
+ # of dropping it from the options without a trace.
+ kind, provider_id = provider_identity(tool)
+ logger.warning(
+ "tool options skipped %s tool %r (provider %r): get_definition() failed: %s",
+ kind or "unknown",
+ type(tool).__name__,
+ provider_id or "unknown",
+ exc,
+ )
continue
kind, provider_id = provider_identity(tool)
if (kind or "mcp") != "mcp":
diff --git a/tests/api/test_tool_options.py b/tests/api/test_tool_options.py
index a8d954ae9..8317e2b29 100644
--- a/tests/api/test_tool_options.py
+++ b/tests/api/test_tool_options.py
@@ -8,6 +8,7 @@ the legacy spelling that must keep working for clients built before them.
from __future__ import annotations
+import logging
from typing import Any
import pytest
@@ -162,6 +163,24 @@ async def test_unreadable_tool_is_skipped(stub_registry) -> None:
assert isinstance(payload["builtin_tools"], list)
+async def test_unreadable_tool_is_skipped_with_warning(stub_registry, caplog) -> None:
+ """A skipped tool must be named in a warning, not vanish silently."""
+ stub_registry([_BrokenTool("mcp_broken_thing"), _McpTool("mcp_notion_search", "notion")])
+
+ with caplog.at_level(logging.WARNING, logger="deeptutor.api.utils.tool_options"):
+ payload = await tool_options_mod.build_tool_options()
+
+ # The warning names the provider the tool came from and the failure reason.
+ warnings = [r.getMessage() for r in caplog.records if r.levelno == logging.WARNING]
+ assert any(
+ "broken" in message and "server went away mid-listing" in message for message in warnings
+ ), warnings
+ # Good tools keep flowing and the return structure is unchanged.
+ assert [row["name"] for row in payload["mcp_tools"]] == ["mcp_notion_search"]
+ assert set(payload) == {"tools", "builtin_tools", "mcp_tools"}
+
+
@pytest.mark.asyncio
async def test_optional_tool_filter_is_explicit_and_does_not_change_default(stub_registry) -> None:
"""Partner policy must not leak into the shared admin grant catalog."""