fix(context): re-probe context length on session reset (#31043)#31492
Open
Tranquil-Flow wants to merge 2 commits into
Open
fix(context): re-probe context length on session reset (#31043)#31492Tranquil-Flow wants to merge 2 commits into
Tranquil-Flow wants to merge 2 commits into
Conversation
9026f42 to
7a62780
Compare
…31043) CLI /new and /reset slash commands reuse the existing ContextCompressor but on_session_reset() only cleared internal flags without re-probing the provider-side context length. When a local model's context window was adjusted (e.g. in LM Studio), the CLI status bar displayed the stale value until process restart — the gateway path was unaffected because it creates a fresh ContextCompressor on /new. Add a re-probe call after the state reset: if the provider now reports a different context length, update_model() recalibrates threshold, tail budget, and summary cap. Probe failures are caught silently so a temporary network blip doesn't zero out the stored value.
7a62780 to
5e152aa
Compare
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.
What
CLI
/new(and/reset) do not refreshcontext_compressor.context_lengthafter provider config changes. After adjusting LM Studio's context length and reloading the model,/newreuses the stale cached value — the agent operates with the wrong context budget.Fix
ContextCompressor.on_session_reset()now re-probes context length from the provider. For LM Studio specifically, it invalidates the short-lived endpoint metadata cache before probing, so/newreflects a just-reloaded model instead of a 5-minute-old/api/v1/modelsresponse.agent/model_metadata.py— +9:invalidate_endpoint_model_metadata_cache(base_url)public helperagent/context_compressor.py— +26:on_session_reset()re-probes + LM Studio cache invalidationWhy over #31067
A competing PR (#31067) identifies the same endpoint-cache issue, but:
cli.pyonly (not the reset abstraction used by/newand/reset)ContextCompressorinstead of reusing the existing reset hookThis fix is narrower in the runtime reset abstraction and better covered.
Tests
4 regression tests: re-probe on reset, no-op when unchanged, probe failure retains stale value, LM Studio cache invalidation.
Closes #31043