fix(vscode): restore per-mode model memory to match CLI TUI behavior#9146
Merged
fix(vscode): restore per-mode model memory to match CLI TUI behavior#9146
Conversation
Persist per-mode model selections to the CLI's model.json so switching modes restores the previously chosen model, matching CLI TUI behavior.
Contributor
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Fix these issues in Kilo Cloud Issue Details (click to expand)No new issues found in the incremental diff. Other Observations (not in diff)Issues found in unchanged code that cannot receive inline comments:
Files Reviewed (5 files)
Reviewed by gpt-5.4-20260305 · 1,481,964 tokens |
…lace semantics Serialize model.json writes through a promise chain to prevent concurrent read-modify-write races from losing data. Use reconcile() for modelSelectionsLoaded so a reset (empty payload) clears stale entries instead of leaving them in memory.
…lections Fix session-model-store.ts applyModel() to match the session.tsx fix (always write to modelSelections, not just sessionOverrides). Update existing tests for new behavior and add tests for mode-switch restore, independent per-mode tracking, and validateModelSelections edge cases.
Move model.json read/write and message handling into kilo-provider/model-state.ts to keep KiloProvider within its max-lines (3353) and complexity (140) ESLint limits.
lambertjosh
approved these changes
Apr 20, 2026
Contributor
lambertjosh
left a comment
There was a problem hiding this comment.
Approved from my POV, but please update docs along with this change.
Add missing behavior to model-selection.md VSCode tab: 'last picked per agent' level in precedence chain, and a note that the model selector remembers picks across sessions with reset button to restore config. Add the same note to custom-modes.md for both the VSCode and CLI tabs under the model property reference (previously only documented in the VSCode Legacy tab as 'Sticky Models').
Contributor
Author
Done, ty |
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.
Summary
The CLI TUI remembers which model you last picked for each mode (code/ask/plan) and restores it when you switch back. The VS Code extension did not — model selections were lost on mode switch and webview reload. This PR brings the extension to parity with the CLI by reading and writing the same
~/.local/state/kilo/model.jsonfile.What was broken
When a session was active,
applyModel()only wrote the model choice to a per-session override. Switching modes cleared that override, and the selection was gone. There was also no persistence — even the in-memory per-mode map was lost on webview reload.How it works now
model.json), regardless of whether a session is active.model.jsonso choices survive restarts.model.jsonthe CLI TUI uses, so picks made in either client are visible to the other.Model resolution priority (unchanged)
This PR does not change the resolution order. Both CLI and extension use:
model.json)agent.code.model)modelin configkilo-auto/freeThe user override takes precedence over config. The reset button (visible when the model differs from config default) clears the override so the config setting takes effect again.
Trade-off: no opencode changes
The per-mode model persistence is a Kilo-specific feature implemented in the TUI client layer (
local.tsx), not in the server. The cleanest fix would add a shared module inpackages/opencode/with server routes so both TUI and extension call the same code. We opted for direct file I/O from the extension host instead — the duplicated logic is trivially small (JSON read-modify-write on one key) and this avoids server route additions, SDK regeneration, and upstream diff churn.