Skip to content

The agent that grows with you

fix(cli): decouple the custom-probe budget from for_picker visibility

liuhao10249e7805858442
diff --git a/hermes_cli/cli_model_switch_mixin.py b/hermes_cli/cli_model_switch_mixin.py
index 27dfbd7ec67..cc74086f109 100644
--- a/hermes_cli/cli_model_switch_mixin.py
+++ b/hermes_cli/cli_model_switch_mixin.py
@@ -300,6 +300,9 @@ def _show_model_picker(cli, ctx, force_refresh: bool) -> None:
# per-model for many providers, so another model may work (#103829) —
# same contract as the gateway picker (#66584) and aux pickers (#66624).
for_picker=True,
+ # Visibility only, not a faster probe: this call live-probes the current custom
+ # endpoint, which historically enjoyed the full 5s discovery budget (#103843).
+ fast_custom_probe=False,
)["providers"]
except Exception:
providers = []
diff --git a/hermes_cli/inventory.py b/hermes_cli/inventory.py
index 085ba0eb717..62ca4e3864b 100644
--- a/hermes_cli/inventory.py
+++ b/hermes_cli/inventory.py
@@ -78,13 +78,16 @@ def build_models_payload(
capabilities: bool = False, featured: bool = False, force_fresh_nous_tier: bool = False,
refresh: bool = False, probe_custom_providers: bool = True, probe_current_custom_provider: bool = False,
for_picker: bool = False, max_models: int | None = None, non_blocking_catalogs: bool = False,
+ fast_custom_probe: bool | None = None,
) -> dict:
"""Build the ``{providers, model, provider}`` shape every consumer needs. ``explicit_only`` keeps
only providers the user explicitly configured — hides ambient/auto-seeded credentials from
desktop chat pickers. ``pricing_cache_only``: with ``pricing``, use only values already resident
in process caches (normal picker opens, while a background worker warms cold endpoints).
``non_blocking_catalogs``: provider catalogs come from the disk cache only — a degraded provider
- cannot stall the response (GUI picker opens)."""
+ cannot stall the response (GUI picker opens). ``fast_custom_probe`` overrides the
+ custom-endpoint discovery budget ``for_picker`` otherwise implies (1.5s vs 5s) — ``None`` keeps
+ the coupling, ``False`` retains the full 5s budget (#103843)."""
from hermes_cli.model_switch import list_authenticated_providers
rows = list_authenticated_providers(
@@ -94,7 +97,7 @@ def build_models_payload(
max_models=max_models, refresh=refresh, probe_custom_providers=probe_custom_providers,
probe_current_custom_provider=probe_current_custom_provider, for_picker=for_picker,
excluded_providers=ctx.excluded_providers or [],
- non_blocking_catalogs=non_blocking_catalogs,
+ non_blocking_catalogs=non_blocking_catalogs, fast_custom_probe=fast_custom_probe,
)
# Managed local runtime: staged GGUFs are selectable like any provider's models, but
diff --git a/hermes_cli/model_switch_providers.py b/hermes_cli/model_switch_providers.py
index fc219b42e44..bf08855fc14 100644
--- a/hermes_cli/model_switch_providers.py
+++ b/hermes_cli/model_switch_providers.py
@@ -597,15 +597,20 @@ def _group_display_name(display_name: str) -> str:
def _discover_endpoint_models(
api_key: Any, api_url: str, native_catalog_provider: str, has_explicit_models: bool, *,
headers: dict | None, api_mode: str | None, probe_live: bool, discovery_allowed: bool,
- for_picker: bool) -> tuple[list | None, bool]:
+ fast_custom_probe: bool) -> tuple[list | None, bool]:
"""Return ``(models, native_catalog_empty)`` for a custom endpoint row.
``probe_live`` runs the native-aware picker fetch; otherwise, when discovery is allowed, a
warm same-fingerprint cache entry still serves the full catalog with no round-trip.
``has_explicit_models`` gates the *probe* (a network-cost guard for keyless endpoints that
declare a catalog), never the cache read — applying it to the read re-pins the endpoint to
- its declared subset. Returns ``(None, False)`` when nothing usable was found."""
- timeout = 1.5 if for_picker else 5.0
+ its declared subset. Returns ``(None, False)`` when nothing usable was found.
+
+ ``fast_custom_probe`` picks the discovery budget (1.5s fast / 5s full) independently of the
+ caller's exhausted-pool visibility flag: a picker that keeps cooldown providers visible
+ still deserves the full budget when it is the one surface that live-probes the current
+ custom endpoint."""
+ timeout = 1.5 if fast_custom_probe else 5.0
if probe_live:
try:
live_models = _fetch_picker_live_models(
@@ -699,6 +704,10 @@ class _PickerBuild:
refresh: bool
excluded: set
curated: dict
+ # Discovery budget override for custom endpoints (1.5s fast / 5s full). None keeps the
+ # historical coupling to for_picker; callers that only want exhausted-pool visibility set
+ # for_picker=True, fast_custom_probe=False so their probe budget is unchanged (#103843).
+ fast_custom_probe: bool | None = None
# GUI read path: catalogs are read from cache only; stale/missing ones warm in the background.
non_blocking_catalogs: bool = False
results: list = field(default_factory=list)
@@ -716,6 +725,11 @@ class _PickerBuild:
def current_base_url_norm(self) -> str:
return self.current_base_url.rstrip("/").lower()
+ @property
+ def resolved_fast_custom_probe(self) -> bool:
+ """None defers to for_picker so pre-existing callers keep their timeout."""
+ return self.for_picker if self.fast_custom_probe is None else self.fast_custom_probe
+
def can_probe_custom(self, *, row_is_current: bool) -> bool:
return bool(self.probe_custom_providers or (self.probe_current_custom_provider and row_is_current))
@@ -789,7 +803,7 @@ class _PickerBuild:
discovered, native_catalog_empty = _discover_endpoint_models(
api_key, api_url, native_provider, has_explicit_models,
headers=headers, api_mode=api_mode, probe_live=probe_live,
- discovery_allowed=discovery_allowed, for_picker=self.for_picker)
+ discovery_allowed=discovery_allowed, fast_custom_probe=self.resolved_fast_custom_probe)
return discovered, native_catalog_empty, probe_live
@@ -1049,7 +1063,7 @@ def _lap_bare_custom_row(b: _PickerBuild, custom_providers: list | None) -> None
discovered, native_catalog_empty = _discover_endpoint_models(
"", api_url, "custom", False, headers=None, api_mode=None,
probe_live=bool(b.refresh or b.probe_current_custom_provider), discovery_allowed=True,
- for_picker=b.for_picker)
+ fast_custom_probe=b.resolved_fast_custom_probe)
if discovered is not None:
models = discovered
except Exception:
@@ -1189,7 +1203,7 @@ def list_authenticated_providers(
max_models: int | None = None, current_model: str = "", refresh: bool = False,
probe_custom_providers: bool = True, probe_current_custom_provider: bool = False,
for_picker: bool = False, excluded_providers: list | None = None,
- non_blocking_catalogs: bool = False) -> List[dict]:
+ non_blocking_catalogs: bool = False, fast_custom_probe: bool | None = None) -> List[dict]:
"""Detect which providers have credentials and list their curated (not full models.dev) models.
Returns dicts with ``slug`` (the --provider value), ``name``, ``is_current``,
@@ -1201,7 +1215,10 @@ def list_authenticated_providers(
true, GUI false); ``probe_current_custom_provider`` probes only the selected custom endpoint.
``non_blocking_catalogs`` is the GUI read path (``model.options``): provider catalogs come from
the disk cache only and stale/missing ones warm in the background, so a degraded provider
- never stalls the picker (#114215)."""
+ never stalls the picker (#114215). ``fast_custom_probe`` overrides the custom-endpoint
+ discovery budget ``for_picker`` otherwise implies (1.5s vs 5s) — ``None`` keeps the
+ historical coupling, ``False`` retains the full 5s budget for callers that only want
+ exhausted-pool visibility (#103843)."""
from agent.models_dev import fetch_models_dev
from hermes_cli.config import coerce_provider_id, stringify_provider_map
@@ -1234,7 +1251,7 @@ def list_authenticated_providers(
max_models=max_models, for_picker=for_picker, force_fresh_nous_tier=force_fresh_nous_tier,
probe_custom_providers=probe_custom_providers, probe_current_custom_provider=probe_current_custom_provider,
refresh=refresh, excluded={str(p).strip().lower() for p in (excluded_providers or []) if p},
- non_blocking_catalogs=non_blocking_catalogs,
+ non_blocking_catalogs=non_blocking_catalogs, fast_custom_probe=fast_custom_probe,
curated=_build_curated_lists(current_provider, current_base_url, current_model,
non_blocking=non_blocking_catalogs))
diff --git a/tests/hermes_cli/test_picker_probe_budget_decoupling.py b/tests/hermes_cli/test_picker_probe_budget_decoupling.py
new file mode 100644
index 00000000000..d4877b13406
--- /dev/null
+++ b/tests/hermes_cli/test_picker_probe_budget_decoupling.py
@@ -0,0 +1,62 @@
+"""Regression test for the probe-budget decoupling on #103843.
+
+``for_picker`` historically picked the custom-endpoint discovery timeout
+(1.5s fast / 5s full). When the CLI main picker started forwarding
+``for_picker=True`` for exhausted-pool visibility, a slow-but-working
+current custom endpoint lost its models: an endpoint answering between
+the two budgets fell out of ``/model``. ``fast_custom_probe`` now owns
+the budget so visibility no longer shortens discovery.
+"""
+
+import pytest
+
+from hermes_cli.model_switch import list_authenticated_providers
+
+
[email protected](autouse=True)
+def _no_builtin_catalog_fetches(monkeypatch):
+ """Keep the row builder independent of provider credentials and network."""
+ monkeypatch.setattr("hermes_cli.models.cached_provider_model_ids", lambda *_a, **_kw: [])
+ monkeypatch.setattr("hermes_cli.models.provider_model_ids", lambda *_a, **_kw: [])
+ monkeypatch.setattr("hermes_cli.models.fetch_api_models", lambda *_a, **_kw: None)
+ monkeypatch.setattr("hermes_cli.models_local.fetch_ollama_local_models", lambda *_a, **_kw: None)
+
+
+def _slow_endpoint_rows(monkeypatch, **extra):
+ """Rows for a current custom endpoint answering after 1.5s but within 5s."""
+
+ def _fake_live(_api_key, _api_url, _native_provider, _preserve, headers=None,
+ timeout=5.0, api_mode=None, **_kw):
+ return ["slow-discovered-model"] if timeout >= 5.0 else None
+
+ monkeypatch.setattr("hermes_cli.model_switch_providers._fetch_picker_live_models", _fake_live)
+ return list_authenticated_providers(
+ current_provider="custom", current_base_url="http://127.0.0.1:9999/v1",
+ current_model="kept-model", probe_custom_providers=False,
+ probe_current_custom_provider=True, for_picker=True, **extra)
+
+
+def _custom_row(rows):
+ return next(r for r in rows if r["slug"] == "custom")
+
+
+def test_full_budget_keeps_slow_endpoint_models(monkeypatch):
+ """for_picker visibility with fast_custom_probe=False retains the historical 5s budget."""
+ row = _custom_row(_slow_endpoint_rows(monkeypatch, fast_custom_probe=False))
+
+ assert "slow-discovered-model" in row["models"]
+
+
+def test_default_callers_keep_the_fast_budget_coupling(monkeypatch):
+ """fast_custom_probe=None still defers to for_picker: the legacy fast-picker behavior."""
+ row = _custom_row(_slow_endpoint_rows(monkeypatch))
+
+ assert "slow-discovered-model" not in row["models"]
+ assert row["models"] == ["kept-model"]
+
+
+def test_explicit_fast_probe_true_still_cuts_the_budget(monkeypatch):
+ row = _custom_row(_slow_endpoint_rows(monkeypatch, fast_custom_probe=True))
+
+ assert "slow-discovered-model" not in row["models"]
+ assert row["models"] == ["kept-model"]
diff --git a/tests/hermes_cli/test_show_model_picker_exhausted_pool.py b/tests/hermes_cli/test_show_model_picker_exhausted_pool.py
index 881718c263f..ed626749eda 100644
--- a/tests/hermes_cli/test_show_model_picker_exhausted_pool.py
+++ b/tests/hermes_cli/test_show_model_picker_exhausted_pool.py
@@ -43,6 +43,9 @@ def test_show_model_picker_requests_for_picker():
# The reasoning-effort step depends on the capability map; the rebase onto a main
# that added ``capabilities=True`` must keep both flags in the same call.
assert captured.get("capabilities") is True
+ # Visibility only: this call live-probes the current custom endpoint, which must keep
+ # its historical 5s discovery budget instead of the 1.5s fast-picker one (#103843).
+ assert captured.get("fast_custom_probe") is False
cli._open_model_picker.assert_called_once()
assert cli._open_model_picker.call_args[0][0] is providers