fix(gateway): read nested per-model context_length in session info banner#14382
Open
pinch-claw wants to merge 1 commit into
Open
fix(gateway): read nested per-model context_length in session info banner#14382pinch-claw wants to merge 1 commit into
pinch-claw wants to merge 1 commit into
Conversation
e102354 to
c47e863
Compare
…nner The session-reset / info banner in `_format_session_info` resolved the context window only from the top-level `model.context_length` key. When users configured context_length under the new `providers.<name>.models.<model>` dict schema (or the legacy `custom_providers[].models.<model>` list schema), the banner fell through to `get_model_context_length()`'s probe chain. Remote OpenAI-compatible proxies frequently omit `context_length` from `/models` responses, so the probe failed silently and the banner displayed `128K tokens (default — set model.context_length in config to override)` — even though the runtime `ContextCompressor` was already budgeting with the correct value resolved by `AIAgent.__init__`. After the top-level lookup, walk `get_compatible_custom_providers(cfg)`, match the entry by `base_url` against the resolved runtime base_url, and read `entry["models"][model]["context_length"]`. This mirrors the exact resolution `AIAgent.__init__` performs at `run_agent.py:1608-1643` so the banner's displayed value matches what the compressor actually uses. Fixes NousResearch#5089. Relationship to existing open PRs (NousResearch/hermes-agent): - NousResearch#5096, NousResearch#8240, NousResearch#10690: each hand-roll traversal of the legacy `custom_providers:` list only. They do not cover the newer `providers:` dict schema users land on via `hermes model`. - NousResearch#12380: touches `/model` display + gateway fallback paths; overlaps in spirit but still traverses lists manually. Routing through `get_compatible_custom_providers()` — the existing compat shim at `hermes_cli/config.py:2078` — gives a single lookup that covers both schemas and stays consistent with every other runtime caller, eliminating future drift between display and compressor.
c47e863 to
6d54494
Compare
Collaborator
Collaborator
This was referenced Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5089 (also partially addresses concerns raised in #2513, #12977 for the banner-display path).
The session-reset / info banner in
_format_session_info(gateway/run.py) resolved the context window only from the top-levelmodel.context_lengthkey. When users configure context_length under either the newerproviders.<name>.models.<model>dict schema or the legacycustom_providers[].models.<model>list schema, the banner fell through toget_model_context_length()'s probe chain. Remote OpenAI-compatible proxies frequently omitcontext_lengthfrom/modelsresponses, so the probe failed silently and the banner displayed:— even though the runtime
ContextCompressorwas already budgeting with the correct value (resolved byAIAgent.__init__atrun_agent.py:1608-1643). A display-vs-truth inconsistency rather than a functional bug, but confusing and repeatedly reported (#5089, #2513).Fix
After the existing top-level lookup, walk
get_compatible_custom_providers(cfg), match the entry bybase_urlagainst the resolved runtime base_url, and readentry["models"][model]["context_length"]. Pass that through toget_model_context_length()asconfig_context_length; step 0 short-circuits the probe.This mirrors the exact resolution
AIAgent.__init__already performs, so the banner's displayed value matches what the compressor actually uses.Why this is an improvement over existing open PRs
Four other open PRs target #5089:
custom_providers:list only. They do not cover the newerproviders:dict schema that users land on viahermes model(and whichconfig.yamltemplates now use)./modeldisplay + gateway fallback paths) but still traverses lists manually.This PR routes through
get_compatible_custom_providers()— the existing compat shim athermes_cli/config.py:2078that already bridges both schemas for the rest of the runtime. One lookup, both schemas, stays consistent withAIAgent.__init__, and eliminates future drift between the banner and the compressor.Reproduction
~/.hermes/config.yaml(new-schema form — the legacy list form reproduces identically):Restart gateway, trigger
/reset:◆ Context: 128K tokens (default — set model.context_length in config to override)◆ Context: 262K tokens (config)Verification
Simulated the patched block against a real-world config (exact code shape of the fix, not a standalone re-implementation):
No functional change to the compressor or any runtime code path — this only affects what
_format_session_infodisplays.Test plan
tests/gateway/test_session_info.pystill pass.providers:config → banner shows nested context_length.custom_providers:list config → banner shows nested context_length (unchanged behavior vs fix(gateway): honor custom provider context length #5096 et al).