mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add Luna Reserve usage fallback to the TUI (#42372)
## Why When ordinary included usage is exhausted, eligible users need a way to keep working with the backend-provided Luna Reserve quota and return to their previous model once ordinary usage recovers. ## What changed - Automatically switch eligible TUI tasks to Luna Reserve after an authoritative account usage read, preserving the prior model and reasoning effort per task. - Restrict model selection while on Reserve to its supported reasoning levels, keep queued turns on the accepted model, and restore the saved model after a fresh read confirms recovery. - Surface Reserve usage in the composer and `/status`, and expose `normalModelSlug` in app-server rate-limit snapshots so clients can use the associated model's display metadata without changing the request model. - Poll account limits more frequently near exhaustion and retain compatibility with app servers that only accept the legacy null request parameters. ## Testing - Added coverage for Reserve entry, queued-turn handling, task reconstruction, recovery authorization, account changes, model selection, usage rendering, and banner dismissal. GitOrigin-RevId: 46a435e9531051f8cec3f6a46c4b9f7cfa479747
This commit is contained in:
1 parent
76f47103fe
commit
5037919777
76 files changed
+1907
-135
No files matched your search
@@ -4,6 +4,7 @@
|
||||
//! into another, especially while Plan mode is active.
|
||||
|
||||
use super::*;
|
||||
use crate::model_catalog::LUNA_RESERVE_MODEL;
|
||||
|
||||
const ULTRA_REASONING_CONCURRENCY_WARNING_THRESHOLD: usize = 8;
|
||||
pub(super) const MODEL_SELECTION_VIEW_ID: &str = "model-selection";
|
||||
@@ -38,7 +39,7 @@ impl ChatWidget {
|
||||
self.app_event_tx.send(AppEvent::FetchModels { request_id });
|
||||
}
|
||||
|
||||
fn model_menu_header(&self, title: &str, subtitle: &str) -> Box<dyn Renderable> {
|
||||
pub(super) fn model_menu_header(&self, title: &str, subtitle: &str) -> Box<dyn Renderable> {
|
||||
let title = title.to_string();
|
||||
let subtitle = subtitle.to_string();
|
||||
let mut header = ColumnRenderable::new();
|
||||
@@ -78,6 +79,10 @@ impl ChatWidget {
|
||||
}
|
||||
|
||||
pub(crate) fn open_model_popup_with_presets(&mut self, presets: Vec<ModelPreset>) {
|
||||
if self.restrict_model_picker_to_luna_reserve() {
|
||||
self.open_luna_reserve_model_popup(presets, MODEL_SELECTION_VIEW_ID);
|
||||
return;
|
||||
}
|
||||
let presets: Vec<ModelPreset> = presets
|
||||
.into_iter()
|
||||
.filter(|preset| preset.show_in_picker)
|
||||
@@ -191,6 +196,13 @@ impl ChatWidget {
|
||||
}
|
||||
|
||||
pub(crate) fn open_all_models_popup(&mut self) {
|
||||
if self.restrict_model_picker_to_luna_reserve() {
|
||||
self.open_luna_reserve_model_popup(
|
||||
self.model_catalog.try_list_models().unwrap_or_default(),
|
||||
ALL_MODELS_SELECTION_VIEW_ID,
|
||||
);
|
||||
return;
|
||||
}
|
||||
let presets = self
|
||||
.model_catalog
|
||||
.try_list_models()
|
||||
@@ -262,8 +274,17 @@ impl ChatWidget {
|
||||
let warning = effort_for_action
|
||||
.as_ref()
|
||||
.and_then(|effort| self.ultra_reasoning_concurrency_warning(effort));
|
||||
let thread_id = self.thread_id();
|
||||
vec![Box::new(move |tx| {
|
||||
if effort_for_action == Some(ReasoningEffortConfig::Ultra) {
|
||||
if model_for_action == LUNA_RESERVE_MODEL {
|
||||
// Reserve is temporary: update the active task without persisting a model default.
|
||||
if let Some(thread_id) = thread_id {
|
||||
tx.send(AppEvent::UpdateLunaReserveReasoning {
|
||||
thread_id,
|
||||
effort: effort_for_action.clone(),
|
||||
});
|
||||
}
|
||||
} else if effort_for_action == Some(ReasoningEffortConfig::Ultra) {
|
||||
tx.send(AppEvent::ApplyAdvancedReasoning {
|
||||
model: model_for_action.clone(),
|
||||
effort: ReasoningEffortConfig::Ultra,
|
||||
@@ -295,6 +316,7 @@ impl ChatWidget {
|
||||
selected_effort: Option<ReasoningEffortConfig>,
|
||||
) -> bool {
|
||||
if !self.collaboration_modes_enabled()
|
||||
|| selected_model == LUNA_RESERVE_MODEL
|
||||
|| self.active_mode_kind() != ModeKind::Plan
|
||||
|| selected_model != self.current_model()
|
||||
{
|
||||
@@ -478,6 +500,11 @@ impl ChatWidget {
|
||||
.then(|| default_effort.clone());
|
||||
|
||||
let model_slug = preset.model.to_string();
|
||||
let model_label = if model_slug == LUNA_RESERVE_MODEL {
|
||||
preset.display_name.clone()
|
||||
} else {
|
||||
model_slug.clone()
|
||||
};
|
||||
let is_current_model = self.current_model() == preset.model.as_str();
|
||||
let highlight_choice = if is_current_model {
|
||||
if in_plan_mode {
|
||||
@@ -575,7 +602,7 @@ impl ChatWidget {
|
||||
|
||||
let mut header = ColumnRenderable::new();
|
||||
header.push(Line::from(
|
||||
format!("Select Reasoning Level for {model_slug}").bold(),
|
||||
format!("Select Reasoning Level for {model_label}").bold(),
|
||||
));
|
||||
|
||||
self.bottom_pane.show_selection_view(SelectionViewParams {
|
||||
@@ -704,27 +731,11 @@ impl ChatWidget {
|
||||
))
|
||||
}
|
||||
|
||||
pub(super) fn apply_model_and_effort_without_persist(
|
||||
&self,
|
||||
model: String,
|
||||
effort: Option<ReasoningEffortConfig>,
|
||||
) {
|
||||
let warning = effort
|
||||
.as_ref()
|
||||
.and_then(|effort| self.ultra_reasoning_concurrency_warning(effort));
|
||||
self.app_event_tx.send(AppEvent::UpdateModel(model));
|
||||
self.app_event_tx
|
||||
.send(AppEvent::UpdateReasoningEffort(effort));
|
||||
if let Some(warning) = warning {
|
||||
self.app_event_tx.send(AppEvent::InsertHistoryCell(Box::new(
|
||||
history_cell::new_warning_event(warning),
|
||||
)));
|
||||
fn apply_model_and_effort(&self, model: String, effort: Option<ReasoningEffortConfig>) {
|
||||
for action in self
|
||||
.model_selection_actions(model, effort, /*should_prompt_plan_mode_scope*/ false)
|
||||
{
|
||||
action(&self.app_event_tx);
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_model_and_effort(&self, model: String, effort: Option<ReasoningEffortConfig>) {
|
||||
self.apply_model_and_effort_without_persist(model.clone(), effort.clone());
|
||||
self.app_event_tx
|
||||
.send(AppEvent::PersistModelSelection { model, effort });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user