Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions crates/tui/src/commands/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn load(app: &mut App, path: Option<&str>) -> CommandResult {
app.extend_history(cells_to_add);
app.mark_history_updated();
app.viewport.transcript_selection.clear();
app.model.clone_from(&session.metadata.model);
app.set_model_selection(session.metadata.model.clone());
app.update_model_compaction_budget();
app.workspace.clone_from(&session.metadata.workspace);
app.session.total_tokens = u32::try_from(session.metadata.total_tokens).unwrap_or(u32::MAX);
Expand Down Expand Up @@ -355,8 +355,8 @@ fn line_to_string(line: ratatui::text::Line<'static>) -> String {
#[cfg(test)]
mod tests {
use super::*;
use crate::config::Config;
use crate::tui::app::{App, TuiOptions, TurnCacheRecord};
use crate::config::{Config, DEFAULT_TEXT_MODEL};
use crate::tui::app::{App, ReasoningEffort, TuiOptions, TurnCacheRecord};
use std::time::Instant;
use tempfile::TempDir;

Expand Down Expand Up @@ -565,6 +565,31 @@ mod tests {
assert!(matches!(result.action, Some(AppAction::SyncSession { .. })));
}

#[test]
fn load_auto_model_session_restores_auto_mode() {
let tmpdir = TempDir::new().unwrap();
let mut saved_app = create_test_app_with_tmpdir(&tmpdir);
saved_app.set_model_selection("auto".to_string());
saved_app.last_effective_model = Some("deepseek-v4-flash".to_string());
saved_app.last_effective_reasoning_effort = Some(ReasoningEffort::Low);
let save_path = tmpdir.path().join("auto_model.json");
save(&mut saved_app, Some(save_path.to_str().unwrap()));

let mut app = create_test_app_with_tmpdir(&tmpdir);
app.set_model_selection("deepseek-v4-flash".to_string());
app.reasoning_effort = ReasoningEffort::High;
let result = load(&mut app, Some(save_path.to_str().unwrap()));

assert!(!result.is_error);
assert!(app.auto_model);
assert_eq!(app.model, "auto");
assert_eq!(app.model_selection_for_persistence(), "auto");
assert_eq!(app.last_effective_model, None);
assert_eq!(app.last_effective_reasoning_effort, None);
assert_eq!(app.reasoning_effort, ReasoningEffort::Auto);
assert_eq!(app.effective_model_for_budget(), DEFAULT_TEXT_MODEL);
}

#[test]
fn load_restores_artifact_registry() {
let tmpdir = TempDir::new().unwrap();
Expand Down
4 changes: 4 additions & 0 deletions crates/tui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4161,6 +4161,10 @@ impl App {
};
self.auto_model = auto_model;
self.last_effective_model = None;
self.last_effective_reasoning_effort = None;
if auto_model {
self.reasoning_effort = ReasoningEffort::Auto;
}
}

pub fn model_selection_for_persistence(&self) -> String {
Expand Down
9 changes: 8 additions & 1 deletion crates/tui/src/tui/ui/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::config::{ApiProvider, Config};
use crate::config::{ApiProvider, Config, DEFAULT_TEXT_MODEL};
use crate::config_ui::{self, WebConfigSession, WebConfigSessionEvent};
use crate::core::engine::mock_engine_handle;
use crate::tui::active_cell::ActiveCell;
Expand Down Expand Up @@ -3956,6 +3956,9 @@ fn apply_loaded_session_restores_concrete_model_mode() {
fn apply_loaded_session_restores_auto_model_mode() {
let mut app = create_test_app();
app.set_model_selection("deepseek-v4-pro".to_string());
app.reasoning_effort = ReasoningEffort::High;
app.last_effective_model = Some("deepseek-v4-flash".to_string());
app.last_effective_reasoning_effort = Some(ReasoningEffort::Low);
let mut session = saved_session_with_messages(vec![
text_message("user", "hello"),
text_message("assistant", "hi"),
Expand All @@ -3968,6 +3971,10 @@ fn apply_loaded_session_restores_auto_model_mode() {
assert!(app.auto_model);
assert_eq!(app.model, "auto");
assert_eq!(app.model_selection_for_persistence(), "auto");
assert_eq!(app.last_effective_model, None);
assert_eq!(app.last_effective_reasoning_effort, None);
assert_eq!(app.reasoning_effort, ReasoningEffort::Auto);
assert_eq!(app.effective_model_for_budget(), DEFAULT_TEXT_MODEL);
}

#[test]
Expand Down