mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Fix stale /status rate limits in active TUI sessions (#16201)
Fix stale weekly limit in `/status` (#16194): /status reused the session’s cached rate-limit snapshot, so the weekly remaining limit could stay frozen within an active session. With this change, we now dynamically update the rate limits after status is displayed. I needed to delete a few low-value test cases from the chatWidget tests because the test.rs file is really large, and the new tests in this PR pushed us over the 512K mandated limit. I'm working on a separate PR to refactor that test file.
This commit is contained in:
1 parent
424e532a6b
commit
ae057e0bb9
12 files changed
+487
-42
No files matched your search
@@ -57,6 +57,7 @@ use crate::model_catalog::ModelCatalog;
|
||||
use crate::multi_agents;
|
||||
use crate::status::RateLimitWindowDisplay;
|
||||
use crate::status::StatusAccountDisplay;
|
||||
use crate::status::StatusHistoryHandle;
|
||||
use crate::status::format_directory_display;
|
||||
use crate::status::format_tokens_compact;
|
||||
use crate::status::rate_limit_snapshot_display_for_limit;
|
||||
@@ -761,6 +762,8 @@ pub(crate) struct ChatWidget {
|
||||
status_account_display: Option<StatusAccountDisplay>,
|
||||
token_info: Option<TokenUsageInfo>,
|
||||
rate_limit_snapshots_by_limit_id: BTreeMap<String, RateLimitSnapshotDisplay>,
|
||||
refreshing_status_outputs: Vec<(u64, StatusHistoryHandle)>,
|
||||
next_status_refresh_request_id: u64,
|
||||
plan_type: Option<PlanType>,
|
||||
rate_limit_warnings: RateLimitWarningState,
|
||||
rate_limit_switch_prompt: RateLimitSwitchPromptState,
|
||||
@@ -4705,6 +4708,8 @@ impl ChatWidget {
|
||||
status_account_display,
|
||||
token_info: None,
|
||||
rate_limit_snapshots_by_limit_id: BTreeMap::new(),
|
||||
refreshing_status_outputs: Vec::new(),
|
||||
next_status_refresh_request_id: 0,
|
||||
plan_type: initial_plan_type,
|
||||
rate_limit_warnings: RateLimitWarningState::default(),
|
||||
rate_limit_switch_prompt: RateLimitSwitchPromptState::default(),
|
||||
@@ -5328,7 +5333,18 @@ impl ChatWidget {
|
||||
self.open_skills_menu();
|
||||
}
|
||||
SlashCommand::Status => {
|
||||
self.add_status_output();
|
||||
if self.should_prefetch_rate_limits() {
|
||||
let request_id = self.next_status_refresh_request_id;
|
||||
self.next_status_refresh_request_id =
|
||||
self.next_status_refresh_request_id.wrapping_add(1);
|
||||
self.add_status_output(/*refreshing_rate_limits*/ true, Some(request_id));
|
||||
self.app_event_tx
|
||||
.send(AppEvent::RefreshRateLimits { request_id });
|
||||
} else {
|
||||
self.add_status_output(
|
||||
/*refreshing_rate_limits*/ false, /*request_id*/ None,
|
||||
);
|
||||
}
|
||||
}
|
||||
SlashCommand::DebugConfig => {
|
||||
self.add_debug_config_output();
|
||||
@@ -7344,7 +7360,11 @@ impl ChatWidget {
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
pub(crate) fn add_status_output(&mut self) {
|
||||
pub(crate) fn add_status_output(
|
||||
&mut self,
|
||||
refreshing_rate_limits: bool,
|
||||
request_id: Option<u64>,
|
||||
) {
|
||||
let default_usage = TokenUsage::default();
|
||||
let token_info = self.token_info.as_ref();
|
||||
let total_usage = token_info
|
||||
@@ -7357,7 +7377,7 @@ impl ChatWidget {
|
||||
.values()
|
||||
.cloned()
|
||||
.collect();
|
||||
self.add_to_history(crate::status::new_status_output_with_rate_limits(
|
||||
let (cell, handle) = crate::status::new_status_output_with_rate_limits_handle(
|
||||
&self.config,
|
||||
self.status_account_display.as_ref(),
|
||||
token_info,
|
||||
@@ -7371,7 +7391,39 @@ impl ChatWidget {
|
||||
self.model_display_name(),
|
||||
collaboration_mode,
|
||||
reasoning_effort_override,
|
||||
));
|
||||
refreshing_rate_limits,
|
||||
);
|
||||
if let Some(request_id) = request_id {
|
||||
self.refreshing_status_outputs.push((request_id, handle));
|
||||
}
|
||||
self.add_to_history(cell);
|
||||
}
|
||||
|
||||
pub(crate) fn finish_status_rate_limit_refresh(&mut self, request_id: u64) {
|
||||
if self.refreshing_status_outputs.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let rate_limit_snapshots: Vec<RateLimitSnapshotDisplay> = self
|
||||
.rate_limit_snapshots_by_limit_id
|
||||
.values()
|
||||
.cloned()
|
||||
.collect();
|
||||
let now = Local::now();
|
||||
let mut remaining = Vec::with_capacity(self.refreshing_status_outputs.len());
|
||||
let mut updated_any = false;
|
||||
for (pending_request_id, handle) in self.refreshing_status_outputs.drain(..) {
|
||||
if pending_request_id == request_id {
|
||||
updated_any = true;
|
||||
handle.finish_rate_limit_refresh(rate_limit_snapshots.as_slice(), now);
|
||||
} else {
|
||||
remaining.push((pending_request_id, handle));
|
||||
}
|
||||
}
|
||||
self.refreshing_status_outputs = remaining;
|
||||
if updated_any {
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn add_debug_config_output(&mut self) {
|
||||
|
||||
Reference in new issue
Block a user