Revert "Option to Notify Workspace Owner When Usage Limit is Reached" (#17391)

Reverts openai/codex#16969

#sev3-2026-04-10-accountscheckversion-500s-for-openai-workspace-7300
This commit is contained in:
Shijie Rao authored and GitHub committed 2026-04-10 23:33:13 +00:00
1 parent a3be74143a
commit 930e5adb7e
82 files changed
+60 -3233

No files matched your search

+6 -339
View File
@@ -67,7 +67,6 @@ use crate::terminal_title::clear_terminal_title;
use crate::terminal_title::set_terminal_title;
use crate::text_formatting::proper_join;
use crate::version::CODEX_CLI_VERSION;
use codex_app_server_protocol::AddCreditsNudgeEmailResult as AppServerAddCreditsNudgeEmailResult;
use codex_app_server_protocol::AppSummary;
use codex_app_server_protocol::CodexErrorInfo as AppServerCodexErrorInfo;
use codex_app_server_protocol::CollabAgentState as AppServerCollabAgentState;
@@ -92,7 +91,6 @@ use codex_app_server_protocol::Turn;
use codex_app_server_protocol::TurnCompletedNotification;
use codex_app_server_protocol::TurnPlanStepStatus;
use codex_app_server_protocol::TurnStatus;
use codex_app_server_protocol::WorkspaceRole as AppServerWorkspaceRole;
use codex_chatgpt::connectors;
use codex_config::types::ApprovalsReviewer;
use codex_config::types::Notifications;
@@ -135,7 +133,6 @@ use codex_protocol::models::local_image_label_text;
use codex_protocol::parse_command::ParsedCommand;
use codex_protocol::plan_tool::PlanItemArg as UpdatePlanItemArg;
use codex_protocol::plan_tool::StepStatus as UpdatePlanItemStatus;
use codex_protocol::protocol::AddCreditsNudgeEmailStatus;
#[cfg(test)]
use codex_protocol::protocol::AgentMessageDeltaEvent;
#[cfg(test)]
@@ -195,7 +192,6 @@ use codex_protocol::protocol::RateLimitSnapshot;
use codex_protocol::protocol::ReviewRequest;
use codex_protocol::protocol::ReviewTarget;
use codex_protocol::protocol::SkillMetadata as ProtocolSkillMetadata;
use codex_protocol::protocol::SpendControlSnapshot;
#[cfg(test)]
use codex_protocol::protocol::StreamErrorEvent;
use codex_protocol::protocol::TerminalInteractionEvent;
@@ -561,8 +557,6 @@ pub(crate) struct ChatWidgetInit {
pub(crate) feedback: codex_feedback::CodexFeedback,
pub(crate) is_first_run: bool,
pub(crate) status_account_display: Option<StatusAccountDisplay>,
pub(crate) initial_workspace_role: Option<AppServerWorkspaceRole>,
pub(crate) initial_is_workspace_owner: Option<bool>,
pub(crate) initial_plan_type: Option<PlanType>,
pub(crate) model: Option<String>,
pub(crate) startup_tooltip_override: Option<String>,
@@ -609,32 +603,6 @@ enum RateLimitErrorKind {
Generic,
}
pub(crate) const CODEX_USAGE_SETTINGS_URL: &str = "https://chatgpt.com/codex/settings/usage";
const WORKSPACE_OWNER_NOTIFICATION_PROMPT: &str =
"Your workspace is out of credits. Request more from your workspace owner? [y/N]";
const WORKSPACE_OWNER_NOTIFICATION_TITLE: &str = "Request more credits from your workspace owner?";
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum UsageBasedWorkspaceRateLimitState {
OwnerCreditsDepleted,
OwnerSpendCapReached,
MemberCreditsDepleted,
MemberSpendCapReached,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum UsageBasedWorkspaceBlockKind {
CreditsDepleted,
SpendCapReached,
}
fn is_usage_based_workspace_plan(plan_type: PlanType) -> bool {
matches!(
plan_type,
PlanType::SelfServeBusinessUsageBased | PlanType::EnterpriseCbpUsageBased
)
}
#[cfg(test)]
fn core_rate_limit_error_kind(info: &CoreCodexErrorInfo) -> Option<RateLimitErrorKind> {
match info {
@@ -790,8 +758,6 @@ pub(crate) struct ChatWidget {
/// The currently active collaboration mask, if any.
active_collaboration_mask: Option<CollaborationModeMask>,
has_chatgpt_account: bool,
workspace_role: Option<AppServerWorkspaceRole>,
is_workspace_owner: Option<bool>,
model_catalog: Arc<ModelCatalog>,
session_telemetry: SessionTelemetry,
session_header: SessionHeader,
@@ -802,8 +768,6 @@ pub(crate) struct ChatWidget {
refreshing_status_outputs: Vec<(u64, StatusHistoryHandle)>,
next_status_refresh_request_id: u64,
plan_type: Option<PlanType>,
notify_workspace_owner_in_flight: bool,
pending_workspace_owner_notification_prompt: bool,
rate_limit_warnings: RateLimitWarningState,
rate_limit_switch_prompt: RateLimitSwitchPromptState,
adaptive_chunking: AdaptiveChunkingPolicy,
@@ -2721,15 +2685,6 @@ impl ChatWidget {
balance: credits.balance.clone(),
});
}
if snapshot.spend_control.is_none() {
snapshot.spend_control = self
.rate_limit_snapshots_by_limit_id
.get(&limit_id)
.and_then(|display| display.spend_control.as_ref())
.map(|spend_control| SpendControlSnapshot {
reached: spend_control.reached,
});
}
self.plan_type = snapshot.plan_type.or(self.plan_type);
@@ -2798,7 +2753,6 @@ impl ChatWidget {
} else {
self.rate_limit_snapshots_by_limit_id.clear();
}
self.maybe_show_pending_workspace_owner_notification_prompt();
self.refresh_status_line();
}
/// Finalize any active exec as failed and stop/clear agent-turn UI state.
@@ -2841,34 +2795,15 @@ impl ChatWidget {
}
fn on_error(&mut self, message: String) {
self.on_error_with_hint(message, /*hint*/ None);
}
fn on_error_with_hint(&mut self, message: String, hint: Option<String>) {
self.submit_pending_steers_after_interrupt = false;
self.finalize_turn();
self.add_to_history(history_cell::new_error_event_with_hint(message, hint));
self.add_to_history(history_cell::new_error_event(message));
self.request_redraw();
// After an error ends the turn, try sending the next queued input.
self.maybe_send_next_queued_input();
}
fn on_rate_limit_error(&mut self, message: String) {
if self.should_prefetch_rate_limits() {
self.request_rate_limit_refresh();
}
let guidance = self.usage_based_workspace_rate_limit_error_guidance();
let should_prompt_workspace_owner = self.should_prompt_workspace_owner_notification();
let hint = guidance.as_ref().and_then(|(_, hint)| hint.clone());
let message = guidance.map(|(message, _)| message).unwrap_or(message);
self.on_error_with_hint(message, hint);
if should_prompt_workspace_owner {
self.pending_workspace_owner_notification_prompt = true;
self.maybe_show_pending_workspace_owner_notification_prompt();
}
}
fn handle_non_retry_error(
&mut self,
message: String,
@@ -2885,7 +2820,7 @@ impl ChatWidget {
match info {
RateLimitErrorKind::ServerOverloaded => self.on_server_overloaded_error(message),
RateLimitErrorKind::UsageLimit | RateLimitErrorKind::Generic => {
self.on_rate_limit_error(message);
self.on_error(message)
}
}
} else {
@@ -4778,8 +4713,6 @@ impl ChatWidget {
feedback,
is_first_run,
status_account_display,
initial_workspace_role,
initial_is_workspace_owner,
initial_plan_type,
model,
startup_tooltip_override,
@@ -4841,8 +4774,6 @@ impl ChatWidget {
current_collaboration_mode,
active_collaboration_mask,
has_chatgpt_account,
workspace_role: initial_workspace_role,
is_workspace_owner: initial_is_workspace_owner,
model_catalog,
session_telemetry,
session_header: SessionHeader::new(header_model),
@@ -4853,8 +4784,6 @@ impl ChatWidget {
refreshing_status_outputs: Vec::new(),
next_status_refresh_request_id: 0,
plan_type: initial_plan_type,
notify_workspace_owner_in_flight: false,
pending_workspace_owner_notification_prompt: false,
rate_limit_warnings: RateLimitWarningState::default(),
rate_limit_switch_prompt: RateLimitSwitchPromptState::default(),
adaptive_chunking: AdaptiveChunkingPolicy::default(),
@@ -5495,7 +5424,9 @@ impl ChatWidget {
}
SlashCommand::Status => {
if self.should_prefetch_rate_limits() {
let request_id = self.next_rate_limit_refresh_request_id();
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 {
origin: RateLimitRefreshOrigin::StatusCommand { request_id },
@@ -6756,18 +6687,6 @@ impl ChatWidget {
);
}
}
ServerNotification::AddCreditsNudgeEmailCompleted(notification) => {
let result = match notification.result {
AppServerAddCreditsNudgeEmailResult::Sent => {
Ok(AddCreditsNudgeEmailStatus::Sent)
}
AppServerAddCreditsNudgeEmailResult::CooldownActive => {
Ok(AddCreditsNudgeEmailStatus::CooldownActive)
}
AppServerAddCreditsNudgeEmailResult::Failed { message } => Err(message),
};
self.finish_notify_workspace_owner(result);
}
ServerNotification::ThreadRealtimeSdp(notification) => {
if !from_replay {
self.on_realtime_conversation_sdp(notification.sdp);
@@ -7183,7 +7102,7 @@ impl ChatWidget {
self.on_server_overloaded_error(message)
}
RateLimitErrorKind::UsageLimit | RateLimitErrorKind::Generic => {
self.on_rate_limit_error(message)
self.on_error(message)
}
}
} else {
@@ -7239,9 +7158,6 @@ impl ChatWidget {
EventMsg::GetHistoryEntryResponse(ev) => self.handle_history_entry_response(ev),
EventMsg::McpListToolsResponse(ev) => self.on_list_mcp_tools(ev),
EventMsg::ListSkillsResponse(ev) => self.on_list_skills(ev),
EventMsg::AddCreditsNudgeEmailResponse(ev) => {
self.finish_notify_workspace_owner(ev.result);
}
EventMsg::SkillsUpdateAvailable => {
self.submit_op(AppCommand::list_skills(
Vec::new(),
@@ -9781,268 +9697,19 @@ impl ChatWidget {
self.plan_type
}
pub(crate) fn current_is_workspace_owner(&self) -> Option<bool> {
self.workspace_role
.map(|role| {
matches!(
role,
AppServerWorkspaceRole::AccountOwner | AppServerWorkspaceRole::AccountAdmin
)
})
.or(self.is_workspace_owner)
}
pub(crate) fn current_workspace_role(&self) -> Option<AppServerWorkspaceRole> {
self.workspace_role
}
pub(crate) fn has_chatgpt_account(&self) -> bool {
self.has_chatgpt_account
}
fn usage_based_workspace_rate_limit_state(&self) -> Option<UsageBasedWorkspaceRateLimitState> {
let block_kind = self.usage_based_workspace_block_kind()?;
let is_workspace_owner = self.current_is_workspace_owner()?;
Some(match (is_workspace_owner, block_kind) {
(true, UsageBasedWorkspaceBlockKind::CreditsDepleted) => {
UsageBasedWorkspaceRateLimitState::OwnerCreditsDepleted
}
(true, UsageBasedWorkspaceBlockKind::SpendCapReached) => {
UsageBasedWorkspaceRateLimitState::OwnerSpendCapReached
}
(false, UsageBasedWorkspaceBlockKind::CreditsDepleted) => {
UsageBasedWorkspaceRateLimitState::MemberCreditsDepleted
}
(false, UsageBasedWorkspaceBlockKind::SpendCapReached) => {
UsageBasedWorkspaceRateLimitState::MemberSpendCapReached
}
})
}
fn usage_based_workspace_block_kind(&self) -> Option<UsageBasedWorkspaceBlockKind> {
let plan_type = self.plan_type?;
if !is_usage_based_workspace_plan(plan_type) {
return None;
}
let codex_snapshot = self.rate_limit_snapshots_by_limit_id.get("codex")?;
let credits_depleted = codex_snapshot
.credits
.as_ref()
.is_some_and(|credits| !credits.has_credits);
let spend_control_reached = codex_snapshot
.spend_control
.as_ref()
.map(|spend_control| spend_control.reached);
let blocked_state = match (credits_depleted, spend_control_reached) {
(true, _) => Some(true),
(false, Some(true)) => Some(false),
(false, Some(false)) => None,
// Older snapshots do not carry spend-control state, so preserve the
// historical interpretation for compatibility.
(false, None) => Some(false),
}?;
Some(match blocked_state {
true => UsageBasedWorkspaceBlockKind::CreditsDepleted,
false => UsageBasedWorkspaceBlockKind::SpendCapReached,
})
}
fn usage_based_workspace_rate_limit_error_guidance(&self) -> Option<(String, Option<String>)> {
if let Some(state) = self.usage_based_workspace_rate_limit_state() {
return match state {
UsageBasedWorkspaceRateLimitState::OwnerCreditsDepleted => Some((
"Your workspace is out of credits.".to_string(),
Some(format!(
"Visit {CODEX_USAGE_SETTINGS_URL} to add workspace credits and continue using Codex."
)),
)),
UsageBasedWorkspaceRateLimitState::OwnerSpendCapReached => Some((
"Your workspace has reached its spend cap.".to_string(),
Some(format!(
"Visit {CODEX_USAGE_SETTINGS_URL} to increase your workspace spend cap and continue using Codex."
)),
)),
UsageBasedWorkspaceRateLimitState::MemberCreditsDepleted => {
Some((WORKSPACE_OWNER_NOTIFICATION_PROMPT.to_string(), None))
}
UsageBasedWorkspaceRateLimitState::MemberSpendCapReached => Some((
"Your workspace has reached its spend cap.".to_string(),
Some(format!(
"Ask an admin to increase your workspace spend cap. Visit {CODEX_USAGE_SETTINGS_URL} for usage settings."
)),
)),
};
}
match self.usage_based_workspace_block_kind()? {
UsageBasedWorkspaceBlockKind::CreditsDepleted => Some((
"Your workspace is out of credits.".to_string(),
Some(format!(
"If you're the workspace owner, visit {CODEX_USAGE_SETTINGS_URL} to add credits. Otherwise wait a moment while Codex refreshes your workspace status."
)),
)),
UsageBasedWorkspaceBlockKind::SpendCapReached => Some((
"Your workspace has reached its spend cap.".to_string(),
Some(format!(
"Ask an admin to increase the workspace spend cap, or visit {CODEX_USAGE_SETTINGS_URL} for usage settings."
)),
)),
}
}
fn next_rate_limit_refresh_request_id(&mut self) -> u64 {
let request_id = self.next_status_refresh_request_id;
self.next_status_refresh_request_id = self.next_status_refresh_request_id.wrapping_add(1);
request_id
}
fn send_rate_limit_refresh_request(&self, request_id: u64) {
self.app_event_tx.send(AppEvent::RefreshRateLimits {
origin: RateLimitRefreshOrigin::StatusCommand { request_id },
});
}
fn request_rate_limit_refresh(&mut self) -> u64 {
let request_id = self.next_rate_limit_refresh_request_id();
self.send_rate_limit_refresh_request(request_id);
request_id
}
fn missing_usage_based_workspace_rate_limit_snapshot(&self) -> bool {
self.should_prefetch_rate_limits()
&& self.plan_type.is_some()
&& !self.rate_limit_snapshots_by_limit_id.contains_key("codex")
}
fn should_prompt_workspace_owner_notification(&self) -> bool {
if self.notify_workspace_owner_in_flight {
return false;
}
if matches!(
self.usage_based_workspace_rate_limit_state(),
Some(UsageBasedWorkspaceRateLimitState::MemberCreditsDepleted)
) {
return true;
}
let is_workspace_owner = self.current_is_workspace_owner();
if !self.plan_type.is_some_and(is_usage_based_workspace_plan)
|| is_workspace_owner == Some(true)
{
return false;
}
let block_kind = self.usage_based_workspace_block_kind();
block_kind != Some(UsageBasedWorkspaceBlockKind::SpendCapReached)
}
fn maybe_show_pending_workspace_owner_notification_prompt(&mut self) {
if !self.pending_workspace_owner_notification_prompt {
return;
}
if self.notify_workspace_owner_in_flight {
self.pending_workspace_owner_notification_prompt = false;
return;
}
if !self.bottom_pane.no_modal_or_popup_active() {
return;
}
match self.usage_based_workspace_rate_limit_state() {
Some(UsageBasedWorkspaceRateLimitState::MemberCreditsDepleted) => {
self.pending_workspace_owner_notification_prompt = false;
self.open_workspace_owner_notification_prompt();
}
Some(_) => {
self.pending_workspace_owner_notification_prompt = false;
}
None => {
if self.usage_based_workspace_block_kind()
== Some(UsageBasedWorkspaceBlockKind::CreditsDepleted)
&& self.current_is_workspace_owner().is_none()
{
return;
}
if !self.missing_usage_based_workspace_rate_limit_snapshot() {
self.pending_workspace_owner_notification_prompt = false;
}
}
}
}
fn open_workspace_owner_notification_prompt(&mut self) {
let items = vec![
SelectionItem {
name: "Yes".to_string(),
display_shortcut: Some(key_hint::plain(KeyCode::Char('y'))),
actions: vec![Box::new(|tx| tx.send(AppEvent::NotifyWorkspaceOwner))],
dismiss_on_select: true,
..Default::default()
},
SelectionItem {
name: "No".to_string(),
display_shortcut: Some(key_hint::plain(KeyCode::Char('n'))),
dismiss_on_select: true,
..Default::default()
},
];
self.bottom_pane.show_selection_view(SelectionViewParams {
title: Some(WORKSPACE_OWNER_NOTIFICATION_TITLE.to_string()),
footer_hint: Some(standard_popup_hint_line()),
items,
initial_selected_idx: Some(1),
..Default::default()
});
}
pub(crate) fn start_notify_workspace_owner(&mut self) {
self.notify_workspace_owner_in_flight = true;
self.pending_workspace_owner_notification_prompt = false;
}
pub(crate) fn finish_notify_workspace_owner(
&mut self,
result: Result<AddCreditsNudgeEmailStatus, String>,
) {
self.notify_workspace_owner_in_flight = false;
self.pending_workspace_owner_notification_prompt = false;
match result {
Ok(AddCreditsNudgeEmailStatus::Sent) => {
self.add_info_message("Workspace owner notified.".to_string(), /*hint*/ None);
}
Ok(AddCreditsNudgeEmailStatus::CooldownActive) => {
self.add_info_message(
"Workspace owner was already notified recently.".to_string(),
/*hint*/ None,
);
}
Err(_) => {
self.add_error_message(
"Could not notify your workspace owner. Please try again.".to_string(),
);
}
}
}
pub(crate) fn update_account_state(
&mut self,
status_account_display: Option<StatusAccountDisplay>,
workspace_role: Option<AppServerWorkspaceRole>,
is_workspace_owner: Option<bool>,
plan_type: Option<PlanType>,
has_chatgpt_account: bool,
) {
self.status_account_display = status_account_display;
self.workspace_role = workspace_role;
self.is_workspace_owner = is_workspace_owner;
self.plan_type = plan_type;
self.has_chatgpt_account = has_chatgpt_account;
self.maybe_show_pending_workspace_owner_notification_prompt();
self.bottom_pane
.set_connectors_enabled(self.connectors_enabled());
}