codex: preserve model service tier ids

Move the raw model service-tier value handling into PR #20974. Dynamic slash commands now write service_tier_id while the lower PR continues to use the legacy service_tier enum path.

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Ahmed Ibrahim
2026-05-08 09:00:29 +03:00
co-authored by Codex
parent e6b5d23e2d
commit 33dc536a05
4 changed files with 57 additions and 22 deletions
+8 -4
View File
@@ -1271,17 +1271,21 @@ impl App {
}
}
}
AppEvent::PersistServiceTierSelection { service_tier } => {
AppEvent::PersistServiceTierSelection {
service_tier,
service_tier_id,
} => {
self.refresh_status_line();
let profile = self.active_profile.as_deref();
self.config.service_tier = service_tier;
self.config.service_tier_id =
service_tier.map(|service_tier| service_tier.request_value().to_string());
self.config.service_tier_id = service_tier_id.or_else(|| {
service_tier.map(|service_tier| service_tier.request_value().to_string())
});
let mut edits = ConfigEditsBuilder::new(&self.config.codex_home)
.with_profile(profile)
.set_service_tier(service_tier)
.set_service_tier_id(self.config.service_tier_id.clone());
if service_tier.is_none() {
if self.config.service_tier_id.is_none() && service_tier.is_none() {
self.config.notices.fast_default_opt_out = Some(true);
edits = edits.set_fast_default_opt_out(/*opted_out*/ true);
}
+1
View File
@@ -570,6 +570,7 @@ pub(crate) enum AppEvent {
/// Persist the selected service tier to the appropriate config.
PersistServiceTierSelection {
service_tier: Option<ServiceTier>,
service_tier_id: Option<String>,
},
/// Open the device picker for a realtime microphone or speaker.
+35 -13
View File
@@ -9417,11 +9417,21 @@ impl ChatWidget {
self.refresh_model_dependent_surfaces();
}
fn set_service_tier_selection(&mut self, service_tier: Option<ServiceTier>) {
if service_tier.is_none() {
fn set_service_tier_selection(
&mut self,
service_tier: Option<ServiceTier>,
service_tier_id: Option<String>,
) {
if service_tier_id.is_none() && service_tier.is_none() {
self.config.notices.fast_default_opt_out = Some(true);
}
self.set_service_tier(service_tier);
let next_service_tier_id = service_tier_id
.or_else(|| service_tier.map(|service_tier| service_tier.request_value().to_string()));
self.effective_service_tier = next_service_tier_id
.as_deref()
.and_then(service_tier_from_value);
self.config.service_tier = service_tier;
self.config.service_tier_id = next_service_tier_id.clone();
self.app_event_tx
.send(AppEvent::CodexOp(AppCommand::override_turn_context(
/*cwd*/ None,
@@ -9432,24 +9442,37 @@ impl ChatWidget {
/*model*/ None,
/*effort*/ None,
/*summary*/ None,
Some(service_tier.map(|service_tier| service_tier.request_value().to_string())),
Some(next_service_tier_id.clone()),
/*collaboration_mode*/ None,
/*personality*/ None,
)));
self.app_event_tx
.send(AppEvent::PersistServiceTierSelection { service_tier });
.send(AppEvent::PersistServiceTierSelection {
service_tier,
service_tier_id: next_service_tier_id,
});
}
fn handle_service_tier_slash_command(&mut self, command: ServiceTierCommand) {
let Some(service_tier) = service_tier_from_value(&command.id) else {
return;
};
let next_tier = if self.current_service_tier() == Some(service_tier) {
let active_service_tier_id_matches_command = self
.config
.service_tier_id
.as_deref()
.is_some_and(|service_tier_id| service_tier_id == command.id)
|| self.effective_service_tier.is_some_and(|service_tier| {
service_tier_from_value(&command.id) == Some(service_tier)
});
let next_service_tier_id = if active_service_tier_id_matches_command {
None
} else {
Some(service_tier)
Some(command.id)
};
self.set_service_tier_selection(next_tier);
self.set_service_tier_selection(
next_service_tier_id
.as_deref()
.and_then(service_tier_from_value),
next_service_tier_id,
);
self.bottom_pane.record_pending_slash_command_history();
}
@@ -9459,7 +9482,7 @@ impl ChatWidget {
} else {
Some(ServiceTier::Fast)
};
self.set_service_tier_selection(next_tier);
self.set_service_tier_selection(next_tier, /*service_tier_id*/ None);
}
pub(crate) fn current_model(&self) -> &str {
@@ -9509,7 +9532,6 @@ impl ChatWidget {
preset
.service_tiers
.into_iter()
.filter(|tier| service_tier_from_value(&tier.id).is_some())
.filter_map(|tier| {
ServiceTierCommand::new(&tier.name, tier.id, tier.description)
})
@@ -1,4 +1,5 @@
use super::*;
use codex_protocol::openai_models::SPEED_TIER_FAST;
use pretty_assertions::assert_eq;
fn complete_turn_with_message(chat: &mut ChatWidget, turn_id: &str, message: Option<&str>) {
@@ -1823,7 +1824,7 @@ async fn service_tier_slash_command_updates_and_persists_local_service_tier() {
AppEvent::CodexOp(Op::OverrideTurnContext {
service_tier: Some(Some(service_tier)),
..
}) if service_tier == ServiceTier::Fast.request_value()
}) if service_tier == SPEED_TIER_FAST
)),
"expected fast-mode override app event; events: {events:?}"
);
@@ -1832,7 +1833,9 @@ async fn service_tier_slash_command_updates_and_persists_local_service_tier() {
event,
AppEvent::PersistServiceTierSelection {
service_tier: Some(ServiceTier::Fast),
service_tier_id: Some(service_tier_id),
}
if service_tier_id == SPEED_TIER_FAST
)),
"expected service-tier persistence app event; events: {events:?}"
);
@@ -1864,7 +1867,9 @@ async fn fast_keybinding_toggle_uses_same_events_as_fast_slash_command() {
event,
AppEvent::PersistServiceTierSelection {
service_tier: Some(ServiceTier::Fast),
service_tier_id: Some(service_tier_id),
}
if service_tier_id == ServiceTier::Fast.request_value()
)),
"expected fast-mode persistence app event; events: {events:?}"
);
@@ -1906,7 +1911,7 @@ async fn user_turn_carries_service_tier_after_fast_toggle() {
Op::UserTurn {
service_tier: Some(Some(service_tier)),
..
} if service_tier == ServiceTier::Fast.request_value() => {}
} if service_tier == SPEED_TIER_FAST => {}
other => panic!("expected Op::UserTurn with fast service tier, got {other:?}"),
}
}
@@ -1932,7 +1937,7 @@ async fn queued_fast_slash_applies_before_next_queued_message() {
AppEvent::CodexOp(Op::OverrideTurnContext {
service_tier: Some(Some(service_tier)),
..
}) if service_tier == ServiceTier::Fast.request_value()
}) if service_tier == SPEED_TIER_FAST
)),
"expected queued /fast to update service tier before next turn; events: {events:?}"
);
@@ -1942,7 +1947,7 @@ async fn queued_fast_slash_applies_before_next_queued_message() {
items,
service_tier: Some(Some(service_tier)),
..
} if service_tier == ServiceTier::Fast.request_value() => assert_eq!(
} if service_tier == SPEED_TIER_FAST => assert_eq!(
items,
vec![UserInput::Text {
text: "hello after fast".to_string(),
@@ -1979,7 +1984,10 @@ async fn user_turn_sends_standard_override_after_fast_is_turned_off() {
assert!(
events.iter().any(|event| matches!(
event,
AppEvent::PersistServiceTierSelection { service_tier: None }
AppEvent::PersistServiceTierSelection {
service_tier: None,
service_tier_id: None,
}
)),
"expected fast-mode opt-out persistence app event; events: {events:?}"
);