1jehuang / 1jehuang/jcode

fix(tui): /model picker switch doesn't survive between jcode relaunches or new sessions

Open
#608 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug from-pr priority: medium triage: needs-decision
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 — Writes config.toml with default_model = "model-a", creates a mock provider with available_models = ["model-a", "model-b"], cycles forward (a→b) and backward (b→a), reads config.toml back from disk and asserts default_model matches.
  • model_command_persists_switch_to_config_toml — Same setup, uses /model model-b command path (handle_model_command), asserts config.toml's default_model is updated to model-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_configConfig::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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.