Release: #6148 alias-prefix model routing fix (exp-v0.52.141) (#6418)

* fix: resolve provider alias before matching _PROVIDER_MODELS (#6148)

* fix(backend): resolve model prefix through _PROVIDER_ALIASES before matching

- Fix IndentationError: dedent _canon_prefix assignment to 8 spaces
- Rebased onto upstream/master
- Add regression test: alias prefix (z-ai) resolves to canonical key (zai)
  and routes cross-provider through OpenRouter (#6131)

* fix(#6131): canonicalize both sides via _canonicalise_provider_id (idempotent) + regression tests

Codex found _resolve_provider_alias breaks Qwen (qwen->alibaba, not in _PROVIDER_MODELS)
and cross-routes alias-of-active-provider (raw vs canon asymmetry). Use the idempotent
_canonicalise_provider_id for both membership and equality. Adds 2 regression tests.

* docs(changelog): stamp #6148 alias-prefix model routing fix

---------

Co-authored-by: webtecnica <75556242+webtecnica@users.noreply.github.com>
Co-authored-by: webtecnica <webtecnica@users.noreply.github.com>
Co-authored-by: nesquena-hermes <agent@nesquena-hermes>
Co-authored-by: nesquena-hermes <agent@webui>
This commit is contained in:
nesquena-hermes 2026-07-22 02:51:37 -07:00 committed by GitHub
parent 478f7749ab
commit e9e9ed09a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 63 additions and 1 deletions

View file

@ -19,6 +19,8 @@
### Fixed
- **Alias-prefixed models now route to the right provider.** When you pick a namespaced model whose prefix is a provider *alias* (e.g. `z-ai/glm-5.2`, where `z-ai` is an alias of the canonical `zai`) under a different active provider, the WebUI resolver now canonicalizes the prefix before deciding whether to cross-route through OpenRouter — so it reaches OpenRouter instead of falling back to the stale configured provider (which produced auth/404 failures). The comparison canonicalizes both sides, so a model selected under an alias of its *own* provider is correctly treated as same-provider (not cross-routed), and OpenRouter selections like Qwen/xAI keep routing to OpenRouter. Thanks @webtecnica. (#6148, #6131)
- **Per-model reasoning-effort metadata is now honored by the WebUI reasoning picker.** When resolving which reasoning modes a model exposes, a `models.<model>.reasoning_efforts` list (as Hermes Agent stores under `custom_providers[].models`) now takes precedence over the provider-wide `reasoning_efforts` list, falling back to the provider list and then heuristics. This lets a model with its own declared modes (e.g. an unrecognized custom model) expose them without a provider-wide override. Configs that only set a provider-level list are completely unaffected — output is byte-identical to before. Thanks @CharlesMcquade. (#6107)
- **Stream teardown no longer leaks per-stream runtime state on long-running servers.** When a stream ended, its `STREAM_SESSION_OWNERS` owner mapping and (for gateway turns) the `AGENT_INSTANCES` entry were retained, so a high-volume, long-lived server slowly accumulated dead per-stream bookkeeping. Teardown now unregisters the stream owner and drops the gateway agent instance. The offline-frame buffer is deliberately **not** cleared on teardown so a late reconnect can still replay buffered `token`/`done`/`stream_end` frames; buffers remain bounded (8,192 frames) and channels are reclaimed once outstanding reconnect references exit. Thanks @webtecnica. (#6389, #6351)

View file

@ -2976,7 +2976,13 @@ def resolve_model_provider(model_id: str, *, explicitly_picked: bool = False) ->
# branch (#3872).
_cp_lower_cross = (config_provider or "").strip().lower()
_is_custom_cross = _cp_lower_cross == "custom" or _cp_lower_cross.startswith("custom:")
if prefix in _PROVIDER_MODELS and prefix != config_provider and not _is_custom_cross:
_canon_prefix = _canonicalise_provider_id(prefix)
_canon_config_provider = _canonicalise_provider_id(config_provider)
if (
_canon_prefix in _PROVIDER_MODELS
and _canon_prefix != _canon_config_provider
and not _is_custom_cross
):
return model_id, "openrouter", None
return model_id, config_provider, config_base_url

View file

@ -121,6 +121,60 @@ def test_cross_provider_routes_through_openrouter():
assert base_url is None # openrouter uses its own endpoint
def test_cross_provider_routes_through_openrouter_with_alias_prefix():
"""A model whose prefix is a _PROVIDER_ALIASES entry (not itself a
_PROVIDER_MODELS key) but resolves to a canonical provider key still
routes through the cross-provider OpenRouter branch.
Regression test for #6131 — before the fix, ``z-ai/glm-5.2`` with
config provider ``anthropic`` would fall through and return the stale
config provider because ``z-ai`` was checked directly against
``_PROVIDER_MODELS`` instead of being resolved through
``_PROVIDER_ALIASES`` first.
"""
model, provider, base_url = _resolve_with_config(
'z-ai/glm-5.2', provider='anthropic',
)
assert model == 'z-ai/glm-5.2'
assert provider == 'openrouter'
assert base_url is None # openrouter uses its own endpoint
def test_cross_provider_openrouter_qwen_selection_not_stale_routed():
"""An OpenRouter Qwen selection under a different config provider must
still route through openrouter — NOT inherit the stale config provider.
Regression guard for #6131's fix: ``qwen`` canonicalises to ``qwen``
(a _PROVIDER_MODELS key), but its hermes_cli *alias* target is
``alibaba`` (NOT a _PROVIDER_MODELS key). An earlier fix that resolved
through _PROVIDER_ALIASES instead of the idempotent
_canonicalise_provider_id would have mapped ``qwen`` → ``alibaba``,
missed the membership check, and wrongly returned the stale provider.
"""
model, provider, base_url = _resolve_with_config(
'qwen/qwen3-max', provider='anthropic',
)
assert model == 'qwen/qwen3-max'
assert provider == 'openrouter'
assert base_url is None
def test_alias_prefix_matching_active_provider_not_cross_routed():
"""A namespaced model whose prefix is an *alias of its own active
provider* must NOT be cross-routed to openrouter.
``z-ai/glm-5.2`` under provider ``zai`` — the prefix ``z-ai`` and the
config provider ``zai`` canonicalise to the SAME id (``zai``), so this
is a same-provider selection, not a cross-provider one. The fix compares
canonical prefix against canonical config provider (not the raw prefix)
so the inequality guard correctly suppresses the openrouter cross-route.
"""
model, provider, base_url = _resolve_with_config(
'z-ai/glm-5.2', provider='zai',
)
assert provider != 'openrouter'
# ── Bare model names ─────────────────────────────────────────────────────
def test_bare_model_uses_config_provider():