The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tools): warn once when a check_fn drops a core tool; reject a mistyped catalog_provider
teknium14e41ab0979b5
diff --git a/agent/models_dev.py b/agent/models_dev.pyindex cefa0774d37..4f35b40d165 100644--- a/agent/models_dev.py+++ b/agent/models_dev.py@@ -175,9 +175,20 @@ def _models_dev_id(provider: str) -> Optional[str]:if mdev_id is None:alias = _configured_catalog_provider(key)mdev_id = PROVIDER_TO_MODELS_DEV.get(alias, alias) if alias else None+ if mdev_id is not None and mdev_id not in PROVIDER_TO_MODELS_DEV.values() \+ and mdev_id not in fetch_models_dev(allow_network=False):+ # A mistyped alias must not leak into ModelInfo.provider_id; the row stays on its own slug.+ if (key, alias) not in _UNKNOWN_CATALOG_PROVIDER_WARNED:+ _UNKNOWN_CATALOG_PROVIDER_WARNED.add((key, alias))+ logger.warning("providers.%s: catalog_provider %r is neither a Hermes provider id nor a "+ "models.dev id; ignoring", key, alias)+ mdev_id = Nonereturn mdev_id+_UNKNOWN_CATALOG_PROVIDER_WARNED: set = set() # (provider, alias) warned once per process++def _cfg_get(*keys: str, default: Any) -> Any:"""``cfg_get`` over the read-only config; *default* on any failure."""try:diff --git a/tests/agent/test_models_dev.py b/tests/agent/test_models_dev.pyindex 3b7a03d046c..eae6ce2253c 100644--- a/tests/agent/test_models_dev.py+++ b/tests/agent/test_models_dev.py@@ -903,6 +903,27 @@ class TestCatalogProviderAlias:assert ctx == 128000assert info is not None and info.provider_id == "deepseek" and info.context_window == 128000+ def test_mistyped_alias_warns_once_and_keeps_the_configured_slug(self, caplog):+ """``catalog_provider: deepsek`` is neither a Hermes provider id nor a models.dev id: warn+ once (per process, like the unknown-key warning) and keep ``ModelInfo.provider_id`` on the+ configured slug instead of leaking the typo as a vendor id."""+ import logging++ import agent.models_dev as md++ config = {"providers": {"925llm": {"api": "http://gw.internal/v1", "catalog_provider": "deepsek"}},+ "model_overrides": {"925llm": {"deepseek-v4.1-flash": {"context_window": 1000000}}}}+ md._UNKNOWN_CATALOG_PROVIDER_WARNED.clear()+ with self._cfg(config), patch("agent.models_dev.fetch_models_dev", return_value={"deepseek": {"models": {}}}), \+ caplog.at_level(logging.WARNING, logger="agent.models_dev"):+ info = get_model_info("925llm", "deepseek-v4.1-flash")+ assert get_model_capabilities("925llm", "deepseek-v4.1-flash").supports_vision is None+ get_model_info("925llm", "deepseek-v4.1-flash")++ assert info is not None and info.provider_id == "925llm"+ warned = [r for r in caplog.records if "catalog_provider" in r.getMessage()]+ assert len(warned) == 1 and "deepsek" in warned[0].getMessage() and "925llm" in warned[0].getMessage()+def test_without_alias_custom_provider_stays_unknown(self):"""Control: no alias → no vendor inheritance, and a legacy ``custom_providers`` row can alias too."""config = {"providers": {"925llm": {"api": "http://gw.internal/v1"}},diff --git a/tests/tools/test_terminal_tool_requirements.py b/tests/tools/test_terminal_tool_requirements.pyindex c1befda9772..fcbdcc18c0f 100644--- a/tests/tools/test_terminal_tool_requirements.py+++ b/tests/tools/test_terminal_tool_requirements.py@@ -147,6 +147,48 @@ 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."""+ import tools.registry as reg++ def core_gate():+ return False++ def optional_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)+ reg.invalidate_check_fn_cache()+ try:+ with caplog.at_level(logging.INFO, logger="tools.registry"):+ assert reg._check_fn_cached(core_gate) is False+ assert reg._check_fn_cached(optional_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.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()]+ 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()+def test_grace_expiry_lets_real_outage_through(self, monkeypatch):import tools.registry as regdiff --git a/tools/registry.py b/tools/registry.pyindex aca8baa4c42..af67cf9ec29 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_core_drop_warned: Set[tuple[Callable, Optional[str]]] = set() # once-per-process WARNING gate_check_fn_cache_lock = threading.Lock()CHECK_FN_CACHE_BYPASS = ""_NO_CACHE_CHECK_FNS: Set[Callable] = set()@@ -336,6 +337,8 @@ def _check_fn_cached(fn: Callable) -> bool:# ``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+ # Resolved outside the cache lock: the registry snapshot takes its own lock.+ core_dropped = sorted(_core_tools_gated_by(fn)) if not value else []with _check_fn_cache_lock:_prune_check_fn_caches(now)if value:@@ -353,14 +356,34 @@ 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.- log = logger.warning if exc_info else logger.info- log(- "check_fn %s %s; dependent tools will be unavailable this turn", _fn_label(fn), outcome,- exc_info=exc_info)+ # 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:+ _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",+ _fn_label(fn), outcome, ", ".join(core_dropped), exc_info=exc_info)+ else:+ log = logger.warning if exc_info else logger.info+ log(+ "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+def _core_tools_gated_by(fn: Callable) -> Set[str]:+ """Names of ``_HERMES_CORE_TOOLS`` members whose registered ``check_fn`` is *fn*."""+ try:+ from toolsets import _HERMES_CORE_TOOLS+ core = frozenset(_HERMES_CORE_TOOLS)+ except Exception:+ return set()+ return {e.name for e in registry._snapshot_entries() if e.check_fn is fn and e.name in core}++def _memo_check(fn: Callable, memo: Dict[Callable, bool]) -> bool:"""Per-pass memo on top of the TTL cache: one probe per distinct check_fn."""if fn not in memo:@@ -373,6 +396,7 @@ def invalidate_check_fn_cache() -> None:with _check_fn_cache_lock:_check_fn_cache.clear()_check_fn_last_good.clear()+ _check_fn_core_drop_warned.clear()def get_cached_check_fn_result(fn: Callable) -> Optional[bool]: