Restore the account email in /status after account updates (#50199)

## Why

Account-update notifications include authentication mode and plan information but
omit the email, causing `/status` to lose the signed-in account's email after an
update.

## What changed

Fetch the ChatGPT account email asynchronously after account updates, with a
30-second timeout, without blocking terminal input. Apply the result only if its
request ID is still current, invalidating pending results on subsequent account
updates and disconnects.

## Testing

Extend the account-update test to verify that the email is restored and a stale
result is ignored. Update the status snapshot to include the account email and
plan alongside credits and limits.

GitOrigin-RevId: 202421f78f3d6a7b373194f9c65d1c22d70a04c1
This commit is contained in:
Eric Traut
2026-10-02 06:22:31 +00:00
committed by copyberry
parent a20fe6335f
commit 3f97f2b3bd
13 changed files with 113 additions and 12 deletions
+2
View File
@@ -194,6 +194,7 @@ use tokio::task::JoinHandle;
use tokio_util::sync::CancellationToken;
use toml::Value as TomlValue;
use uuid::Uuid;
mod account_status;
mod agent_message_consolidation;
mod agent_navigation;
mod agent_picker;
@@ -654,6 +655,7 @@ pub(crate) struct App {
/// Keeps that boundary armed while a startup approval waits for the typing-idle timer.
startup_pending_protected_request: bool,
/// Invalidates in-flight full rate-limit reads when a newer rolling hard stop arrives.
account_email_request_id: Option<uuid::Uuid>,
rate_limit_hard_stop_generation: u64,
rate_limit_refresh_state: rate_limit_refresh::RateLimitRefreshState,
pending_mcp_login_start: Option<PendingMcpLoginStart>,
+44
View File
@@ -0,0 +1,44 @@
//! Refreshes the email omitted by account-update notifications without blocking terminal input.
//! Results carry a request ID so account changes and reconnects reject obsolete identities.
use super::App;
use crate::app_event::AppEvent;
use crate::app_server_session::AppServerSession;
use codex_app_server_protocol::Account;
use codex_app_server_protocol::ClientRequest;
use codex_app_server_protocol::GetAccountParams;
use codex_app_server_protocol::GetAccountResponse;
use codex_app_server_protocol::RequestId;
use std::time::Duration;
use uuid::Uuid;
impl App {
pub(super) fn refresh_account_email(&mut self, app_server: &AppServerSession) {
let request_id = Uuid::new_v4();
self.account_email_request_id = Some(request_id);
let request_handle = app_server.request_handle();
let app_event_tx = self.app_event_tx.clone();
tokio::spawn(async move {
let result = tokio::time::timeout(
Duration::from_secs(/*secs*/ 30),
request_handle.request_typed::<GetAccountResponse>(ClientRequest::GetAccount {
request_id: RequestId::String(format!("account-status-{request_id}")),
params: GetAccountParams {
refresh_token: false,
},
}),
)
.await;
match result {
Ok(Ok(response)) => {
if let Some(Account::Chatgpt { email, .. }) = response.account {
app_event_tx.send(AppEvent::AccountEmailLoaded { request_id, email });
}
}
Ok(Err(_)) | Err(_) => {
tracing::warn!("failed to read account identity after account update");
}
}
});
}
}
+12 -8
View File
@@ -349,18 +349,22 @@ impl App {
| AuthMode::PersonalAccessToken
)
);
self.chat_widget.update_account_state(
status_account_display_from_auth_mode(
notification.auth_mode,
notification.plan_type,
),
let account_display = status_account_display_from_auth_mode(
notification.auth_mode,
notification.plan_type,
notification
.auth_mode
.is_some_and(AuthMode::has_chatgpt_account),
);
let has_chatgpt_account = notification
.auth_mode
.is_some_and(AuthMode::has_chatgpt_account);
self.account_email_request_id = None;
self.chat_widget.update_account_state(
account_display,
notification.plan_type,
has_chatgpt_account,
has_codex_backend_auth,
);
if self.chat_widget.has_chatgpt_account() {
self.refresh_account_email(app_server_client);
crate::security_setup::prefetch(
&self.config,
app_server_client,
+6
View File
@@ -1267,6 +1267,12 @@ impl App {
elicitation_target: None,
});
}
AppEvent::AccountEmailLoaded { request_id, email } => {
if self.account_email_request_id == Some(request_id) {
self.account_email_request_id = None;
self.chat_widget.on_account_email_loaded(email);
}
}
AppEvent::SecuritySetupLoaded { request_id, identity, notice } => {
tracing::debug!(current = request_id == self.chat_widget.security_setup_request_id, "handling security setup notice");
if request_id == self.chat_widget.security_setup_request_id {
+1
View File
@@ -195,6 +195,7 @@ impl App {
}
self.retire_background_voice();
self.reconnect.offline = true;
self.account_email_request_id = None;
// Cached blank sessions are usable only while this connection owns a subscription.
self.agents_overview.blank_sessions.clear();
self.reconnect.failed = false;
+1
View File
@@ -933,6 +933,7 @@ See the Codex keymap documentation for supported actions and examples."
pending_managed_worktree_attach: None,
startup_protected_input_boundary: true,
startup_pending_protected_request: false,
account_email_request_id: None,
rate_limit_hard_stop_generation: 0,
rate_limit_refresh_state: Default::default(),
pending_mcp_login_start: None,
+1
View File
@@ -112,6 +112,7 @@ pub(crate) async fn make_test_app() -> App {
pending_managed_worktree_attach: None,
startup_protected_input_boundary: false,
startup_pending_protected_request: false,
account_email_request_id: None,
rate_limit_hard_stop_generation: 0,
rate_limit_refresh_state: Default::default(),
pending_mcp_login_start: None,
+2
View File
@@ -6151,6 +6151,7 @@ async fn make_test_app() -> Box<App> {
pending_managed_worktree_attach: None,
startup_protected_input_boundary: false,
startup_pending_protected_request: false,
account_email_request_id: None,
rate_limit_hard_stop_generation: 0,
rate_limit_refresh_state: Default::default(),
pending_mcp_login_start: None,
@@ -6270,6 +6271,7 @@ pub(super) async fn make_test_app_with_channels() -> (
pending_managed_worktree_attach: None,
startup_protected_input_boundary: false,
startup_pending_protected_request: false,
account_email_request_id: None,
rate_limit_hard_stop_generation: 0,
rate_limit_refresh_state: Default::default(),
pending_mcp_login_start: None,
@@ -3,6 +3,7 @@ use super::disconnect::serve_reconnect_requests;
use super::*;
use crate::app_server_session::ThreadParamsMode;
use crate::security_setup::Identity;
use crate::status::StatusAccountDisplay;
use app_test_support::ChatGptAuthFixture;
use app_test_support::write_chatgpt_auth;
use codex_app_server_client::AppServerEvent;
@@ -27,6 +28,7 @@ async fn security_setup_fetch_with_default_features_uses_authenticated_codex_end
write_chatgpt_auth(
&app.config.codex_home,
ChatGptAuthFixture::new("test-token")
.email("user@example.com")
.account_id("account")
.chatgpt_user_id("user"),
AuthCredentialsStoreMode::File,
@@ -141,9 +143,14 @@ async fn security_setup_fetch_with_default_features_uses_authenticated_codex_end
);
app.replace_chat_widget(ChatWidget::new_with_app_event(init));
let event = tokio::time::timeout(Duration::from_secs(5), async {
let mut security_notice = None;
let mut email_loaded = false;
loop {
let event = events.recv().await.unwrap();
if let AppEvent::SecuritySetupLoaded {
if matches!(event, AppEvent::AccountEmailLoaded { .. }) {
app.handle_event(&mut tui, &mut server, event).await?;
email_loaded = true;
} else if let AppEvent::SecuritySetupLoaded {
request_id: actual,
identity: actual_identity,
..
@@ -151,11 +158,30 @@ async fn security_setup_fetch_with_default_features_uses_authenticated_codex_end
{
assert_eq!(*actual, request_id);
assert_eq!(actual_identity, &identity);
break event;
security_notice = Some(event);
}
if email_loaded && let Some(event) = security_notice.take() {
break Result::<AppEvent>::Ok(event);
}
}
})
.await??;
app.handle_event(
&mut tui,
&mut server,
AppEvent::AccountEmailLoaded {
request_id: uuid::Uuid::new_v4(),
email: Some("stale@example.com".into()),
},
)
.await?;
assert_eq!(
app.chat_widget.status_account_display(),
Some(&StatusAccountDisplay::ChatGpt {
email: Some("user@example.com".into()),
plan: None,
})
);
app.handle_event(&mut tui, &mut server, event).await?;
assert!(!render_bottom_popup(&app.chat_widget, /*width*/ 70).contains("Set up security"));
}
+4
View File
@@ -279,6 +279,10 @@ pub(crate) struct AgentsOverviewThreadRefresh {
#[allow(clippy::large_enum_variant)]
#[derive(Debug, IntoStaticStr)]
pub(crate) enum AppEvent {
AccountEmailLoaded {
request_id: uuid::Uuid,
email: Option<String>,
},
SecuritySetupLoaded {
request_id: uuid::Uuid,
identity: crate::security_setup::Identity,
+7
View File
@@ -198,6 +198,13 @@ impl ChatWidget {
self.model_catalog.clone()
}
pub(crate) fn on_account_email_loaded(&mut self, current_email: Option<String>) {
if let Some(StatusAccountDisplay::ChatGpt { email, .. }) = &mut self.status_account_display
{
*email = current_email;
}
}
pub(crate) fn current_plan_type(&self) -> Option<PlanType> {
self.plan_type
}
@@ -13,8 +13,8 @@ expression: sanitized
Directory: [[workspace]]
Permissions: Custom (workspace with network access, Ask for approval)
Agents.md: <none>
Account: user@example.com (Pro 200)
Token usage: 2K total (1.4K input + 600 output)
Context window: 100% left (2.2K used / 272K)
5h limit: [███████████░░░░░░░░░] 55% left (resets 09:25)
Weekly limit: [██████████████░░░░░░] 70% left (resets 09:55)
+4 -1
View File
@@ -1913,7 +1913,10 @@ async fn status_snapshot_includes_credits_and_limits() {
config.model = Some("gpt-5.1-codex".to_string());
set_workspace_cwd(&mut config, test_path_buf("/workspace/tests").abs());
let account_display = test_status_account_display();
let account_display = Some(StatusAccountDisplay::ChatGpt {
email: Some("user@example.com".into()),
plan: Some("Pro 200".into()),
});
let usage = TokenUsage {
input_tokens: 1_500,
cached_input_tokens: 100,