Skip to content

The agent that grows with you

fix(tools): core-tool drop warns only after the probe had admitted it

teknium10a3b74379f8e
diff --git a/tests/tools/test_terminal_tool_requirements.py b/tests/tools/test_terminal_tool_requirements.py
index fcbdcc18c0f..39797f7c6af 100644
--- a/tests/tools/test_terminal_tool_requirements.py
+++ b/tests/tools/test_terminal_tool_requirements.py
@@ -147,47 +147,55 @@ class TestCheckFnTransientFailureSuppression:
assert raised[0].exc_info is not None
- def test_core_tool_drop_warns_once_but_optional_tool_drop_stays_info(self, monkeypatch, caplog):
- """A check_fn that drops a ``_HERMES_CORE_TOOLS`` member logs at WARNING naming the tool
- (#112649 atom 4): core tools are non-deferrable, so a dropped one leaves neither the schema
- nor the tool_search catalog and the model's "no such tool" is accurate. Optional toolsets
- keep the INFO verdict of ae5666f7fc4; the WARNING fires once per probe per process, not
- on every TTL re-probe."""
+ def test_core_tool_drop_after_success_warns_once_never_configured_stays_info(self, monkeypatch, caplog):
+ """A check_fn that drops a ``_HERMES_CORE_TOOLS`` member it had previously admitted logs at
+ WARNING naming the tool (#112649 atom 4): core tools are non-deferrable, so a dropped one
+ leaves neither the schema nor the tool_search catalog and the model's "no such tool" is
+ accurate. A core tool whose probe never succeeded (unconfigured browser/image_gen/HA on a
+ stock home) keeps the INFO verdict of ae5666f7fc4 — the live pass counted 13 WARNINGs per
+ process when every unconfigured core tool warned. The WARNING fires once per probe per
+ process, not on every TTL re-probe.
+ """
import tools.registry as reg
+ state = {"core": True}
+
def core_gate():
- return False
+ return state["core"]
- def optional_gate():
+ def never_gate():
return False
import toolsets
clock = {"now": 1000.0}
monkeypatch.setattr(reg.time, "monotonic", lambda: clock["now"])
- monkeypatch.setattr(toolsets, "_HERMES_CORE_TOOLS", [*toolsets._HERMES_CORE_TOOLS, "core_probe_tool"])
- reg.registry.register(name="core_probe_tool", toolset="core_probe", schema={"name": "core_probe_tool"},
- handler=lambda **kw: None, check_fn=core_gate)
- reg.registry.register(name="optional_probe_tool", toolset="optional_probe", schema={"name": "x"},
- handler=lambda **kw: None, check_fn=optional_gate)
+ monkeypatch.setattr(toolsets, "_HERMES_CORE_TOOLS",
+ [*toolsets._HERMES_CORE_TOOLS, "core_probe_tool", "never_probe_tool"])
+ for name, gate in (("core_probe_tool", core_gate), ("never_probe_tool", never_gate)):
+ reg.registry.register(name=name, toolset=name, schema={"name": name},
+ handler=lambda **kw: None, check_fn=gate)
reg.invalidate_check_fn_cache()
try:
with caplog.at_level(logging.INFO, logger="tools.registry"):
+ assert reg._check_fn_cached(core_gate) is True
+ assert reg._check_fn_cached(never_gate) is False
+ state["core"] = False
+ clock["now"] += reg._CHECK_FN_FAILURE_GRACE_SECONDS + reg._CHECK_FN_TTL_SECONDS + 1
assert reg._check_fn_cached(core_gate) is False
- assert reg._check_fn_cached(optional_gate) is False
+ assert reg._check_fn_cached(never_gate) is False
clock["now"] += reg._CHECK_FN_TTL_SECONDS + 1
assert reg._check_fn_cached(core_gate) is False
finally:
reg.registry.deregister("core_probe_tool")
- reg.registry.deregister("optional_probe_tool")
+ reg.registry.deregister("never_probe_tool")
reg.invalidate_check_fn_cache()
core = [r for r in caplog.records if "core_gate" in r.getMessage()]
- optional = [r for r in caplog.records if "optional_gate" in r.getMessage()]
+ never = [r for r in caplog.records if "never_gate" in r.getMessage()]
assert [r.levelno for r in core] == [logging.WARNING, logging.INFO]
- assert "core_probe_tool" in core[0].getMessage() and "dependent tools will be unavailable" in core[0].getMessage()
- assert [r.levelno for r in optional] == [logging.INFO]
- assert "core tool" not in optional[0].getMessage()
+ assert "core_probe_tool" in core[0].getMessage()
+ assert never and all(r.levelno == logging.INFO for r in never)
def test_grace_expiry_lets_real_outage_through(self, monkeypatch):
import tools.registry as reg
diff --git a/tools/registry.py b/tools/registry.py
index af67cf9ec29..a59f0f9e162 100644
--- a/tools/registry.py
+++ b/tools/registry.py
@@ -226,6 +226,7 @@ _CHECK_FN_FAILURE_GRACE_SECONDS = 60.0
_CHECK_FN_CACHE_MAX = 512
_check_fn_cache: Dict[tuple[Callable, Optional[str]], tuple[float, bool]] = {}
_check_fn_last_good: Dict[tuple[Callable, Optional[str]], float] = {}
+_check_fn_ever_good: Set[tuple[Callable, Optional[str]]] = set() # probes that admitted tools this process
_check_fn_core_drop_warned: Set[tuple[Callable, Optional[str]]] = set() # once-per-process WARNING gate
_check_fn_cache_lock = threading.Lock()
CHECK_FN_CACHE_BYPASS = ""
@@ -343,6 +344,7 @@ def _check_fn_cached(fn: Callable) -> bool:
_prune_check_fn_caches(now)
if value:
_check_fn_last_good[cache_key] = now
+ _check_fn_ever_good.add(cache_key)
_check_fn_cache[cache_key] = (now, True)
return True
last_good = _check_fn_last_good.get(cache_key)
@@ -356,14 +358,17 @@ def _check_fn_cached(fn: Callable) -> bool:
# No recent success (or grace expired) — honor the failure. A False verdict is the
# expected state for optional, unconfigured toolsets; only a raised probe is actionable.
- # Core (non-deferrable) tools are the exception: dropped, they leave neither the schema
- # nor the tool_search catalog, so the model's "no such tool" is accurate and nothing
- # points at the probe. Their drop is a WARNING once per probe per process (#112649).
- if core_dropped and cache_key not in _check_fn_core_drop_warned:
+ # Core (non-deferrable) tools are the exception when they were available earlier in
+ # this process and the probe now fails: dropped, they leave neither the schema nor the
+ # tool_search catalog, so the model's "no such tool" is accurate and nothing points at
+ # the probe. That regression is a WARNING once per probe per process (#112649). A core
+ # tool whose probe never succeeded (browser, image_gen, HA unconfigured on a stock home)
+ # is the expected state and keeps the INFO verdict.
+ if core_dropped and cache_key in _check_fn_ever_good and cache_key not in _check_fn_core_drop_warned:
_check_fn_core_drop_warned.add(cache_key)
logger.warning(
- "check_fn %s %s; core tool(s) %s dropped (non-deferrable, so not searchable "
- "either); dependent tools will be unavailable this turn",
+ "check_fn %s %s; previously available core tool(s) %s dropped (non-deferrable, "
+ "so not searchable either); dependent tools will be unavailable this turn",
_fn_label(fn), outcome, ", ".join(core_dropped), exc_info=exc_info)
else:
log = logger.warning if exc_info else logger.info
@@ -396,6 +401,7 @@ def invalidate_check_fn_cache() -> None:
with _check_fn_cache_lock:
_check_fn_cache.clear()
_check_fn_last_good.clear()
+ _check_fn_ever_good.clear()
_check_fn_core_drop_warned.clear()