Option to Notify Workspace Owner When Usage Limit is Reached (#16969)

## Summary
- Replace the manual `/notify-owner` flow with an inline confirmation
prompt when a usage-based workspace member hits a credits-depleted
limit.
- Fetch the current workspace role from the live ChatGPT
`accounts/check/v4-2023-04-27` endpoint so owner/member behavior matches
the desktop and web clients.
- Keep owner, member, and spend-cap messaging distinct so we only offer
the owner nudge when the workspace is actually out of credits.

## What Changed
- `backend-client`
- Added a typed fetch for the current account role from
`accounts/check`.
  - Mapped backend role values into a Rust workspace-role enum.
- `app-server` and protocol
  - Added `workspaceRole` to `account/read` and `account/updated`.
- Derived `isWorkspaceOwner` from the live role, with a fallback to the
cached token claim when the role fetch is unavailable.
- `tui`
  - Removed the explicit `/notify-owner` slash command.
- When a member is blocked because the workspace is out of credits, the
error now prompts:
- `Your workspace is out of credits. Request more from your workspace
owner? [y/N]`
  - Choosing `y` sends the existing owner-notification request.
- Choosing `n`, pressing `Esc`, or accepting the default selection
dismisses the prompt without sending anything.
- Selection popups now honor explicit item shortcuts, which is how the
`y` / `n` interaction is wired.

## Reviewer Notes
- The main behavior change is scoped to usage-based workspace members
whose workspace credits are depleted.
- Spend-cap reached should not show the owner-notification prompt.
- Owners and admins should continue to see `/usage` guidance instead of
the member prompt.
- The live role fetch is best-effort; if it fails, we fall back to the
existing token-derived ownership signal.

## Testing
- Manual verification
  - Workspace owner does not see the member prompt.
- Workspace member with depleted credits sees the confirmation prompt
and can send the nudge with `y`.
- Workspace member with spend cap reached does not see the
owner-notification prompt.

### Workspace member out of usage

https://github.com/user-attachments/assets/341ac396-eff4-4a7f-bf0c-60660becbea1

### Workspace owner
<img width="1728" height="1086" alt="Screenshot 2026-04-09 at 11 48
22 AM"
src="https://github.com/user-attachments/assets/06262a45-e3fc-4cc4-8326-1cbedad46ed6"
/>
This commit is contained in:
richardopenai authored and GitHub committed 2026-04-09 21:15:17 -07:00
1 parent 36712d8546
commit 9f2a585153
82 files changed
+3233 -60

No files matched your search

+63
View File
@@ -537,6 +537,9 @@ impl ThreadEventStore {
ThreadBufferedEvent::Request(_)
| ThreadBufferedEvent::Notification(ServerNotification::HookStarted(_))
| ThreadBufferedEvent::Notification(ServerNotification::HookCompleted(_))
| ThreadBufferedEvent::Notification(
ServerNotification::AddCreditsNudgeEmailCompleted(_),
)
| ThreadBufferedEvent::FeedbackSubmission(_)
)
}
@@ -1096,6 +1099,8 @@ impl App {
feedback: self.feedback.clone(),
is_first_run: false,
status_account_display: self.chat_widget.status_account_display().cloned(),
initial_workspace_role: self.chat_widget.current_workspace_role(),
initial_is_workspace_owner: self.chat_widget.current_is_workspace_owner(),
initial_plan_type: self.chat_widget.current_plan_type(),
model: Some(self.chat_widget.current_model().to_string()),
startup_tooltip_override: None,
@@ -2426,6 +2431,10 @@ impl App {
.await?;
Ok(true)
}
AppCommandView::SendAddCreditsNudgeEmail => {
app_server.thread_add_credits_nudge_email(thread_id).await?;
Ok(true)
}
AppCommandView::ReloadUserConfig => {
app_server.reload_user_config().await?;
Ok(true)
@@ -3649,6 +3658,8 @@ impl App {
let has_chatgpt_account = bootstrap.has_chatgpt_account;
let requires_openai_auth = bootstrap.requires_openai_auth;
let status_account_display = bootstrap.status_account_display.clone();
let initial_workspace_role = bootstrap.workspace_role;
let initial_is_workspace_owner = bootstrap.is_workspace_owner;
let initial_plan_type = bootstrap.plan_type;
let session_telemetry = SessionTelemetry::new(
ThreadId::new(),
@@ -3698,6 +3709,8 @@ impl App {
feedback: feedback.clone(),
is_first_run,
status_account_display: status_account_display.clone(),
initial_workspace_role,
initial_is_workspace_owner,
initial_plan_type,
model: Some(model.clone()),
startup_tooltip_override,
@@ -3732,6 +3745,8 @@ impl App {
feedback: feedback.clone(),
is_first_run,
status_account_display: status_account_display.clone(),
initial_workspace_role,
initial_is_workspace_owner,
initial_plan_type,
model: config.model.clone(),
startup_tooltip_override: None,
@@ -3771,6 +3786,8 @@ impl App {
feedback: feedback.clone(),
is_first_run,
status_account_display: status_account_display.clone(),
initial_workspace_role,
initial_is_workspace_owner,
initial_plan_type,
model: config.model.clone(),
startup_tooltip_override: None,
@@ -4549,6 +4566,23 @@ impl App {
}
}
},
AppEvent::NotifyWorkspaceOwner => {
if self.active_thread_id.is_some() {
self.chat_widget.start_notify_workspace_owner();
if let Err(err) = self
.submit_active_thread_op(app_server, Op::SendAddCreditsNudgeEmail.into())
.await
{
self.chat_widget
.finish_notify_workspace_owner(Err(err.to_string()));
return Err(err);
}
} else {
self.chat_widget.finish_notify_workspace_owner(Err(
"no active thread is available".to_string(),
));
}
}
AppEvent::ConnectorsLoaded { result, is_final } => {
self.chat_widget.on_connectors_loaded(result, is_final);
}
@@ -6329,6 +6363,8 @@ mod tests {
use crate::multi_agents::AgentPickerThreadEntry;
use assert_matches::assert_matches;
use codex_app_server_protocol::AddCreditsNudgeEmailNotification;
use codex_app_server_protocol::AddCreditsNudgeEmailResult;
use codex_app_server_protocol::AdditionalFileSystemPermissions;
use codex_app_server_protocol::AdditionalNetworkPermissions;
use codex_app_server_protocol::AdditionalPermissionProfile;
@@ -6716,6 +6752,8 @@ mod tests {
feedback: codex_feedback::CodexFeedback::new(),
is_first_run: false,
status_account_display: None,
initial_workspace_role: None,
initial_is_workspace_owner: None,
initial_plan_type: None,
model: Some(model),
startup_tooltip_override: None,
@@ -9619,6 +9657,29 @@ guardian_approval = true
);
}
#[test]
fn thread_event_store_rebase_preserves_add_credits_nudge_email_completion() {
let thread_id = ThreadId::new();
let mut store = ThreadEventStore::new(/*capacity*/ 8);
let notification =
ServerNotification::AddCreditsNudgeEmailCompleted(AddCreditsNudgeEmailNotification {
thread_id: thread_id.to_string(),
result: AddCreditsNudgeEmailResult::Sent,
});
store.push_notification(notification.clone());
store.rebase_buffer_after_session_refresh();
let snapshot = store.snapshot();
let [ThreadBufferedEvent::Notification(actual)] = snapshot.events.as_slice() else {
panic!("expected add-credits nudge email completion notification");
};
assert_eq!(
serde_json::to_value(actual).expect("notification should serialize"),
serde_json::to_value(notification).expect("notification should serialize"),
);
}
#[test]
fn build_feedback_upload_params_includes_thread_id_and_rollout_path() {
let thread_id = ThreadId::new();
@@ -10680,6 +10741,8 @@ guardian_approval = true
feedback: app.feedback.clone(),
is_first_run: false,
status_account_display: app.chat_widget.status_account_display().cloned(),
initial_workspace_role: app.chat_widget.current_workspace_role(),
initial_is_workspace_owner: app.chat_widget.current_is_workspace_owner(),
initial_plan_type: app.chat_widget.current_plan_type(),
model: Some(app.chat_widget.current_model().to_string()),
startup_tooltip_override: None,