fix: persist resolved context_length after /model switch#36199
Closed
vanhoof wants to merge 1 commit into
Closed
Conversation
After switch_model() clears _config_context_length to None so the new model can resolve its own context window, the display path in cli.py reads None and falls through to the 256K default for custom providers (LiteLLM, vertex-proxy, etc.) that don't match any probing step. The context compressor already resolves the correct value via get_model_context_length() — write it back to _config_context_length so the /model confirmation message shows the actual context window instead of the fallback. Fixes the display for all custom provider setups where the model's context length resolves via DEFAULT_CONTEXT_LENGTHS or live probes rather than config_context_length. Signed-off-by: Chris van Hoof <vanhoof@ouwish.com>
mxnstrexgl
approved these changes
Jun 1, 2026
mxnstrexgl
left a comment
There was a problem hiding this comment.
LGTM — automated review passed. No security, quality, or test coverage issues detected.
Author
|
Superseded by #37712, which fixes the root cause (two additional bugs in the resolution chain that made the persistence here persist the wrong value). |
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
After
switch_model()clears_config_context_lengthtoNone(line 1411) so the new model can resolve its own context window, the display path incli.pyreadsNoneviagetattr(agent, "_config_context_length", None)and falls through every resolution step to the 256K default.This affects all custom provider setups (LiteLLM, vertex-proxy, or any
custom_providers/providersentry) where the model's context length resolves viaDEFAULT_CONTEXT_LENGTHSor live probes rather than an explicitconfig_context_length.Observed behavior:
/modelalways showsContext: 256,000 tokensregardless of the actual model context window, even when switching between 200K and 1M models.Fix
The context compressor already resolves the correct value via
get_model_context_length()during the switch. Write it back toagent._config_context_lengthso the/modelconfirmation message incli.py(and gateway/info) can read the resolved value instead ofNone.7-line change, no new dependencies.
Testing
Manual testing with
providers:config entries pointing at a local proxy (vertex-proxy on port 8788, Anthropic wire protocol). Before fix:/modelalways shows 256K. After fix: shows correct context length per model (1M for claude-opus-4.6, 200K for claude-sonnet-4, etc.).Signed-off-by: Chris van Hoof vanhoof@ouwish.com