fix(agent): preserve global model.context_length through switch_model and fallback - #32413
Open
TF0rd wants to merge 1 commit into
Open
fix(agent): preserve global model.context_length through switch_model and fallback#32413TF0rd wants to merge 1 commit into
TF0rd wants to merge 1 commit into
Conversation
TF0rd
force-pushed
the
fix/preserve-global-context-length
branch
from
May 26, 2026 04:52
df6ebfa to
ac51419
Compare
… and fallback Both switch_model() and try_activate_fallback() unconditionally set agent._config_context_length = None before passing it to get_model_context_length(). This discards the global model.context_length from config.yaml, causing the context window to fall through to the 256K probe-down default even when the user has explicitly configured a larger value (e.g. 1048576). Fix: before clearing _config_context_length, re-read the global model.context_length from config.yaml and pass it to get_model_context_length(). The per-model override is still cleared (so switching from model A with a custom_providers per-model override to model B doesn't inherit A's value), but the global setting — which applies to all models — is preserved. Also consolidates the config load in switch_model() that was previously duplicated: once at the top (new) for the global context_length, and once in the compressor block (removed) for custom_providers. Both now share a single load_config() call.
TF0rd
force-pushed
the
fix/preserve-global-context-length
branch
from
May 26, 2026 04:53
ac51419 to
5e4e78c
Compare
Contributor
|
Thanks for identifying the lost global override. The premise is confirmed on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
This was referenced Jul 31, 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.
Problem
Both
switch_model()andtry_activate_fallback()unconditionally setagent._config_context_length = Nonebefore passing it toget_model_context_length(). This discards the globalmodel.context_lengthfrom config.yaml, causing the context window to fall through to the 256K probe-down default even when the user has explicitly configured a larger value (e.g. 1048576).The clearing was intended to prevent inheriting a stale per-model custom_providers override when switching models — but it also nukes the global config setting, which applies to ALL models.
Fix
Before clearing
_config_context_length, re-read the globalmodel.context_lengthfrom config.yaml and pass it toget_model_context_length(). The per-model override is still cleared (correct behavior), but the global setting is preserved.Also consolidates the config load in
switch_model()that was previously duplicated — once for the global context_length and once for custom_providers. Both now share a singleload_config()call.Files Changed
agent/agent_runtime_helpers.py—switch_model(): preserve global context_length, deduplicate config loadagent/chat_completion_helpers.py—try_activate_fallback(): same fixTesting
test_custom_provider_context_length,test_model_switch_context_display,test_session_info(28/28)model.context_length: 1048576in config