fix(tools): don't pre-check keyless local backends in Tool Gateway checklist

get_gateway_eligible_tools() classified a tool as "unconfigured" whenever
it found no direct API-key credential, ignoring an explicit non-nous
selection already stored in config (e.g. web.backend: searxng, a keyless
self-hosted backend). Every unconfigured tool is pre-checked in the
`hermes model` Tool Gateway checklist, so a single Enter during Nous model
setup silently rewrote web.backend (and similarly browser.cloud_provider,
tts/stt/image_gen.provider) to "nous" for users who had deliberately
configured a keyless local backend.

get_gateway_eligible_tools() now also resolves each tool's stored
selection via the existing _selected_provider() helper and routes an
explicit non-nous selection into a new explicit_configured bucket instead
of unconfigured. prompt_enable_tool_gateway() never offers those tools,
so they can no longer be pre-checked or accidentally overwritten.

Fixes #92647
This commit is contained in:
chelsealong
2026-08-23 03:09:22 +00:00
committed by Teknium
parent f4067774aa
commit 4edb24276f
2 changed files with 74 additions and 5 deletions
+34 -5
View File
@@ -1034,16 +1034,34 @@ _GATEWAY_DIRECT_LABELS = {
_ALL_GATEWAY_KEYS = ("web", "image_gen", "video_gen", "tts", "stt", "browser")
# Config section + selection field for each gateway key, matching the
# field names ``apply_gateway_defaults`` writes and
# ``get_nous_subscription_features`` reads (web uses "backend", browser
# uses "cloud_provider", everything else uses "provider").
_GATEWAY_SECTION_FIELDS = {
"web": ("web", "backend"),
"image_gen": ("image_gen", "provider"),
"video_gen": ("video_gen", "provider"),
"tts": ("tts", "provider"),
"stt": ("stt", "provider"),
"browser": ("browser", "cloud_provider"),
}
def get_gateway_eligible_tools(
config: Optional[Dict[str, object]] = None,
*,
force_fresh: bool = False,
) -> tuple[list[str], list[str], list[str]]:
"""Return (unconfigured, has_direct, already_managed) tool key lists.
) -> tuple[list[str], list[str], list[str], list[str]]:
"""Return (unconfigured, has_direct, explicit_configured, already_managed)
tool key lists.
- unconfigured: tools with no direct credentials (easy switch)
- unconfigured: tools with no direct credentials and no explicit
non-nous selection (easy switch, safe to pre-check)
- has_direct: tools where the user has their own API keys
- explicit_configured: tools with an explicit non-nous selection stored
(e.g. ``web.backend: searxng``), including keyless backends that would
otherwise look unconfigured
- already_managed: tools already routed through the gateway
All lists are empty when the user is not a paid Nous subscriber or
@@ -1084,6 +1102,7 @@ def get_gateway_eligible_tools(
unconfigured: list[str] = []
has_direct: list[str] = []
explicit_configured: list[str] = []
already_managed: list[str] = []
for key in _ALL_GATEWAY_KEYS:
# Only offer tools the user's entitlement actually covers. For a free
@@ -1093,13 +1112,20 @@ def get_gateway_eligible_tools(
MANAGED_FEATURE_COVERAGE_CATEGORY[key]
):
continue
section_key, field = _GATEWAY_SECTION_FIELDS[key]
selected = _selected_provider(config.get(section_key), field)
if opted_in.get(key):
already_managed.append(key)
elif selected is not None and selected != "nous":
# An explicit non-nous selection (e.g. a keyless local backend
# like SearXNG or Camofox) is configured on purpose, even
# though it has no direct credentials to detect.
explicit_configured.append(key)
elif direct.get(key):
has_direct.append(key)
else:
unconfigured.append(key)
return unconfigured, has_direct, already_managed
return unconfigured, has_direct, explicit_configured, already_managed
def apply_gateway_defaults(
@@ -1193,7 +1219,10 @@ def prompt_enable_tool_gateway(
Returns the set of tools that were enabled, or empty set if the user
declined or no tools were eligible.
"""
unconfigured, has_direct, already_managed = get_gateway_eligible_tools(
# explicit_configured tools (e.g. an explicit `web.backend: searxng`) are
# configured on purpose and are never offered here — same treatment as
# already_managed, just for a non-nous vendor.
unconfigured, has_direct, _explicit_configured, already_managed = get_gateway_eligible_tools(
config,
force_fresh=force_fresh,
)
@@ -206,6 +206,46 @@ def test_prompt_enable_tool_gateway_pool_offers_covered_tools_only(monkeypatch):
assert "free" in captured["title"].lower() and "pool" in captured["title"].lower()
def test_get_gateway_eligible_tools_treats_explicit_backend_as_configured(monkeypatch):
"""A keyless local backend (e.g. searxng) has no credentials to detect,
but an explicit non-nous selection must still keep it out of
'unconfigured' — regression for #92647, where it was pre-checked and a
single Enter during `hermes model` overwrote it to `web.backend: nous`.
"""
monkeypatch.setattr(ns, "get_nous_portal_account_info", lambda **kw: _account(logged_in=True, paid=True))
monkeypatch.setattr(
ns,
"_get_gateway_direct_credentials",
lambda: {"web": False, "image_gen": False, "video_gen": False, "tts": False, "browser": False},
)
config = {"model": {"provider": "nous"}, "web": {"backend": "searxng"}}
unconfigured, has_direct, explicit_configured, already_managed = ns.get_gateway_eligible_tools(config)
assert "web" not in unconfigured
assert "web" not in has_direct
assert "web" in explicit_configured
assert "web" not in already_managed
def test_prompt_enable_tool_gateway_never_offers_explicit_backend(monkeypatch):
"""The checklist itself must not list (let alone pre-check) a tool with
an explicit non-nous selection, so it can never be silently overwritten
by an accidental Enter."""
monkeypatch.setattr(ns, "get_nous_portal_account_info", lambda **kw: _account(logged_in=True, paid=True))
monkeypatch.setattr(
ns,
"_get_gateway_direct_credentials",
lambda: {"web": False, "image_gen": False, "video_gen": False, "tts": False, "browser": False},
)
captured = _capture_checklist(monkeypatch, selected_idx=[])
config = {"model": {"provider": "nous"}, "web": {"backend": "searxng"}}
ns.prompt_enable_tool_gateway(config)
blob = " ".join(captured["items"]).lower()
assert "firecrawl" not in blob # web (searxng-configured) NOT offered
assert "image" in blob # other unconfigured tools still offered
def test_apply_nous_managed_defaults_writes_video_gen_config(monkeypatch):