Skip to content

The agent that grows with you

fix(tools): log the traceback when a check_fn raises on the cached path

teknium1aa7980d77789
diff --git a/tests/tools/test_terminal_tool_requirements.py b/tests/tools/test_terminal_tool_requirements.py
index 828b5f04889..4817c2cdc08 100644
--- a/tests/tools/test_terminal_tool_requirements.py
+++ b/tests/tools/test_terminal_tool_requirements.py
@@ -368,6 +368,21 @@ class TestUnscopedSecretReadLogging:
crashed check_fn (WARNING + traceback); an unscoped read reported while
the scope was *resolved* is a genuinely lost scope and stays loud."""
+ def test_raising_check_fn_logs_traceback_on_cached_path(self, caplog):
+ """A check_fn that raises is a probe bug, not "nothing configured": the verdict log must
+ carry the traceback so a silently stripped toolset is diagnosable from agent.log (#87950)."""
+ import logging
+
+ import tools.registry as reg
+
+ def probe():
+ raise RuntimeError("resolver exploded")
+
+ with caplog.at_level(logging.WARNING, logger="tools.registry"):
+ assert reg._check_fn_cached(probe) is False
+ verdicts = [r for r in caplog.records if "dependent tools will be unavailable" in r.getMessage()]
+ assert verdicts and all(r.exc_info and r.exc_info[0] is RuntimeError for r in verdicts)
+
def test_expected_fail_closed_probe_is_quiet_but_lost_scope_stays_loud(self, caplog):
import logging
diff --git a/tools/registry.py b/tools/registry.py
index 8544c76af54..f2469d41364 100644
--- a/tools/registry.py
+++ b/tools/registry.py
@@ -311,10 +311,14 @@ def _check_fn_cached(fn: Callable) -> bool:
cached = _check_fn_cache.get(cache_key)
if cached is not None:
return cached[1]
+ exc_info = None
try:
value, outcome = bool(fn()), "returned False"
- except Exception:
- value, outcome = False, "raised"
+ except Exception as exc:
+ # Keep the exception for the verdict log below (emitted outside this block, where
+ # ``exc_info=True`` would resolve to nothing): a check_fn that raises is a bug in the probe
+ # or its resolver, and a bare "raised" verdict reads as "nothing configured" (#87950).
+ value, outcome, exc_info = False, "raised", exc
with _check_fn_cache_lock:
_prune_check_fn_caches(now)
if value:
@@ -333,7 +337,8 @@ def _check_fn_cached(fn: Callable) -> bool:
# No recent success (or grace expired) — honor the failure; logged so silent tool
# loss in quiet mode (subagents) is diagnosable.
logger.warning(
- "check_fn %s %s; dependent tools will be unavailable this turn", _fn_label(fn), outcome)
+ "check_fn %s %s; dependent tools will be unavailable this turn", _fn_label(fn), outcome,
+ exc_info=exc_info)
_check_fn_cache[cache_key] = (now, False)
return False