Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(tools): keep the per-module discovery failure at WARNING

Haozhe Wu674f1aba97ac
diff --git a/agent/src/tools/__init__.py b/agent/src/tools/__init__.py
index 01a4e4a5c..710aa63ac 100644
--- a/agent/src/tools/__init__.py
+++ b/agent/src/tools/__init__.py
@@ -53,11 +53,11 @@ def _discover_subclasses() -> list[type[BaseTool]]:
except Exception as exc:
reason = f"{type(exc).__name__}: {exc}"
discovery_failures[module_name] = reason
- logger.debug(
- "Skipped src.tools.%s during discovery: %s",
- module_name,
- reason,
- exc_info=True,
+ # Stays at WARNING: an operator who cannot see *which* module
+ # dropped out is back to the silent partial registry of #1124.
+ # The aggregate line below counts them; this one names them.
+ logger.warning(
+ "Skipped src.tools.%s during discovery: %s", module_name, reason
)
classes: list[type[BaseTool]] = []
diff --git a/agent/tests/test_tool_registry_diagnostics.py b/agent/tests/test_tool_registry_diagnostics.py
index 046b172cf..423dbf46d 100644
--- a/agent/tests/test_tool_registry_diagnostics.py
+++ b/agent/tests/test_tool_registry_diagnostics.py
@@ -40,3 +40,42 @@ def test_build_registry_surfaces_aggregate_failure_warning(monkeypatch, caplog)
"Registered 0 local tools; 1 tool source(s) failed during registry construction"
in caplog.messages
)
+
+
+def test_discovery_names_each_failed_module_at_warning(monkeypatch, caplog) -> None:
+ """Discovery must name the module that dropped out, not just count it (#1124).
+
+ The aggregate line in ``build_registry`` reports *how many* sources failed;
+ only this per-module record says *which*. Demoting it to DEBUG puts an
+ operator back in front of the silent partial registry the issue is about.
+ """
+ import src.tools as tools_module
+
+ real_import = tools_module.importlib.import_module
+ target = "sentiment_tool"
+
+ class _ShimImportlib:
+ @staticmethod
+ def import_module(name: str):
+ if name == f"src.tools.{target}":
+ raise ImportError("no module named 'nowhere'")
+ return real_import(name)
+
+ # Patched on this package's namespace rather than on the shared
+ # ``importlib`` module, whose replacement would reach every importer in
+ # the process for the duration of the test (#1123).
+ monkeypatch.setattr(tools_module, "importlib", _ShimImportlib)
+ monkeypatch.setattr(tools_module, "_SUBCLASSES_CACHE", None)
+ monkeypatch.setattr(tools_module, "_DISCOVERY_FAILURES", {})
+
+ with caplog.at_level(logging.WARNING, logger="src.tools"):
+ tools_module._discover_subclasses()
+
+ assert [
+ message
+ for message in caplog.messages
+ if target in message and "no module named 'nowhere'" in message
+ ], caplog.messages
+ assert tools_module._DISCOVERY_FAILURES[target] == (
+ "ImportError: no module named 'nowhere'"
+ )