diff --git a/cli.py b/cli.py index 4dc546bac4e8..7cc2302fb16d 100644 --- a/cli.py +++ b/cli.py @@ -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") diff --git a/tests/hermes_cli/test_model_switch_context_display.py b/tests/hermes_cli/test_model_switch_context_display.py index cb6275af0930..b30ed9024fdc 100644 --- a/tests/hermes_cli/test_model_switch_context_display.py +++ b/tests/hermes_cli/test_model_switch_context_display.py @@ -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." + )