mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:50:52 +00:00
Use the current billing plan for TUI thread usage (#61978)
## Why Account reads can use a cached subscription plan, and rolling quota updates can carry an obsolete plan. This can leave thread usage unavailable or cause `/status` to display costs using the wrong billing model. ## What changed - Prefer a known plan from a full Codex quota read over the account plan, regardless of reply order. Ignore unknown quota plans and prevent rolling updates from changing the billing plan. - Preserve quota plan state across chat widget replacement and apply accepted quota reads even after the requesting status card is gone. - Refresh thread usage availability when the plan changes and pair asynchronous `/status` estimates with the corrected plan, including native dollar usage for `Ent26`. ## Testing Add regression tests for reply ordering, unknown plans, corrected pending status cards, obsolete rolling updates, and quota replies arriving after widget replacement. GitOrigin-RevId: 238fadb587fe98cda0eeb5111c1949928acc8153
This commit is contained in:
@@ -56,6 +56,25 @@ pub(super) struct ThreadUsageState {
|
||||
}
|
||||
|
||||
impl ChatWidget {
|
||||
pub(super) fn refresh_billing_plan(&mut self) {
|
||||
// A full quota read reflects the current subscription; account/read can use a cached token.
|
||||
let plan = self.quota_plan.or(self.account_plan);
|
||||
if self.plan_type == plan {
|
||||
return;
|
||||
}
|
||||
let previously_available = self.thread_usage_is_available();
|
||||
self.plan_type = plan;
|
||||
if !self.thread_usage_is_available() {
|
||||
self.clear_thread_usage_state();
|
||||
} else if !previously_available {
|
||||
// A pending /status can learn that the account is billable from its own quota read.
|
||||
for (_, handle) in self.refreshing_status_outputs.clone() {
|
||||
handle.reserve_thread_usage_label_width();
|
||||
self.request_thread_usage_for_status(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn clear_thread_usage_state(&mut self) {
|
||||
self.thread_usage = ThreadUsageState::default();
|
||||
}
|
||||
@@ -299,7 +318,7 @@ impl ChatWidget {
|
||||
}
|
||||
if usage_updated && !self.thread_usage.status_history_handles.is_empty() {
|
||||
for handle in &self.thread_usage.status_history_handles {
|
||||
handle.set_thread_usage(self.thread_usage.estimate.clone());
|
||||
handle.set_thread_usage(self.thread_usage.estimate.clone(), self.plan_type);
|
||||
}
|
||||
if self
|
||||
.thread_usage
|
||||
|
||||
Reference in New Issue
Block a user