Skip to content

fix(context): re-probe context length on session reset (#31043)#31492

Open
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/31043-cli-new-context-length-refresh
Open

fix(context): re-probe context length on session reset (#31043)#31492
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/31043-cli-new-context-length-refresh

Conversation

@Tranquil-Flow

Copy link
Copy Markdown
Contributor

What

CLI /new (and /reset) do not refresh context_compressor.context_length after provider config changes. After adjusting LM Studio's context length and reloading the model, /new reuses 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 /new reflects a just-reloaded model instead of a 5-minute-old /api/v1/models response.

  • agent/model_metadata.py — +9: invalidate_endpoint_model_metadata_cache(base_url) public helper
  • agent/context_compressor.py — +26: on_session_reset() re-probes + LM Studio cache invalidation

Why over #31067

A competing PR (#31067) identifies the same endpoint-cache issue, but:

  • Patches cli.py only (not the reset abstraction used by /new and /reset)
  • Imports private model_metadata cache internals directly
  • Recreates ContextCompressor instead of reusing the existing reset hook
  • Has no committed regression tests

This fix is narrower in the runtime reset abstraction and better covered.

Tests

python3 -m pytest tests/agent/test_context_compressor.py -q -o addopts=
87 passed in 25s

4 regression tests: re-probe on reset, no-op when unchanged, probe failure retains stale value, LM Studio cache invalidation.

Closes #31043

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard labels May 24, 2026
@Tranquil-Flow Tranquil-Flow force-pushed the fix/31043-cli-new-context-length-refresh branch from 9026f42 to 7a62780 Compare May 25, 2026 09:12
…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.
@Tranquil-Flow Tranquil-Flow force-pushed the fix/31043-cli-new-context-length-refresh branch from 7a62780 to 5e152aa Compare May 25, 2026 11:02
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 comp/cli CLI entry point, hermes_cli/, setup wizard 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.

[Bug]: CLI /new does not refresh context_compressor.context_length after provider config changes

2 participants