Skip to content

fix(agent): clear stale config context_length on model switch#24724

Merged
teknium1 merged 1 commit into
mainfrom
salvage/pr-22387
May 13, 2026
Merged

fix(agent): clear stale config context_length on model switch#24724
teknium1 merged 1 commit into
mainfrom
salvage/pr-22387

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #22387 by @AgentArcLab onto current main.

self._config_context_length is set once in __init__ from config and read in fallback/switch paths but was never cleared on model switch. After switching to a model with a different context window, the old value would persist and cause incorrect compression decisions. Clear it on switch.

When switching models via /model, AIAgent._config_context_length was
never cleared, so the new model inherited the previous model's context
window instead of auto-detecting the correct one via
get_model_context_length().

Clear _config_context_length to None before the runtime field swap so
the full resolution chain (custom_providers per-model, endpoint probe,
models.dev, etc.) is re-evaluated for the newly selected model.

Closes #21509
@teknium1 teknium1 merged commit 8ac3514 into main May 13, 2026
@teknium1 teknium1 deleted the salvage/pr-22387 branch May 13, 2026 01:50
@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 labels May 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/pr-22387 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8252 on HEAD, 8252 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4338 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

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