fix(tui): /model picker switch doesn't survive between jcode relaunches or new sessions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 19.9k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 30
Description
Problem
After switching a model in /model (via Ctrl+Tab/Ctrl+Shift+Tab or /model <name>), the selection does not survive between jcode relaunches or across new sessions. The model reverts to the config.toml [provider].default_model value on the next launch.
Root cause
The TUI model picker's finalize_model_switch() only persists the model to the session file (session.save()), not to config.toml. So:
- A resumed session restores the model from the session file (works).
- A new session or relaunch reads
config.toml's[provider].default_model→ reverts to the old default (bug).
This is especially visible for user-defined named OpenAI-compatible providers ([providers.<name>]) with model_catalog = false, where the /model list comes from config's [[providers.<name>.models]] entries loaded fresh on every launch.
Why the inline-interactive picker was already correct
The inline-interactive model picker (/model browse UI) already calls Config::set_default_model() to persist the selection to config.toml. Only the direct paths (cycle_model and /model <name>) missed this call.
Fix
Add persist_model_switch_to_config() which writes the active model + provider key to config.toml via Config::set_default_model, and call it from the two user-initiated switch paths (cycle_model, /model <name>). Failover- and auth-driven switches deliberately do NOT persist, so they cannot override the user's configured default.
Files changed (4 files, +192/-1)
| File | Summary |
|---|---|
crates/jcode-tui/src/tui/app/model_context.rs |
New persist_model_switch_to_config() helper; called after finalize_model_switch in cycle_model and /model <name> paths |
crates/jcode-tui/src/tui/app/tests/model_persist_config.rs |
Two end-to-end regression tests |
crates/jcode-tui/src/tui/app/tests.rs |
Include new test file |
crates/jcode-tui/src/tui/ui_tests/mod.rs |
Fix pre-existing mcp_servers trait signature mismatch |
Regression tests (both pass)
cycle_model_persists_switch_to_config_toml— Writesconfig.tomlwithdefault_model = "model-a", creates a mock provider withavailable_models = ["model-a", "model-b"], cycles forward (a→b) and backward (b→a), readsconfig.tomlback from disk and assertsdefault_modelmatches.model_command_persists_switch_to_config_toml— Same setup, uses/model model-bcommand path (handle_model_command), assertsconfig.toml'sdefault_modelis updated tomodel-b.
test tui::app::tests::cycle_model_persists_switch_to_config_toml ... ok
test tui::app::tests::model_command_persists_switch_to_config_toml ... ok
The tests verify the full end-to-end path: user-initiated switch → finalize_model_switch (session save) → persist_model_switch_to_config → Config::set_default_model → config.toml on disk → reload via Config::load() → assert persisted model matches.
Branch
Branch: https://github.com/alecuba16/jcode/tree/fix/model-persist-config
Commit: 9756b080
Single commit containing both the fix and the regression tests.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in crates/jcode-tui/src/tui/app/model_context.rs and inspect the model switch paths, then read crates/jcode-tui/src/tui/app/tests/model_persist_config.rs and its inclusion in tests.rs. Run the two named regression tests; done means user-initiated model changes persist in config.toml across reloads without persisting failover or auth-driven switches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100