mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Allow session-only model and reasoning selection in the TUI (#45831)
## Why Users need to change the active session's model and reasoning effort without replacing saved defaults for future threads. ## What changed - Add an `s` shortcut to final model and reasoning choices, with footer hints and a session-only confirmation. - Apply the selection to the active thread while preserving saved configuration, including separate Plan mode defaults. - Restore Plan mode reasoning effort with thread input state and suppress the shortcut when it conflicts with configured list bindings. ## Testing Add coverage for picker shortcuts, active-thread updates, unchanged configuration and fresh-thread defaults, Plan mode restoration, and shortcut conflicts. Update picker snapshots to show the new hints. GitOrigin-RevId: 07fd129021cc076e3a9bdee04b71979212788eb4
This commit is contained in:
1 parent
ca99b271d4
commit
0dfb28edb9
22 files changed
+465
-29
No files matched your search
@@ -2131,6 +2131,9 @@ impl App {
|
||||
}
|
||||
}
|
||||
}
|
||||
AppEvent::SelectSessionModel { model, effort } => {
|
||||
self.select_session_model(app_server, model, effort).await;
|
||||
}
|
||||
AppEvent::CyberModelAutoReviewNotice => {
|
||||
self.chat_widget.add_warning_message(
|
||||
"Cyber models default to \"Approve for me\" for safety reasons.".to_string(),
|
||||
|
||||
@@ -1,15 +1,73 @@
|
||||
//! Saved model-default feedback, independent of active thread settings.
|
||||
//! Apply session model choices separately from saved model defaults.
|
||||
//!
|
||||
//! A successful config write can still be overridden. Report that distinction without
|
||||
//! replacing the active task's explicit selection with launch-time configuration.
|
||||
|
||||
use super::App;
|
||||
use crate::app_server_session::AppServerSession;
|
||||
use codex_app_server_client::AppServerRequestHandle;
|
||||
use codex_app_server_protocol::ConfigEdit;
|
||||
use codex_app_server_protocol::WriteStatus;
|
||||
use codex_protocol::config_types::ModeKind;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use color_eyre::eyre::Result;
|
||||
|
||||
impl App {
|
||||
pub(super) async fn select_session_model(
|
||||
&mut self,
|
||||
app_server: &mut AppServerSession,
|
||||
model: String,
|
||||
effort: Option<ReasoningEffort>,
|
||||
) {
|
||||
let model_changed = self.chat_widget.current_model() != model
|
||||
|| self.chat_widget.current_collaboration_mode().model() != model;
|
||||
if model_changed
|
||||
&& self
|
||||
.active_thread_model_setting_update_params(model.clone())
|
||||
.is_some_and(|params| params.permissions.is_some())
|
||||
&& self.reject_pending_permission_change()
|
||||
{
|
||||
return;
|
||||
}
|
||||
let in_plan_mode = self.chat_widget.effective_collaboration_mode().mode == ModeKind::Plan;
|
||||
let ultra = effort == Some(ReasoningEffort::Ultra);
|
||||
let clear_default_ultra = self
|
||||
.chat_widget
|
||||
.current_collaboration_mode()
|
||||
.reasoning_effort()
|
||||
== Some(ReasoningEffort::Ultra)
|
||||
&& self.config.model_reasoning_effort != Some(ReasoningEffort::Ultra);
|
||||
let clear_plan_ultra = self.chat_widget.config_ref().plan_mode_reasoning_effort
|
||||
== Some(ReasoningEffort::Ultra)
|
||||
&& self.config.plan_mode_reasoning_effort != Some(ReasoningEffort::Ultra);
|
||||
self.chat_widget.set_model(&model);
|
||||
if !in_plan_mode || ultra || clear_default_ultra {
|
||||
self.chat_widget.set_reasoning_effort(effort.clone());
|
||||
}
|
||||
if in_plan_mode || ultra || clear_plan_ultra {
|
||||
self.chat_widget
|
||||
.set_plan_mode_reasoning_effort(effort.clone());
|
||||
}
|
||||
if model_changed {
|
||||
self.sync_active_thread_model_setting(app_server, model.clone(), effort.clone())
|
||||
.await;
|
||||
} else if let Some(mut params) =
|
||||
self.active_thread_reasoning_setting_update_params(effort.clone())
|
||||
{
|
||||
params.collaboration_mode = Some(self.chat_widget.effective_collaboration_mode());
|
||||
self.send_thread_settings_update(app_server, params).await;
|
||||
}
|
||||
self.sync_active_thread_service_tier_to_cached_session()
|
||||
.await;
|
||||
let mut message = format!("Model changed to {model}");
|
||||
if let Some(label) = Self::reasoning_label_for(&model, effort.as_ref()) {
|
||||
message.push(' ');
|
||||
message.push_str(&label);
|
||||
}
|
||||
message.push_str(" for this session only");
|
||||
self.chat_widget.add_info_message(message, /*hint*/ None);
|
||||
}
|
||||
|
||||
pub(super) async fn persist_model_defaults(
|
||||
&mut self,
|
||||
request_handle: AppServerRequestHandle,
|
||||
|
||||
@@ -1789,6 +1789,8 @@ async fn replay_thread_snapshot_restores_collaboration_mode_without_input() {
|
||||
reasoning_effort: Some(Some(ReasoningEffortConfig::High)),
|
||||
developer_instructions: None,
|
||||
});
|
||||
app.chat_widget
|
||||
.set_plan_mode_reasoning_effort(Some(ReasoningEffortConfig::High));
|
||||
let input_state = app
|
||||
.chat_widget
|
||||
.capture_thread_input_state()
|
||||
@@ -1796,6 +1798,8 @@ async fn replay_thread_snapshot_restores_collaboration_mode_without_input() {
|
||||
|
||||
let (chat_widget, _app_event_tx, _rx, _new_op_rx) = make_chatwidget_manual_with_sender().await;
|
||||
app.chat_widget = chat_widget;
|
||||
app.chat_widget
|
||||
.set_plan_mode_reasoning_effort(Some(ReasoningEffortConfig::Low));
|
||||
app.chat_widget.handle_thread_session(session.clone());
|
||||
app.chat_widget
|
||||
.set_reasoning_effort(Some(ReasoningEffortConfig::Low));
|
||||
@@ -1829,6 +1833,14 @@ async fn replay_thread_snapshot_restores_collaboration_mode_without_input() {
|
||||
app.chat_widget.current_reasoning_effort(),
|
||||
Some(ReasoningEffortConfig::High)
|
||||
);
|
||||
for _ in 0..2 {
|
||||
app.chat_widget
|
||||
.handle_key_event(KeyEvent::from(KeyCode::BackTab));
|
||||
}
|
||||
assert_eq!(
|
||||
app.chat_widget.current_reasoning_effort(),
|
||||
Some(ReasoningEffortConfig::High)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -8949,8 +8961,25 @@ async fn changing_cyber_model_reasoning_preserves_selected_permissions() {
|
||||
.expect("primary thread should be registered");
|
||||
|
||||
let mut tui = crate::tui::test_support::make_test_tui().expect("test tui");
|
||||
for effort in [ReasoningEffortConfig::High, ReasoningEffortConfig::Ultra] {
|
||||
if effort == ReasoningEffortConfig::Ultra {
|
||||
for (effort, session_only) in [
|
||||
(ReasoningEffortConfig::High, false),
|
||||
(ReasoningEffortConfig::Medium, true),
|
||||
(ReasoningEffortConfig::Ultra, false),
|
||||
(ReasoningEffortConfig::High, true),
|
||||
(ReasoningEffortConfig::Ultra, true),
|
||||
] {
|
||||
if session_only {
|
||||
app.handle_event(
|
||||
&mut tui,
|
||||
&mut app_server,
|
||||
AppEvent::SelectSessionModel {
|
||||
model: model_name.clone(),
|
||||
effort: Some(effort.clone()),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("session-only reasoning selection should succeed");
|
||||
} else if effort == ReasoningEffortConfig::Ultra {
|
||||
app.chat_widget
|
||||
.set_feature_enabled(Feature::CollaborationModes, /*enabled*/ true);
|
||||
app.chat_widget
|
||||
|
||||
@@ -1,8 +1,88 @@
|
||||
use super::*;
|
||||
use crate::collaboration_modes;
|
||||
use codex_app_server_client::AppServerClient;
|
||||
use codex_config::LoaderOverrides;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn session_model_selection_preserves_defaults_and_updates_active_thread() -> Result<()> {
|
||||
for mode in [ModeKind::Default, ModeKind::Plan] {
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
app.config.model = Some("gpt-5.5".into());
|
||||
app.config.model_reasoning_effort = Some(ReasoningEffortConfig::Medium);
|
||||
app.config.plan_mode_reasoning_effort = Some(ReasoningEffortConfig::Low);
|
||||
let config_path = app.config.codex_home.join("config.toml");
|
||||
let original = "# My defaults\nmodel = 'gpt-5.5'\nmodel_reasoning_effort = 'medium'\nplan_mode_reasoning_effort = 'low'\n";
|
||||
std::fs::write(&config_path, original)?;
|
||||
let mut server = Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
|
||||
let started = server.start_thread(&app.config).await?;
|
||||
let thread_id = started.session.thread_id;
|
||||
app.enqueue_primary_thread_session(started.session, started.turns)
|
||||
.await?;
|
||||
app.chat_widget
|
||||
.set_feature_enabled(Feature::CollaborationModes, /*enabled*/ true);
|
||||
if mode == ModeKind::Plan {
|
||||
let mask = collaboration_modes::plan_mask(app.model_catalog.as_ref()).unwrap();
|
||||
app.chat_widget.set_collaboration_mask(mask);
|
||||
}
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
for effort in [
|
||||
ReasoningEffortConfig::High,
|
||||
ReasoningEffortConfig::Ultra,
|
||||
ReasoningEffortConfig::Max,
|
||||
] {
|
||||
while events.try_recv().is_ok() {}
|
||||
Box::pin(app.handle_event(
|
||||
&mut tui,
|
||||
&mut server,
|
||||
AppEvent::SelectSessionModel {
|
||||
model: "gpt-5.6-terra".into(),
|
||||
effort: Some(effort.clone()),
|
||||
},
|
||||
))
|
||||
.await?;
|
||||
let settings = next_thread_settings_updated(&mut server, thread_id).await;
|
||||
assert_eq!(
|
||||
(
|
||||
settings.thread_settings.model.as_str(),
|
||||
settings.thread_settings.effort.clone()
|
||||
),
|
||||
("gpt-5.6-terra", Some(effort.clone()))
|
||||
);
|
||||
if mode == ModeKind::Default && effort == ReasoningEffortConfig::High {
|
||||
insta::assert_snapshot!(
|
||||
"session_only_model_confirmation",
|
||||
next_history_message(&mut events)
|
||||
);
|
||||
}
|
||||
app.enqueue_thread_notification(
|
||||
thread_id,
|
||||
ServerNotification::ThreadSettingsUpdated(settings),
|
||||
)
|
||||
.await?;
|
||||
assert_eq!(
|
||||
(
|
||||
app.chat_widget.current_model(),
|
||||
app.chat_widget.current_reasoning_effort()
|
||||
),
|
||||
("gpt-5.6-terra", Some(effort))
|
||||
);
|
||||
assert_eq!(std::fs::read(&config_path)?, original.as_bytes());
|
||||
}
|
||||
let fresh = server.start_thread(&app.config).await?;
|
||||
assert_eq!(
|
||||
(fresh.session.model.as_str(), fresh.session.reasoning_effort),
|
||||
("gpt-5.5", Some(ReasoningEffortConfig::Medium))
|
||||
);
|
||||
assert_eq!(
|
||||
app.config.plan_mode_reasoning_effort,
|
||||
Some(ReasoningEffortConfig::Low)
|
||||
);
|
||||
server.shutdown().await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn model_default_saves_report_server_outcomes_and_target_server_profile() -> Result<()> {
|
||||
for outcome in ["saved", "overridden", "rejected"] {
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tui/src/app/tests/model_defaults_tests.rs
|
||||
expression: next_history_message(&mut events)
|
||||
---
|
||||
• Model changed to gpt-5.6-terra high for this session only
|
||||
Reference in new issue
Block a user