Skip to content

fix: persist resolved context_length after /model switch#36199

Closed
vanhoof wants to merge 1 commit into
NousResearch:mainfrom
vanhoof:fix/model-switch-context-length-display
Closed

fix: persist resolved context_length after /model switch#36199
vanhoof wants to merge 1 commit into
NousResearch:mainfrom
vanhoof:fix/model-switch-context-length-display

Conversation

@vanhoof

@vanhoof vanhoof commented Jun 1, 2026

Copy link
Copy Markdown

Problem

After switch_model() clears _config_context_length to None (line 1411) so the new model can resolve its own context window, the display path in cli.py reads None via getattr(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/providers entry) where the model's context length resolves via DEFAULT_CONTEXT_LENGTHS or live probes rather than an explicit config_context_length.

Observed behavior: /model always shows Context: 256,000 tokens regardless 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 to agent._config_context_length so the /model confirmation message in cli.py (and gateway /info) can read the resolved value instead of None.

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: /model always 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

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>
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists labels Jun 1, 2026

@mxnstrexgl mxnstrexgl left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — automated review passed. No security, quality, or test coverage issues detected.

@vanhoof

vanhoof commented Jun 2, 2026

Copy link
Copy Markdown
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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants