mirror of
https://github.com/openai/codex.git
synced 2026-11-26 07:26:11 +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
@@ -1,70 +1,328 @@
|
||||
//! Account banner state, independent of the current model and the lifetime of its rendered view.
|
||||
//! Account banners and response-driven model transitions for the selected task.
|
||||
//!
|
||||
//! Only explicitly dismissible, previously shown occurrences can be dismissed. Model changes hide
|
||||
//! content without dismissing it; an authoritative replacement/absence starts a new occurrence.
|
||||
//! Reserve recovery uses a focused picker and a persisted task-local return model.
|
||||
//! Its entry notice is shared across chats until the backend confirms ordinary usage has recovered.
|
||||
|
||||
use super::ChatWidget;
|
||||
use super::luna_reserve_return::ReserveReturnModel;
|
||||
use crate::app_command::AppCommand;
|
||||
use crate::backend_banners::BackendBanner;
|
||||
use crate::backend_banners::BannerPresentation;
|
||||
use crate::backend_banners::LUNA_RESERVE_BANNER;
|
||||
use crate::backend_banners::LUNA_RESERVE_RECOVERY_VIEW_ID;
|
||||
use crate::bottom_pane::SelectionItem;
|
||||
use crate::bottom_pane::SelectionViewParams;
|
||||
use crate::bottom_pane::popup_consts::accept_cancel_hint_line;
|
||||
use crate::keymap::ListAction;
|
||||
use crate::model_catalog::LUNA_RESERVE_MODEL;
|
||||
use codex_app_server_protocol::GetAccountRateLimitsResponse;
|
||||
use codex_protocol::config_types::CollaborationMode;
|
||||
use codex_protocol::config_types::ModeKind;
|
||||
use codex_protocol::openai_models::ModelPreset;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) enum AutomaticModelSwitchReason {
|
||||
UsageLimit,
|
||||
UsageRecovered,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) struct AutomaticModelSwitch {
|
||||
pub model: ModelPreset,
|
||||
pub effort: Option<ReasoningEffort>,
|
||||
pub reason: AutomaticModelSwitchReason,
|
||||
}
|
||||
|
||||
/// Live transition state; the return target is also persisted per task for reconstruction.
|
||||
#[derive(Default)]
|
||||
pub(super) struct AutomaticModelSwitchState {
|
||||
reserve_return: Option<ReserveReturnModel>,
|
||||
replaced_model: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct BackendBannerState {
|
||||
account_id: Option<String>,
|
||||
ordinary_usage_recovered: bool,
|
||||
banner: Option<BackendBanner>,
|
||||
presented: Option<BackendBanner>,
|
||||
shown: bool,
|
||||
dismissed: bool,
|
||||
picker_dismissed: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl ChatWidget {
|
||||
pub(crate) fn backend_banner_fallback(&self) -> Option<ModelPreset> {
|
||||
let banner = self.backend_banner_state.banner.as_ref()?;
|
||||
if !self.has_chatgpt_account
|
||||
|| !self.requires_openai_auth
|
||||
|| banner.blocked_model_slug.as_deref() != Some(self.current_model())
|
||||
{
|
||||
pub(super) fn restrict_model_picker_to_luna_reserve(&self) -> bool {
|
||||
// A fresh account read can allow manual recovery even without a valid saved return model.
|
||||
self.current_model() == LUNA_RESERVE_MODEL
|
||||
&& !self.backend_banner_state.ordinary_usage_recovered
|
||||
}
|
||||
|
||||
pub(crate) fn invalidate_ordinary_usage_recovery(&mut self) {
|
||||
// Keep the current banner, but never reuse permission from before a new hard stop.
|
||||
self.backend_banner_state.ordinary_usage_recovered = false;
|
||||
}
|
||||
|
||||
pub(super) fn waiting_for_luna_reserve(&self) -> bool {
|
||||
self.current_model() != LUNA_RESERVE_MODEL
|
||||
&& self
|
||||
.backend_banner_state
|
||||
.banner
|
||||
.as_ref()
|
||||
.is_some_and(|banner| banner.banner_type == LUNA_RESERVE_BANNER)
|
||||
}
|
||||
|
||||
pub(crate) fn backend_banner_fallback(&mut self) -> Option<AutomaticModelSwitch> {
|
||||
if !self.has_chatgpt_account || !self.requires_openai_auth {
|
||||
return None;
|
||||
}
|
||||
if self.current_model() == LUNA_RESERVE_MODEL
|
||||
&& self.automatic_model_switch_state.reserve_return.is_none()
|
||||
{
|
||||
self.automatic_model_switch_state.reserve_return =
|
||||
self.thread_id().and_then(|thread_id| {
|
||||
ReserveReturnModel::load(self.config.codex_home.as_path(), thread_id).or_else(
|
||||
|| {
|
||||
// Forks inherit Reserve settings, but need their own return target:
|
||||
// the parent's recovery will delete the parent's saved target.
|
||||
let previous = ReserveReturnModel::load(
|
||||
self.config.codex_home.as_path(),
|
||||
self.forked_from?,
|
||||
)?;
|
||||
if self.backend_banner_state.account_id.as_deref()
|
||||
!= Some(previous.account_id.as_str())
|
||||
{
|
||||
return None;
|
||||
}
|
||||
previous
|
||||
.save(self.config.codex_home.as_path(), thread_id)
|
||||
.ok()?;
|
||||
Some(previous)
|
||||
},
|
||||
)
|
||||
});
|
||||
}
|
||||
if self
|
||||
.automatic_model_switch_state
|
||||
.reserve_return
|
||||
.as_ref()
|
||||
.is_some_and(|previous| {
|
||||
self.backend_banner_state
|
||||
.account_id
|
||||
.as_ref()
|
||||
.is_some_and(|account_id| account_id != &previous.account_id)
|
||||
})
|
||||
{
|
||||
self.clear_reserve_return();
|
||||
}
|
||||
let models = self.model_catalog.try_list_models().ok()?;
|
||||
banner.fallback_model_slugs.iter().find_map(|candidate| {
|
||||
models
|
||||
.iter()
|
||||
.find(|model| {
|
||||
model.show_in_picker
|
||||
&& model.model == *candidate
|
||||
&& model.model != self.current_model()
|
||||
})
|
||||
.cloned()
|
||||
if self.current_model() == LUNA_RESERVE_MODEL
|
||||
&& self.backend_banner_state.ordinary_usage_recovered
|
||||
{
|
||||
let previous = self.automatic_model_switch_state.reserve_return.as_ref()?;
|
||||
if self.backend_banner_state.account_id.as_deref() != Some(previous.account_id.as_str())
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let model = models
|
||||
.into_iter()
|
||||
.find(|model| model.show_in_picker && model.model == previous.model)?;
|
||||
return Some(AutomaticModelSwitch {
|
||||
model,
|
||||
effort: previous.effort.clone(),
|
||||
reason: AutomaticModelSwitchReason::UsageRecovered,
|
||||
});
|
||||
}
|
||||
let banner = self.backend_banner_state.banner.as_ref()?;
|
||||
// The backend emits this banner only after ordinary usage is exhausted and Reserve
|
||||
// is available. Reserve is deliberately hidden from manual model selection.
|
||||
let model = if banner.banner_type == LUNA_RESERVE_BANNER {
|
||||
models.into_iter().find(|model| {
|
||||
model.model == LUNA_RESERVE_MODEL
|
||||
&& model.model != self.current_model()
|
||||
&& banner
|
||||
.blocked_model_slug
|
||||
.as_deref()
|
||||
.is_none_or(|blocked| blocked == self.current_model())
|
||||
})
|
||||
} else {
|
||||
if banner.blocked_model_slug.as_deref() != Some(self.current_model()) {
|
||||
return None;
|
||||
}
|
||||
banner.fallback_model_slugs.iter().find_map(|candidate| {
|
||||
models
|
||||
.iter()
|
||||
.find(|model| {
|
||||
model.show_in_picker
|
||||
&& model.model == *candidate
|
||||
&& model.model != self.current_model()
|
||||
})
|
||||
.cloned()
|
||||
})
|
||||
}?;
|
||||
Some(AutomaticModelSwitch {
|
||||
model,
|
||||
effort: self.current_reasoning_effort(),
|
||||
reason: AutomaticModelSwitchReason::UsageLimit,
|
||||
})
|
||||
}
|
||||
|
||||
/// Save the return target before changing server state, including before any turn is sent.
|
||||
pub(crate) fn prepare_luna_reserve_return(&mut self) -> bool {
|
||||
let Some((account_id, thread_id)) = self
|
||||
.backend_banner_state
|
||||
.account_id
|
||||
.clone()
|
||||
.zip(self.thread_id())
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let previous = ReserveReturnModel {
|
||||
account_id,
|
||||
model: self.current_model().to_string(),
|
||||
effort: self.current_reasoning_effort(),
|
||||
};
|
||||
previous
|
||||
.save(self.config.codex_home.as_path(), thread_id)
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
pub(super) fn clear_reserve_return(&mut self) {
|
||||
if let Some(thread_id) = self.thread_id() {
|
||||
ReserveReturnModel::clear(self.config.codex_home.as_path(), thread_id);
|
||||
}
|
||||
self.automatic_model_switch_state = AutomaticModelSwitchState::default();
|
||||
}
|
||||
|
||||
pub(crate) fn show_unavailable_reserve_recovery(&mut self) {
|
||||
self.clear_reserve_return();
|
||||
// A failed switch still needs recovery actions, even if another chat used Reserve.
|
||||
self.backend_banner_state.dismissed = false;
|
||||
self.backend_banner_state.picker_dismissed = Arc::default();
|
||||
self.backend_banner_state.presented = None;
|
||||
self.refresh_backend_banner_visibility();
|
||||
}
|
||||
|
||||
/// A composer submission can already be in the app queue when a Reserve switch fails.
|
||||
/// Reuse the retained prompt/steer rather than sending it on the blocked model.
|
||||
pub(crate) fn defer_pending_turn_for_luna_reserve(&mut self) -> bool {
|
||||
if !self.waiting_for_luna_reserve() {
|
||||
return false;
|
||||
}
|
||||
if self.input_queue.user_turn_pending_start
|
||||
&& let Some(prompt) = self.safety_buffering_prompt.take()
|
||||
{
|
||||
self.finalize_turn();
|
||||
self.input_queue
|
||||
.queued_user_messages
|
||||
.push_front(prompt.into());
|
||||
self.input_queue
|
||||
.queued_user_message_history_records
|
||||
.push_front(super::UserMessageHistoryRecord::UserMessageText);
|
||||
self.refresh_pending_input_preview();
|
||||
return true;
|
||||
}
|
||||
!self.input_queue.pending_steers.is_empty() && self.enqueue_rejected_steer()
|
||||
}
|
||||
|
||||
/// Commit a successfully applied task setting and keep its recovery notice visible together.
|
||||
pub(crate) fn finish_backend_banner_fallback(&mut self, mode: CollaborationMode) {
|
||||
let previous_model = self.current_model().to_string();
|
||||
let reserve_return = (mode.model() == LUNA_RESERVE_MODEL)
|
||||
.then(|| self.backend_banner_state.account_id.clone())
|
||||
.flatten()
|
||||
.map(|account_id| ReserveReturnModel {
|
||||
account_id,
|
||||
model: previous_model.clone(),
|
||||
effort: self.current_reasoning_effort(),
|
||||
});
|
||||
let involves_reserve =
|
||||
mode.model() == LUNA_RESERVE_MODEL || previous_model == LUNA_RESERVE_MODEL;
|
||||
self.set_model(mode.model());
|
||||
self.set_reasoning_effort(mode.reasoning_effort());
|
||||
if mode.mode == ModeKind::Plan {
|
||||
self.set_plan_mode_reasoning_effort(mode.reasoning_effort());
|
||||
}
|
||||
self.set_effective_collaboration_mode(mode);
|
||||
self.automatic_model_switch_state = AutomaticModelSwitchState {
|
||||
reserve_return,
|
||||
replaced_model: involves_reserve.then_some(previous_model),
|
||||
};
|
||||
// Showing the post-switch notice is distinct from having seen the original blocked state.
|
||||
self.backend_banner_state.shown = false;
|
||||
self.backend_banner_state.dismissed = false;
|
||||
self.backend_banner_state.dismissed = self.reserve_notice_already_shown();
|
||||
self.backend_banner_state.picker_dismissed = Arc::default();
|
||||
self.bottom_pane
|
||||
.dismiss_view_by_id(LUNA_RESERVE_RECOVERY_VIEW_ID);
|
||||
self.backend_banner_state.presented = None;
|
||||
self.backend_banner_notice_model = Some(self.current_model().to_string());
|
||||
self.refresh_backend_banner_visibility();
|
||||
}
|
||||
|
||||
/// A queued command may have been composed before the account read switched this task.
|
||||
pub(crate) fn apply_reserve_fallback_to_pending_turn(&self, op: &mut AppCommand) {
|
||||
let AppCommand::UserTurn {
|
||||
model,
|
||||
effort,
|
||||
service_tier,
|
||||
collaboration_mode,
|
||||
..
|
||||
} = op
|
||||
else {
|
||||
return;
|
||||
};
|
||||
if self.automatic_model_switch_state.replaced_model.as_deref() != Some(model.as_str()) {
|
||||
return;
|
||||
}
|
||||
*model = self.current_model().to_string();
|
||||
*effort = self.current_reasoning_effort();
|
||||
*service_tier = self.service_tier_update_for_core();
|
||||
if let Some(mode) = collaboration_mode {
|
||||
mode.settings.model = model.clone();
|
||||
mode.settings.reasoning_effort = effort.clone();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn inherit_backend_banner_state(&mut self, previous: &mut ChatWidget) {
|
||||
previous.observe_backend_banner_view();
|
||||
self.backend_banner_state = std::mem::take(&mut previous.backend_banner_state);
|
||||
self.luna_reserve_notice_account_id = previous.luna_reserve_notice_account_id.take();
|
||||
self.backend_banner_state.dismissed |= self.reserve_notice_already_shown();
|
||||
// Usage belongs to the account, so switching tasks must not reset the polling cadence
|
||||
// or discard the already-known limits shown by /status.
|
||||
self.rate_limit_snapshots_by_limit_id =
|
||||
std::mem::take(&mut previous.rate_limit_snapshots_by_limit_id);
|
||||
self.codex_rate_limit_reached_type = previous.codex_rate_limit_reached_type;
|
||||
self.codex_spend_control_reached = previous.codex_spend_control_reached;
|
||||
self.backend_banner_state.presented = None;
|
||||
self.refresh_backend_banner_visibility();
|
||||
}
|
||||
|
||||
pub(crate) fn update_backend_banner(&mut self, response: &GetAccountRateLimitsResponse) {
|
||||
self.observe_backend_banner_view();
|
||||
self.backend_banner_state.account_id = response.account_id.clone();
|
||||
// Only a full, identity-validated backend read can authorize recovery. Unknown banners
|
||||
// still block it; percentages, sparse notifications and reset timestamps cannot prove it.
|
||||
let has_usable_credits = response
|
||||
.rate_limits
|
||||
.credits
|
||||
.as_ref()
|
||||
.is_some_and(|credits| credits.unlimited || credits.has_credits);
|
||||
self.backend_banner_state.ordinary_usage_recovered =
|
||||
response.ordinary_usage_allowed.is_some()
|
||||
&& (response.ordinary_usage_allowed == Some(true) || has_usable_credits)
|
||||
&& response.rate_limit_upsell.is_none()
|
||||
&& response.rate_limits.spend_control_reached != Some(true)
|
||||
&& response.rate_limits.rate_limit_reached_type.is_none();
|
||||
if self.backend_banner_state.ordinary_usage_recovered {
|
||||
self.luna_reserve_notice_account_id = None;
|
||||
}
|
||||
let banner = response
|
||||
.rate_limit_upsell
|
||||
.as_ref()
|
||||
@@ -88,23 +346,47 @@ impl ChatWidget {
|
||||
== new.blocked_model_slug.as_ref().or(new.model_slug.as_ref())
|
||||
&& old.fallback_model_slugs == new.fallback_model_slugs
|
||||
});
|
||||
self.backend_banner_state.banner = banner;
|
||||
if !same_occurrence {
|
||||
self.backend_banner_state.shown = false;
|
||||
self.backend_banner_state.dismissed = false;
|
||||
self.backend_banner_state.dismissed = self.reserve_notice_already_shown();
|
||||
self.backend_banner_state.picker_dismissed = Arc::default();
|
||||
self.backend_banner_notice_model = None;
|
||||
}
|
||||
self.backend_banner_state.banner = banner;
|
||||
if self.waiting_for_luna_reserve() {
|
||||
self.hold_rate_limit_recovery();
|
||||
}
|
||||
self.refresh_backend_banner_visibility();
|
||||
}
|
||||
|
||||
fn reserve_notice_already_shown(&self) -> bool {
|
||||
self.backend_banner_state
|
||||
.banner
|
||||
.as_ref()
|
||||
.is_some_and(|banner| {
|
||||
banner.banner_type == LUNA_RESERVE_BANNER
|
||||
&& self.luna_reserve_notice_account_id.as_deref()
|
||||
== Some(banner.account_id.as_str())
|
||||
})
|
||||
}
|
||||
|
||||
fn observe_backend_banner_view(&mut self) {
|
||||
let (shown, dismissed) = self.bottom_pane.inline_banner_lifecycle();
|
||||
self.backend_banner_state.shown |= shown;
|
||||
self.backend_banner_state.dismissed |= dismissed;
|
||||
self.backend_banner_state.dismissed |= self
|
||||
.backend_banner_state
|
||||
.picker_dismissed
|
||||
.load(Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub(super) fn refresh_backend_banner_visibility(&mut self) {
|
||||
let banner = self.backend_banner_state.banner.as_ref().filter(|banner| {
|
||||
// Keep recovery actions available while switching, including on older servers
|
||||
// without settings/update. The copy below describes the accepted model only.
|
||||
if banner.banner_type == LUNA_RESERVE_BANNER {
|
||||
return !self.backend_banner_state.dismissed;
|
||||
}
|
||||
// Explicit fallback payloads describe the selected replacement, not a pending switch.
|
||||
let matches_selected_model = match banner.blocked_model_slug.as_deref() {
|
||||
Some(blocked) if !banner.fallback_model_slugs.is_empty() => {
|
||||
@@ -127,7 +409,19 @@ impl ChatWidget {
|
||||
if banner == self.backend_banner_state.presented.as_ref() {
|
||||
return;
|
||||
}
|
||||
let content = banner.map(BackendBanner::actionable_banner);
|
||||
let is_reserve = banner.is_some_and(|banner| banner.banner_type == LUNA_RESERVE_BANNER);
|
||||
let content = banner.map(|banner| {
|
||||
let mut content = banner.actionable_banner();
|
||||
if banner.banner_type == LUNA_RESERVE_BANNER
|
||||
&& self.current_model() != LUNA_RESERVE_MODEL
|
||||
{
|
||||
content.title = "Usage limit reached".to_string();
|
||||
content.description =
|
||||
"Your included usage is exhausted. Choose an option below to continue."
|
||||
.to_string();
|
||||
}
|
||||
content
|
||||
});
|
||||
self.backend_banner_state.presented = banner.cloned();
|
||||
if content.is_some() {
|
||||
self.bottom_pane
|
||||
@@ -140,7 +434,45 @@ impl ChatWidget {
|
||||
self.rate_limit_switch_prompt = super::RateLimitSwitchPromptState::Pending;
|
||||
}
|
||||
}
|
||||
self.bottom_pane.set_inline_banner(content);
|
||||
self.bottom_pane
|
||||
.dismiss_view_by_id(LUNA_RESERVE_RECOVERY_VIEW_ID);
|
||||
match (is_reserve, content) {
|
||||
(true, Some(content)) => {
|
||||
self.bottom_pane.set_inline_banner(/*banner*/ None);
|
||||
let mut params: SelectionViewParams = content.into();
|
||||
params.view_id = Some(LUNA_RESERVE_RECOVERY_VIEW_ID);
|
||||
if self.current_model() == LUNA_RESERVE_MODEL {
|
||||
self.luna_reserve_notice_account_id =
|
||||
self.backend_banner_state.account_id.clone();
|
||||
// Continuing is a local dismissal, separate from the backend's purchase CTAs.
|
||||
params.items.push(SelectionItem {
|
||||
name: "Continue with Luna Reserve".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
let list_keymap = self.bottom_pane.list_keymap();
|
||||
params.footer_hint = Some(accept_cancel_hint_line(
|
||||
list_keymap.primary_hint(ListAction::Accept),
|
||||
"to confirm",
|
||||
list_keymap.primary_hint(ListAction::Cancel),
|
||||
"to continue working",
|
||||
));
|
||||
}
|
||||
// Use the standard focused picker: arrows/Enter and numeric shortcuts select,
|
||||
// Escape returns to the unchanged composer and its saved draft.
|
||||
let dismissed = Arc::clone(&self.backend_banner_state.picker_dismissed);
|
||||
params.on_cancel =
|
||||
Some(Box::new(move |_| dismissed.store(true, Ordering::Relaxed)));
|
||||
for item in &mut params.items {
|
||||
item.dismiss_on_select = true;
|
||||
let dismissed = Arc::clone(&self.backend_banner_state.picker_dismissed);
|
||||
item.actions
|
||||
.push(Box::new(move |_| dismissed.store(true, Ordering::Relaxed)));
|
||||
}
|
||||
self.backend_banner_state.shown = true;
|
||||
self.bottom_pane.show_selection_view(params);
|
||||
}
|
||||
(_, content) => self.bottom_pane.set_inline_banner(content),
|
||||
}
|
||||
if self.backend_banner_state.presented.is_none()
|
||||
&& !self.bottom_pane.is_task_running()
|
||||
&& self.bottom_pane.no_modal_or_popup_active()
|
||||
@@ -175,6 +507,8 @@ impl ChatWidget {
|
||||
pub(crate) fn clear_backend_banner(&mut self) {
|
||||
self.backend_banner_state = BackendBannerState::default();
|
||||
self.backend_banner_notice_model = None;
|
||||
self.bottom_pane
|
||||
.dismiss_view_by_id(LUNA_RESERVE_RECOVERY_VIEW_ID);
|
||||
self.bottom_pane.set_inline_banner(/*banner*/ None);
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,9 @@ impl ChatWidget {
|
||||
codex_spend_control_reached: None,
|
||||
rate_limit_warnings: RateLimitWarningState::default(),
|
||||
backend_banner_state: backend_banners::BackendBannerState::default(),
|
||||
automatic_model_switch_state: backend_banners::AutomaticModelSwitchState::default(),
|
||||
backend_banner_notice_model: None,
|
||||
luna_reserve_notice_account_id: None,
|
||||
warning_display_state: WarningDisplayState::default(),
|
||||
rate_limit_switch_prompt: RateLimitSwitchPromptState::default(),
|
||||
add_credits_nudge_email_in_flight: None,
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
//! The Reserve-only /model picker uses normal-model metadata while keeping Reserve routing.
|
||||
|
||||
use super::*;
|
||||
use crate::model_catalog::LUNA_MODEL;
|
||||
use crate::model_catalog::LUNA_RESERVE_MODEL;
|
||||
|
||||
impl ChatWidget {
|
||||
pub(super) fn open_luna_reserve_model_popup(
|
||||
&mut self,
|
||||
presets: Vec<ModelPreset>,
|
||||
view_id: &'static str,
|
||||
) {
|
||||
let normal_model_slug = self
|
||||
.rate_limit_snapshots_by_limit_id
|
||||
.values()
|
||||
.find(|snapshot| snapshot.limit_name == LUNA_RESERVE_MODEL)
|
||||
.and_then(|snapshot| snapshot.normal_model_slug.as_deref());
|
||||
let preset = normal_model_slug
|
||||
.and_then(|slug| presets.iter().find(|preset| preset.model == slug))
|
||||
.or_else(|| presets.iter().find(|preset| preset.model == LUNA_MODEL));
|
||||
let Some(mut preset) = preset.cloned() else {
|
||||
self.bottom_pane.dismiss_view_by_id(view_id);
|
||||
self.add_info_message(
|
||||
"Luna model settings are unavailable; please try /model again in a moment."
|
||||
.to_string(),
|
||||
/*hint*/ None,
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
// Only borrow the normal model's presentation and supported efforts. Selecting an
|
||||
// effort must keep the authorized Reserve model and the saved ordinary return target.
|
||||
preset.model = LUNA_RESERVE_MODEL.to_string();
|
||||
let single_supported_effort = preset.supported_reasoning_efforts.len() == 1;
|
||||
let name = preset.display_name.clone();
|
||||
let description = (!preset.description.is_empty()).then_some(preset.description.clone());
|
||||
let actions: Vec<SelectionAction> = vec![Box::new(move |tx| {
|
||||
tx.send(AppEvent::OpenReasoningPopup {
|
||||
model: preset.clone(),
|
||||
});
|
||||
})];
|
||||
let header = self.model_menu_header(
|
||||
"Select Model",
|
||||
"Other models return when ordinary usage is available again.",
|
||||
);
|
||||
self.show_model_selection_view(SelectionViewParams {
|
||||
view_id: Some(view_id),
|
||||
header,
|
||||
footer_hint: Some(self.bottom_pane.standard_popup_hint_line()),
|
||||
items: vec![SelectionItem {
|
||||
name,
|
||||
description,
|
||||
is_current: true,
|
||||
actions,
|
||||
dismiss_on_select: single_supported_effort,
|
||||
dismiss_parent_on_child_accept: !single_supported_effort,
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//! Persist the account-bound return model for a task before automatically entering Reserve.
|
||||
//! Task IDs scope the cache across reconnects/resumes without changing global model defaults.
|
||||
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub(super) struct ReserveReturnModel {
|
||||
pub account_id: String,
|
||||
pub model: String,
|
||||
pub effort: Option<ReasoningEffort>,
|
||||
}
|
||||
|
||||
impl ReserveReturnModel {
|
||||
fn path(codex_home: &Path, thread_id: ThreadId) -> PathBuf {
|
||||
codex_home
|
||||
.join("tui-luna-reserve")
|
||||
.join(format!("{thread_id}.json"))
|
||||
}
|
||||
|
||||
pub(super) fn load(codex_home: &Path, thread_id: ThreadId) -> Option<Self> {
|
||||
let file = std::fs::File::open(Self::path(codex_home, thread_id)).ok()?;
|
||||
// A corrupt or unrelated cache file must not cause an unbounded read.
|
||||
serde_json::from_reader(file.take(/*limit*/ 4096)).ok()
|
||||
}
|
||||
|
||||
pub(super) fn save(&self, codex_home: &Path, thread_id: ThreadId) -> io::Result<()> {
|
||||
let path = Self::path(codex_home, thread_id);
|
||||
let directory = path.parent().ok_or(io::ErrorKind::InvalidInput)?;
|
||||
std::fs::create_dir_all(directory)?;
|
||||
let mut file = tempfile::NamedTempFile::new_in(directory)?;
|
||||
serde_json::to_writer(&mut file, self)?;
|
||||
file.as_file().sync_all()?;
|
||||
file.persist(path).map_err(|error| error.error)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn clear(codex_home: &Path, thread_id: ThreadId) {
|
||||
// A missing cache needs no cleanup; the live model is authoritative after leaving Reserve.
|
||||
let _ = std::fs::remove_file(Self::path(codex_home, thread_id));
|
||||
}
|
||||
}
|
||||
@@ -36,16 +36,22 @@ impl ChatWidget {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
self.model_catalog = Arc::new(ModelCatalog::new(presets.clone()));
|
||||
self.model_catalog = Arc::new(ModelCatalog::new(presets));
|
||||
self.refresh_effective_service_tier();
|
||||
self.refresh_model_dependent_surfaces();
|
||||
true
|
||||
}
|
||||
|
||||
/// Keep a present model picker aligned with the active task, including Reserve entry/exit.
|
||||
pub(super) fn refresh_open_model_picker(&mut self) {
|
||||
// Refresh an existing parent without reopening it or interrupting its reasoning child.
|
||||
match self.model_popup_view_id() {
|
||||
Some(MODEL_SELECTION_VIEW_ID) => self.open_model_popup_with_presets(presets),
|
||||
Some(MODEL_SELECTION_VIEW_ID) => self.open_model_popup_with_presets(
|
||||
self.model_catalog.try_list_models().unwrap_or_default(),
|
||||
),
|
||||
Some(ALL_MODELS_SELECTION_VIEW_ID) => self.open_all_models_popup(),
|
||||
_ => {}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub(super) fn show_model_selection_view(&mut self, mut params: SelectionViewParams) {
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
//! Rate-limit warning, prompt, and notice surfaces for `ChatWidget`.
|
||||
//! Rate-limit warning, prompt, and notice surfaces, plus quota-aware account refresh cadence.
|
||||
|
||||
use super::*;
|
||||
pub(super) const WORKSPACE_NUDGE_VIEW_ID: &str = "workspace-usage-nudge";
|
||||
use crate::bottom_pane::ActionableBanner;
|
||||
use crate::model_catalog::LUNA_RESERVE_MODEL;
|
||||
use codex_app_server_protocol::CodexErrorInfo as AppServerCodexErrorInfo;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -11,7 +12,7 @@ pub(super) struct PendingCreditsNudge {
|
||||
credit_type: AddCreditsNudgeCreditType,
|
||||
}
|
||||
|
||||
pub(super) const NUDGE_MODEL_SLUG: &str = "gpt-5.6-luna";
|
||||
pub(super) const NUDGE_MODEL_SLUG: &str = crate::model_catalog::LUNA_MODEL;
|
||||
pub(super) const RATE_LIMIT_SWITCH_PROMPT_THRESHOLD: f64 = 90.0;
|
||||
pub(super) const RATE_LIMIT_SWITCH_PROMPT_VIEW_ID: &str = "rate-limit-switch-prompt";
|
||||
|
||||
@@ -185,11 +186,43 @@ fn has_usable_workspace_credits(credits: &CreditsSnapshot) -> bool {
|
||||
}
|
||||
|
||||
impl ChatWidget {
|
||||
/// Poll more often near exhaustion for every ChatGPT account, independently of experiments.
|
||||
pub(crate) fn rate_limit_refresh_interval(&self) -> Option<std::time::Duration> {
|
||||
if !self.should_prefetch_rate_limits() {
|
||||
return None;
|
||||
}
|
||||
// Ignore unrelated model buckets; watch ordinary usage and the selected model's bucket.
|
||||
let used_percent = self
|
||||
.rate_limit_snapshots_by_limit_id
|
||||
.iter()
|
||||
.filter(|(limit_id, snapshot)| {
|
||||
limit_id.as_str() == "codex" || snapshot.limit_name == self.current_model()
|
||||
})
|
||||
.flat_map(|(_, snapshot)| snapshot.primary.iter().chain(snapshot.secondary.iter()))
|
||||
.map(|window| window.used_percent)
|
||||
.filter(|percent| percent.is_finite())
|
||||
.max_by(f64::total_cmp)
|
||||
.unwrap_or_default();
|
||||
let seconds = if used_percent >= 99.0 {
|
||||
5
|
||||
} else if used_percent >= 90.0 {
|
||||
15
|
||||
} else if used_percent >= 75.0 {
|
||||
30
|
||||
} else {
|
||||
60
|
||||
};
|
||||
Some(std::time::Duration::from_secs(seconds))
|
||||
}
|
||||
|
||||
pub(crate) fn hold_rate_limit_recovery(&mut self) -> bool {
|
||||
std::mem::replace(&mut self.input_queue.rate_limit_recovery_pending, true)
|
||||
}
|
||||
|
||||
pub(crate) fn finish_rate_limit_recovery(&mut self) {
|
||||
if self.waiting_for_luna_reserve() {
|
||||
return;
|
||||
}
|
||||
if std::mem::take(&mut self.input_queue.rate_limit_recovery_pending) {
|
||||
self.submit_initial_user_message_if_pending();
|
||||
self.maybe_send_next_queued_input();
|
||||
@@ -224,10 +257,6 @@ impl ChatWidget {
|
||||
.limit_id
|
||||
.clone()
|
||||
.unwrap_or_else(|| "codex".to_string());
|
||||
let limit_label = snapshot
|
||||
.limit_name
|
||||
.clone()
|
||||
.unwrap_or_else(|| limit_id.clone());
|
||||
if matches!(source, RateLimitSnapshotSource::RollingUpdate)
|
||||
&& snapshot.credits.is_none()
|
||||
{
|
||||
@@ -241,16 +270,6 @@ impl ChatWidget {
|
||||
balance: credits.balance.clone(),
|
||||
});
|
||||
}
|
||||
let preserved_individual_limit =
|
||||
if matches!(source, RateLimitSnapshotSource::RollingUpdate)
|
||||
&& snapshot.individual_limit.is_none()
|
||||
{
|
||||
self.rate_limit_snapshots_by_limit_id
|
||||
.get(&limit_id)
|
||||
.and_then(|display| display.individual_limit.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.plan_type = snapshot.plan_type.or(self.plan_type);
|
||||
|
||||
let is_codex_limit = limit_id.eq_ignore_ascii_case("codex");
|
||||
@@ -341,13 +360,18 @@ impl ChatWidget {
|
||||
self.rate_limit_switch_prompt = RateLimitSwitchPromptState::Pending;
|
||||
}
|
||||
|
||||
let mut display =
|
||||
rate_limit_snapshot_display_for_limit(&snapshot, limit_label, Local::now());
|
||||
if display.individual_limit.is_none() {
|
||||
display.individual_limit = preserved_individual_limit;
|
||||
// /wham/usage identifies ordinary and additional model limits separately. Streamed
|
||||
// updates still drive warnings/recovery above, but must not overwrite status data.
|
||||
if matches!(source, RateLimitSnapshotSource::AccountUsage) {
|
||||
let limit_label = snapshot
|
||||
.limit_name
|
||||
.clone()
|
||||
.unwrap_or_else(|| limit_id.clone());
|
||||
let display =
|
||||
rate_limit_snapshot_display_for_limit(&snapshot, limit_label, Local::now());
|
||||
self.rate_limit_snapshots_by_limit_id
|
||||
.insert(limit_id, display);
|
||||
}
|
||||
self.rate_limit_snapshots_by_limit_id
|
||||
.insert(limit_id, display);
|
||||
|
||||
if !warnings.is_empty() {
|
||||
for warning in warnings {
|
||||
@@ -394,7 +418,9 @@ impl ChatWidget {
|
||||
if self.has_applicable_backend_banner() {
|
||||
return;
|
||||
}
|
||||
if self.rate_limit_switch_prompt_hidden() || self.current_model() == NUDGE_MODEL_SLUG {
|
||||
if self.rate_limit_switch_prompt_hidden()
|
||||
|| matches!(self.current_model(), NUDGE_MODEL_SLUG | LUNA_RESERVE_MODEL)
|
||||
{
|
||||
self.rate_limit_switch_prompt = RateLimitSwitchPromptState::Idle;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ impl ChatWidget {
|
||||
.set_queue_submissions(/*queue_submissions*/ false);
|
||||
if previous_thread_id != self.thread_id {
|
||||
self.backend_banner_notice_model = None;
|
||||
self.automatic_model_switch_state =
|
||||
backend_banners::AutomaticModelSwitchState::default();
|
||||
self.pending_automatic_thread_names.clear();
|
||||
self.review.recent_auto_review_denials = RecentAutoReviewDenials::default();
|
||||
self.clear_thread_usage_state();
|
||||
@@ -114,6 +116,19 @@ impl ChatWidget {
|
||||
.set_active_reasoning_effort_baseline(effort.as_ref());
|
||||
self.refresh_model_display();
|
||||
self.refresh_status_surfaces();
|
||||
if previous_thread_id != self.thread_id
|
||||
&& self.should_prefetch_rate_limits()
|
||||
&& (self.current_model() == crate::model_catalog::LUNA_RESERVE_MODEL
|
||||
|| self.backend_banner_fallback().is_some())
|
||||
{
|
||||
// Reconcile this task with retained account state before sending its initial/queued
|
||||
// prompt. Do not wait for the next usage poll after /new, /resume or a thread switch.
|
||||
self.hold_rate_limit_recovery();
|
||||
self.app_event_tx
|
||||
.send(AppEvent::ApplyBackendBannerFallback {
|
||||
thread_id: session.thread_id,
|
||||
});
|
||||
}
|
||||
self.sync_service_tier_commands();
|
||||
self.sync_personality_command_enabled();
|
||||
self.sync_plugins_command_enabled();
|
||||
|
||||
@@ -221,6 +221,8 @@ impl ChatWidget {
|
||||
self.clear_pending_token_activity_refreshes();
|
||||
self.clear_pending_rate_limit_reset_requests();
|
||||
self.clear_backend_banner();
|
||||
self.luna_reserve_notice_account_id = None;
|
||||
self.automatic_model_switch_state = backend_banners::AutomaticModelSwitchState::default();
|
||||
self.input_queue.rate_limit_recovery_pending = false;
|
||||
self.add_credits_nudge_email_in_flight = None;
|
||||
self.codex_rate_limit_reached_type = None;
|
||||
@@ -261,6 +263,14 @@ impl ChatWidget {
|
||||
|
||||
/// Set the model in the widget's config copy and stored collaboration mode.
|
||||
pub(crate) fn set_model(&mut self, model: &str) {
|
||||
if model != self.current_model() {
|
||||
if self.current_model() == crate::model_catalog::LUNA_RESERVE_MODEL {
|
||||
self.clear_reserve_return();
|
||||
} else {
|
||||
self.automatic_model_switch_state =
|
||||
backend_banners::AutomaticModelSwitchState::default();
|
||||
}
|
||||
}
|
||||
self.current_collaboration_mode = self.current_collaboration_mode.with_updates(
|
||||
Some(model.to_string()),
|
||||
/*effort*/ None,
|
||||
@@ -452,6 +462,7 @@ impl ChatWidget {
|
||||
self.sync_backend_banner_view();
|
||||
self.refresh_model_display();
|
||||
self.refresh_status_line();
|
||||
self.refresh_open_model_picker();
|
||||
}
|
||||
|
||||
fn apply_thread_settings(&mut self, mut settings: ThreadSettings) {
|
||||
@@ -551,7 +562,7 @@ impl ChatWidget {
|
||||
if model.is_empty() {
|
||||
DEFAULT_MODEL_DISPLAY_NAME
|
||||
} else {
|
||||
model
|
||||
crate::model_catalog::model_display_name(model)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::branch_summary;
|
||||
use crate::chatwidget::limit_label_for_window;
|
||||
use crate::chatwidget::rate_limits::get_limits_duration;
|
||||
use crate::legacy_core::config::Config;
|
||||
use crate::model_catalog::LUNA_RESERVE_MODEL;
|
||||
use crate::status::format_credit_micros;
|
||||
use crate::status::format_estimated_usd_micros;
|
||||
use crate::status::format_tokens_compact;
|
||||
@@ -293,6 +294,8 @@ impl ChatWidget {
|
||||
/// warnings once, synchronizes shared cached state (such as git-branch
|
||||
/// lookup), then renders each surface from that shared snapshot.
|
||||
pub(crate) fn refresh_status_surfaces(&mut self) {
|
||||
self.bottom_pane
|
||||
.set_luna_reserve_active(self.current_model() == LUNA_RESERVE_MODEL);
|
||||
let selections = self.status_surface_selections();
|
||||
self.warn_invalid_status_line_items_once(&selections.invalid_status_line_items);
|
||||
self.warn_invalid_terminal_title_items_once(&selections.invalid_terminal_title_items);
|
||||
|
||||
@@ -246,6 +246,8 @@ mod goal_validation;
|
||||
mod guardian;
|
||||
pub(crate) mod helpers;
|
||||
mod history_replay;
|
||||
#[path = "tests/luna_reserve_usage_tests.rs"]
|
||||
mod luna_reserve_usage_tests;
|
||||
mod mcp_startup;
|
||||
#[path = "tests/misalignment_policy_tests.rs"]
|
||||
mod misalignment_policy;
|
||||
|
||||
@@ -319,7 +319,10 @@ async fn backend_banner_fallback_candidates_and_notice_follow_selected_model() {
|
||||
response.rate_limit_upsell.as_mut().unwrap()["fallback_model_slugs"] =
|
||||
json!(["hidden-model", "test-model-c", "test-model-b"]);
|
||||
chat.update_backend_banner(&response);
|
||||
assert_eq!(chat.backend_banner_fallback(), Some(models[2].clone()));
|
||||
assert_eq!(
|
||||
chat.backend_banner_fallback().map(|switch| switch.model),
|
||||
Some(models[2].clone())
|
||||
);
|
||||
// A retained ChatGPT login must not change a task whose server does not require auth.
|
||||
chat.requires_openai_auth = false;
|
||||
assert_eq!(chat.backend_banner_fallback(), None);
|
||||
|
||||
@@ -107,6 +107,7 @@ pub(super) fn snapshot(percent: f64) -> RateLimitSnapshot {
|
||||
RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: percent.round() as i32,
|
||||
window_duration_mins: Some(60),
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
//! Exercise Reserve picker focus, its status label, and the composer palette across entry and exit.
|
||||
|
||||
use super::helpers::normalize_snapshot_paths;
|
||||
use super::*;
|
||||
use crate::terminal_palette::with_test_default_colors;
|
||||
use crate::terminal_probe::DefaultColors;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
|
||||
fn reserve_snapshot(primary_used: i32, weekly_used: i32) -> RateLimitSnapshot {
|
||||
RateLimitSnapshot {
|
||||
limit_id: Some("base_model_inference".into()),
|
||||
limit_name: Some("gpt-reserve".into()),
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: primary_used,
|
||||
window_duration_mins: Some(300),
|
||||
resets_at: None,
|
||||
}),
|
||||
secondary: Some(RateLimitWindow {
|
||||
used_percent: weekly_used,
|
||||
window_duration_mins: Some(10080),
|
||||
resets_at: None,
|
||||
}),
|
||||
..snapshot(/*percent*/ 0.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn luna_reserve_selector_supports_arrows_enter_shortcuts_and_escape_without_losing_draft() {
|
||||
for (keys, destination) in [
|
||||
(
|
||||
vec![KeyCode::Down, KeyCode::Enter],
|
||||
Some("https://chatgpt.com/?cta_tab=personal&highlight_plan=plus#pricing"),
|
||||
),
|
||||
(
|
||||
vec![KeyCode::Down, KeyCode::Up, KeyCode::Enter],
|
||||
Some("https://chatgpt.com/codex/settings/usage?credits_modal=true"),
|
||||
),
|
||||
(
|
||||
vec![KeyCode::Char('1')],
|
||||
Some("https://chatgpt.com/codex/settings/usage?credits_modal=true"),
|
||||
),
|
||||
(
|
||||
vec![KeyCode::Char('2')],
|
||||
Some("https://chatgpt.com/?cta_tab=personal&highlight_plan=plus#pricing"),
|
||||
),
|
||||
(vec![KeyCode::Down, KeyCode::Esc], None),
|
||||
] {
|
||||
let (mut chat, mut events, _ops) = make_chatwidget_manual(Some("gpt-reserve")).await;
|
||||
chat.has_chatgpt_account = true;
|
||||
chat.apply_external_edit("saved draft".into());
|
||||
chat.on_rate_limit_snapshot(Some(reserve_snapshot(
|
||||
/*primary_used*/ 48, /*weekly_used*/ 20,
|
||||
)));
|
||||
let response = serde_json::from_value(json!({
|
||||
"accountId": "account-preview", "rateLimits": {},
|
||||
"rateLimitUpsell": {
|
||||
"banner_type": "luna_reserve", "presentation": "dismissible",
|
||||
"title": "You’re now using Luna, a faster model for simpler tasks.",
|
||||
"description": "Add credits or upgrade to continue using the most advanced models.",
|
||||
"ctas": [{"action": "add_credits", "label": "Add credits"},
|
||||
{"action": "open_pricing_dialog", "label": "Upgrade"}]
|
||||
}
|
||||
}))
|
||||
.unwrap();
|
||||
chat.update_backend_banner(&response);
|
||||
let rendered = normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 90));
|
||||
assert!(
|
||||
!rendered.contains("saved draft"),
|
||||
"selector owns input focus"
|
||||
);
|
||||
assert!(rendered.contains("esc to continue working"));
|
||||
while events.try_recv().is_ok() {}
|
||||
for key in keys {
|
||||
chat.handle_key_event(KeyEvent::from(key));
|
||||
if key == KeyCode::Down {
|
||||
insta::assert_snapshot!(
|
||||
"luna_reserve_selector_second_choice",
|
||||
normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 90))
|
||||
);
|
||||
}
|
||||
}
|
||||
let queued = std::iter::from_fn(|| events.try_recv().ok()).collect::<Vec<_>>();
|
||||
let urls: Vec<_> = queued
|
||||
.iter()
|
||||
.filter_map(|event| match event {
|
||||
AppEvent::OpenUrlInBrowser { url } => Some(url.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(urls, destination.into_iter().collect::<Vec<_>>());
|
||||
assert!(
|
||||
!queued
|
||||
.iter()
|
||||
.any(|event| matches!(event, AppEvent::CodexOp(AppCommand::UserTurn { .. })))
|
||||
);
|
||||
assert_eq!(chat.composer_text_with_pending(), "saved draft");
|
||||
// A periodic usage reply must not reopen a selector the user just closed.
|
||||
chat.update_backend_banner(&response);
|
||||
let rendered = normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 90));
|
||||
assert!(!rendered.contains("You’re now using Luna"));
|
||||
assert!(rendered.contains("saved draft"));
|
||||
assert!(rendered.contains("Luna Reserve"));
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn luna_reserve_status_tracks_the_active_model() {
|
||||
let (mut chat, _rx, _ops) = make_chatwidget_manual(Some("gpt-5.6-sol")).await;
|
||||
chat.has_chatgpt_account = true;
|
||||
chat.on_rate_limit_snapshot(Some(reserve_snapshot(
|
||||
/*primary_used*/ 25, /*weekly_used*/ 60,
|
||||
)));
|
||||
assert!(
|
||||
!normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80))
|
||||
.contains("Luna Reserve")
|
||||
);
|
||||
|
||||
chat.set_model("gpt-reserve");
|
||||
let rendered = normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80));
|
||||
assert!(rendered.contains("Luna Reserve default"));
|
||||
insta::assert_snapshot!("luna_reserve_usage_wide", rendered);
|
||||
insta::assert_snapshot!(
|
||||
"luna_reserve_usage_narrow",
|
||||
normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 34))
|
||||
);
|
||||
|
||||
chat.set_model("gpt-5.6-sol");
|
||||
assert!(
|
||||
!normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80))
|
||||
.contains("Luna Reserve")
|
||||
);
|
||||
chat.set_model("gpt-reserve");
|
||||
assert!(
|
||||
normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80)).contains("Luna Reserve")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn luna_reserve_usage_survives_banner_dismissal_and_typing_during_a_turn() {
|
||||
let (mut chat, _rx, _ops) = make_chatwidget_manual(Some("gpt-reserve")).await;
|
||||
chat.has_chatgpt_account = true;
|
||||
chat.on_rate_limit_snapshot(Some(reserve_snapshot(
|
||||
/*primary_used*/ 48, /*weekly_used*/ 20,
|
||||
)));
|
||||
let response = codex_app_server_protocol::GetAccountRateLimitsResponse {
|
||||
ordinary_usage_allowed: Some(false),
|
||||
account_id: Some("account-preview".into()),
|
||||
rate_limits: snapshot(/*percent*/ 100.0),
|
||||
rate_limits_by_limit_id: None,
|
||||
rate_limit_reset_credits: None,
|
||||
rate_limit_upsell: Some(json!({
|
||||
"banner_type": "luna_reserve", "presentation": "dismissible",
|
||||
"title": "You’re now using Luna, a faster model for simpler tasks.",
|
||||
"description": "Add credits or upgrade to continue using the most advanced models.",
|
||||
"ctas": [
|
||||
{"action": "add_credits", "label": "Add credits"},
|
||||
{"action": "open_pricing_dialog", "label": "Upgrade"}
|
||||
]
|
||||
})),
|
||||
};
|
||||
chat.update_backend_banner(&response);
|
||||
for colors in [
|
||||
DefaultColors {
|
||||
fg: (230, 230, 230),
|
||||
bg: (20, 20, 20),
|
||||
},
|
||||
DefaultColors {
|
||||
fg: (25, 25, 25),
|
||||
bg: (255, 255, 255),
|
||||
},
|
||||
] {
|
||||
with_test_default_colors(colors, || {
|
||||
let area = Rect::new(0, 0, 80, chat.bottom_pane.desired_height(/*width*/ 80));
|
||||
let mut buffer = Buffer::empty(area);
|
||||
chat.bottom_pane.render(area, &mut buffer);
|
||||
// Do not rely on the terminal's bold default foreground or dim important copy.
|
||||
for (y, text) in buffer
|
||||
.content
|
||||
.chunks(80)
|
||||
.enumerate()
|
||||
.filter_map(|(y, row)| {
|
||||
let text: String = row.iter().map(ratatui::buffer::Cell::symbol).collect();
|
||||
(text.contains("You’re now using Luna")
|
||||
|| text.contains("Add credits or upgrade"))
|
||||
.then_some((y as u16, text))
|
||||
})
|
||||
{
|
||||
let copy = &buffer[(2, y)];
|
||||
assert_eq!(copy.fg, crate::terminal_palette::rgb_color(colors.fg));
|
||||
assert!(
|
||||
!copy.modifier.contains(ratatui::style::Modifier::DIM),
|
||||
"{text}"
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
insta::assert_snapshot!(
|
||||
"luna_reserve_usage_with_upsell",
|
||||
normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80))
|
||||
);
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));
|
||||
assert!(
|
||||
!normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80))
|
||||
.contains("You’re now using Luna")
|
||||
);
|
||||
chat.bottom_pane.set_task_running(/*running*/ true);
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Char('x'), KeyModifiers::NONE));
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Left, KeyModifiers::NONE));
|
||||
let rendered = normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80));
|
||||
assert_eq!(chat.composer_text_with_pending(), "x");
|
||||
insta::assert_snapshot!("luna_reserve_usage_running", rendered);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn luna_reserve_prompt_preserves_the_composer_palette_on_exit() {
|
||||
let (mut chat, _rx, _ops) = make_chatwidget_manual(Some("gpt-reserve")).await;
|
||||
chat.has_chatgpt_account = true;
|
||||
chat.on_rate_limit_snapshot(Some(reserve_snapshot(
|
||||
/*primary_used*/ 25, /*weekly_used*/ 60,
|
||||
)));
|
||||
for colors in [
|
||||
DefaultColors {
|
||||
fg: (230, 230, 230),
|
||||
bg: (20, 20, 20),
|
||||
},
|
||||
DefaultColors {
|
||||
fg: (25, 25, 25),
|
||||
bg: (255, 255, 255),
|
||||
},
|
||||
] {
|
||||
with_test_default_colors(colors, || {
|
||||
chat.set_model("gpt-reserve");
|
||||
let area = Rect::new(0, 0, 80, chat.bottom_pane.desired_height(/*width*/ 80));
|
||||
let mut active = Buffer::empty(area);
|
||||
chat.bottom_pane.render(area, &mut active);
|
||||
let cursor = chat.bottom_pane.cursor_pos(area).expect("composer cursor");
|
||||
let ordinary_style = crate::style::user_message_style();
|
||||
assert_eq!(active[(0, cursor.1)].bg, ordinary_style.bg.unwrap());
|
||||
assert_eq!(active[(0, cursor.1)].bg, active[(0, cursor.1 - 1)].bg);
|
||||
chat.set_model("gpt-5.6-sol");
|
||||
let area = Rect::new(0, 0, 80, chat.bottom_pane.desired_height(/*width*/ 80));
|
||||
let mut inactive = Buffer::empty(area);
|
||||
chat.bottom_pane.render(area, &mut inactive);
|
||||
let restored_cursor = chat.bottom_pane.cursor_pos(area).expect("composer cursor");
|
||||
assert_eq!(
|
||||
inactive[(0, restored_cursor.1)].bg,
|
||||
ordinary_style.bg.unwrap()
|
||||
);
|
||||
assert_eq!(restored_cursor.1, cursor.1);
|
||||
});
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -1,11 +1,9 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/backend_banners_tests.rs
|
||||
assertion_line: 50
|
||||
expression: "render_bottom_popup(&chat, 70)"
|
||||
expression: "normalize_snapshot_paths(render_bottom_popup(&chat, 70))"
|
||||
---
|
||||
Selected model usage exhausted
|
||||
Ask your owner for credits or switch to another model.
|
||||
|
||||
› 1. Notify owner
|
||||
|
||||
Press a number to choose
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/luna_reserve_usage_tests.rs
|
||||
expression: "normalize_snapshot_paths(render_bottom_popup(&chat, 90))"
|
||||
---
|
||||
You’re now using Luna, a faster model for simpler tasks.
|
||||
Add credits or upgrade to continue using the most advanced models.
|
||||
|
||||
1. Add credits
|
||||
› 2. Upgrade
|
||||
3. Continue with Luna Reserve
|
||||
|
||||
Press enter to confirm or esc to continue working
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/luna_reserve_usage_tests.rs
|
||||
expression: "render_bottom_popup(&chat, 34)"
|
||||
---
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
Luna Reserve default · /tmp/pro…
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/luna_reserve_usage_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
• Working (0s • esc to interrupt)
|
||||
|
||||
|
||||
› x
|
||||
|
||||
tab to queue message 100% context left
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/luna_reserve_usage_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
Luna Reserve default · /tmp/project
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/luna_reserve_usage_tests.rs
|
||||
expression: "normalize_snapshot_paths(render_bottom_popup(&chat, 80))"
|
||||
---
|
||||
You’re now using Luna, a faster model for simpler tasks.
|
||||
Add credits or upgrade to continue using the most advanced models.
|
||||
|
||||
› 1. Add credits
|
||||
2. Upgrade
|
||||
3. Continue with Luna Reserve
|
||||
|
||||
Press enter to confirm or esc to continue working
|
||||
@@ -706,6 +706,7 @@ async fn status_line_uses_secondary_fallback_for_unsupported_window() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: None,
|
||||
secondary: Some(RateLimitWindow {
|
||||
used_percent: 50,
|
||||
@@ -732,6 +733,7 @@ async fn status_line_legacy_limit_items_prefer_matching_windows() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 94,
|
||||
window_duration_mins: Some(7 * 24 * 60),
|
||||
@@ -766,6 +768,7 @@ async fn status_line_shows_secondary_non_weekly_when_primary_is_weekly() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 94,
|
||||
window_duration_mins: Some(7 * 24 * 60),
|
||||
@@ -800,6 +803,7 @@ async fn status_line_five_hour_item_omits_weekly_only_limit() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 9,
|
||||
window_duration_mins: Some(7 * 24 * 60),
|
||||
@@ -830,6 +834,7 @@ async fn status_line_single_monthly_primary_omits_weekly_limit_item() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 35,
|
||||
window_duration_mins: Some(30 * 24 * 60),
|
||||
@@ -860,6 +865,7 @@ async fn status_line_secondary_only_non_weekly_limit_omits_primary_limit_item()
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: None,
|
||||
secondary: Some(RateLimitWindow {
|
||||
used_percent: 35,
|
||||
@@ -890,7 +896,12 @@ async fn rate_limit_snapshot_keeps_prior_credits_when_missing_from_headers() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
primary: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 10,
|
||||
window_duration_mins: Some(60),
|
||||
resets_at: Some(123),
|
||||
}),
|
||||
secondary: None,
|
||||
credits: Some(CreditsSnapshot {
|
||||
has_credits: true,
|
||||
@@ -912,6 +923,7 @@ async fn rate_limit_snapshot_keeps_prior_credits_when_missing_from_headers() {
|
||||
chat.on_rolling_rate_limit_snapshot(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 80,
|
||||
window_duration_mins: Some(60),
|
||||
@@ -938,7 +950,7 @@ async fn rate_limit_snapshot_keeps_prior_credits_when_missing_from_headers() {
|
||||
assert!(!credits.unlimited);
|
||||
assert_eq!(
|
||||
display.primary.as_ref().map(|window| window.used_percent),
|
||||
Some(80.0)
|
||||
Some(10.0)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -983,6 +995,7 @@ async fn rate_limit_snapshot_updates_and_retains_plan_type() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 10,
|
||||
window_duration_mins: Some(60),
|
||||
@@ -1004,6 +1017,7 @@ async fn rate_limit_snapshot_updates_and_retains_plan_type() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 25,
|
||||
window_duration_mins: Some(30),
|
||||
@@ -1025,6 +1039,7 @@ async fn rate_limit_snapshot_updates_and_retains_plan_type() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 30,
|
||||
window_duration_mins: Some(60),
|
||||
@@ -1051,6 +1066,7 @@ async fn rate_limit_snapshots_keep_separate_entries_per_limit_id() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: Some("codex".to_string()),
|
||||
limit_name: Some("codex".to_string()),
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 20,
|
||||
window_duration_mins: Some(300),
|
||||
@@ -1071,6 +1087,7 @@ async fn rate_limit_snapshots_keep_separate_entries_per_limit_id() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: Some("codex_other".to_string()),
|
||||
limit_name: Some("codex_other".to_string()),
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 90,
|
||||
window_duration_mins: Some(60),
|
||||
@@ -1126,6 +1143,7 @@ async fn rate_limit_switch_prompt_skips_non_codex_limit() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: Some("codex_other".to_string()),
|
||||
limit_name: Some("codex_other".to_string()),
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 95,
|
||||
window_duration_mins: Some(60),
|
||||
|
||||
@@ -67,6 +67,7 @@ fn cache_rate_limit_snapshot(chat: &mut ChatWidget) {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 35,
|
||||
window_duration_mins: Some(30 * 24 * 60),
|
||||
@@ -353,6 +354,7 @@ async fn status_surface_preview_omits_unavailable_rate_limit_items() {
|
||||
chat.on_rate_limit_snapshot(Some(RateLimitSnapshot {
|
||||
limit_id: None,
|
||||
limit_name: None,
|
||||
normal_model_slug: None,
|
||||
primary: Some(RateLimitWindow {
|
||||
used_percent: 9,
|
||||
window_duration_mins: Some(7 * 24 * 60),
|
||||
|
||||
@@ -401,6 +401,7 @@ impl ChatWidget {
|
||||
}
|
||||
|
||||
pub(super) fn on_rate_limit_error(&mut self, error_kind: RateLimitErrorKind, message: String) {
|
||||
self.invalidate_ordinary_usage_recovery();
|
||||
// on_error can drain queued input, before the asynchronous recovery read completes.
|
||||
self.input_queue.rate_limit_recovery_pending = self.has_chatgpt_account;
|
||||
let usage_limit_error = matches!(error_kind, RateLimitErrorKind::UsageLimit);
|
||||
|
||||
Reference in new issue
Block a user