Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

## [Unreleased]

### Fixed
- **`/api/models/live` now probes upstream for custom providers even when `model:` is configured.** Previously, when a `custom_providers` entry had a `model:` field, the live endpoint extracted that as the model list and skipped the live `/v1/models` probe entirely. The model picker's refresh button returned only the config entry instead of the full upstream catalog. Config-specified models are now used as a fallback and merged with the live results. (#3718)

## [v0.51.292] — 2026-06-06 — Release JH (stage-s4 — compression-exhausted turns surface as errors, not fake completions)

### Fixed
Expand Down
21 changes: 18 additions & 3 deletions api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10229,14 +10229,19 @@ def _custom_provider_api_key(_cp):
# Fall back to the custom_providers entries from config.yaml so
# the live-model enrichment step can add any models that weren't
# already in the static list (issue #1619).
# Collect config-specified model IDs separately so they don't
# prevent the live fetch below from running (#3718).
_config_ids = []
if provider == "custom" or provider.startswith("custom:"):
for _cp in _custom_provider_entries_for_request():
if custom_provider_entry is None:
custom_provider_entry = _cp
ids.extend(_custom_provider_model_ids(_cp))
_config_ids.extend(_custom_provider_model_ids(_cp))

# If still no ids, try fetching from base_url directly (OpenAI-compat endpoint)
if not ids and (provider == "custom" or provider.startswith("custom:")):
# Always try live fetch for custom providers — config entries are a
# fallback, not a replacement. The live endpoint should return ALL
# models the key has access to, not just what's listed in config.yaml.
if provider == "custom" or provider.startswith("custom:"):
_base_url = None
_api_key = None
if custom_provider_entry:
Expand Down Expand Up @@ -10283,6 +10288,16 @@ def _custom_provider_api_key(_cp):

except Exception as _fetch_err:
logger.debug("Live fetch from custom provider failed: %s", _fetch_err)

# If live fetch succeeded, merge with config entries (live takes
# priority). If live fetch failed, fall back to config-only list.
if ids:
_live_set = set(ids)
for _cid in _config_ids:
if _cid not in _live_set:
ids.append(_cid)
else:
ids = list(_config_ids)

# ── OpenAI-compat live fetch fallback ──────────────────────────────────
# When provider_model_ids() is unavailable or returns [] for a provider
Expand Down
42 changes: 42 additions & 0 deletions tests/test_issue3718_live_models_custom_probe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Regression test for #3718 -- /api/models/live skips probe for custom providers.

When a custom provider (``custom_providers`` entry in config.yaml) has a
``model:`` field but no ``models:`` allowlist, the live endpoint previously
populated ``ids`` from the config entry and then skipped the live ``/v1/models``
probe (guarded by ``if not ids``). The fix collects config-specified model IDs
in a separate ``_config_ids`` list so the live fetch always runs, and merges
config entries as a fallback after the fetch.
"""
import pathlib

ROUTES_PY = (pathlib.Path(__file__).parent.parent / "api" / "routes.py").read_text(encoding="utf-8")


class TestLiveModelsCustomProviderProbe:
"""Live endpoint must probe the upstream /v1/models even when config has entries."""

def test_config_ids_collected_separately(self):
"""Config-specified model IDs must go into ``_config_ids``, not ``ids``."""
assert "_config_ids" in ROUTES_PY, (
"routes.py must collect config model IDs in _config_ids, not ids (#3718)"
)

def test_live_fetch_not_guarded_by_ids(self):
"""The live fetch must not be guarded by ``if not ids`` for custom providers."""
# The old code had: if not ids and (provider == "custom" ...
# The fix changes it to: if provider == "custom" ...
# Verify the guard ``not ids`` is NOT present before the custom-provider block.
live_fetch_section = ROUTES_PY[ROUTES_PY.find("Always try live fetch for custom providers"):]
assert "if not ids and" not in live_fetch_section.split("OpenAI-compat live fetch fallback")[0], (
"Live fetch for custom providers must not be guarded by 'if not ids' (#3718)"
)

def test_merge_logic_after_live_fetch(self):
"""After the live fetch, config entries must be merged (not replaced)."""
merge_section = ROUTES_PY[ROUTES_PY.find("live fetch succeeded, merge"):]
assert "_live_set = set(ids)" in merge_section, (
"Live fetch results must take priority over config entries (#3718)"
)
assert "ids.append(_cid)" in merge_section, (
"Config entries not already in live results must be appended (#3718)"
)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved