fix(cli): pass custom_providers to resolve_display_context_length (#59314)

The CLI model-switch display (both picker and direct-switch paths)
omitted the custom_providers keyword when calling
resolve_display_context_length(). The function already supports it
(and the gateway correctly passes it), but the CLI call sites relied
on the fallthrough to probe-down default (256K) even when a
custom_providers entry specified a per-model context_length.

Fix: pass agent._custom_providers at both resolve_display_context_length
call sites in HermesCLI._apply_model_switch_result(), matching the
pattern already used for config_context_length.
This commit is contained in:
Tranquil-Flow 2026-07-06 10:12:57 +02:00 committed by Teknium
parent b5158442f0
commit 9d848cc60a
2 changed files with 29 additions and 0 deletions

2
cli.py
View file

@ -7844,6 +7844,7 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin):
api_key=result.api_key or self.api_key or "",
model_info=mi,
config_context_length=getattr(self.agent, "_config_context_length", None) if self.agent else None,
custom_providers=getattr(self.agent, "_custom_providers", None) if self.agent else None,
)
if ctx:
_cprint(f" Context: {ctx:,} tokens")
@ -8152,6 +8153,7 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin):
api_key=result.api_key or self.api_key or "",
model_info=mi,
config_context_length=getattr(self.agent, "_config_context_length", None) if self.agent else None,
custom_providers=getattr(self.agent, "_custom_providers", None) if self.agent else None,
)
if ctx:
_cprint(f" Context: {ctx:,} tokens")

View file

@ -146,3 +146,30 @@ class TestResolveDisplayContextLength:
custom_providers=custom_provs,
)
assert ctx == 400_000
def test_without_custom_providers_returns_default_fallback(self):
"""Regression for #59314: When custom_providers is NOT passed
(the bug pre-fix), a custom provider model falls through to
probe-down default (256K) instead of the configured per-model
context_length."""
from unittest.mock import patch as _p
from agent import model_metadata as _mm
with _p.object(_mm, "get_cached_context_length", return_value=None), \
_p.object(_mm, "fetch_endpoint_model_metadata", return_value={}), \
_p.object(_mm, "fetch_model_metadata", return_value={}), \
_p.object(_mm, "is_local_endpoint", return_value=False), \
_p.object(_mm, "_is_known_provider_base_url", return_value=False):
# Without custom_providers, the function probes and gets default
ctx = resolve_display_context_length(
"test-model-unconfigured",
"custom",
base_url="https://example.invalid/v1",
api_key="k",
model_info=None,
)
# Without custom_providers, the function falls to probe-down default
assert ctx == 256_000, (
"Without custom_providers, an un-cached model gets 256K default. "
"The fix ensures custom_providers is passed so per-model overrides "
"are honored."
)