mirror of
https://github.com/openai/codex.git
synced 2026-11-26 07:26:11 +00:00
Condense TUI startup warnings (#42609)
## What changed - Coalesce configuration, skill, sandbox, and MCP startup diagnostics into a single summary below the session header, including MCP and sign-in counts. - Keep the complete warning text in the transcript and update the summary's transcript shortcut when key bindings change. - Continue rendering warnings that arrive after work begins as inline history entries. - Hide the MCP startup status row before a turn while preserving the configured interrupt shortcut. ## Testing - Add coverage for warning ordering and deduplication, transcript details, MCP sign-in counts, resumed sessions, runtime warnings, reflow, backtracking, and interruption without a visible status row. GitOrigin-RevId: 009657cf04f1d3a52270cf096eebf9db7513c040
This commit is contained in:
1 parent
ed391d4dd2
commit
32c303c197
31 files changed
+728
-69
No files matched your search
@@ -3,9 +3,12 @@
|
||||
//! The app server reports MCP server startup as per-server status updates. This
|
||||
//! module keeps the TUI's buffered startup round state coherent and translates
|
||||
//! those updates into status headers, warnings, and queued-input release points.
|
||||
//! Initial diagnostics coalesce beneath the splash; warnings after a turn starts
|
||||
//! stay inline so failures during ongoing work remain visible.
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use codex_app_server_protocol::McpServerStartupFailureReason;
|
||||
use codex_app_server_protocol::McpServerStartupState;
|
||||
use codex_app_server_protocol::McpServerStatusUpdatedNotification;
|
||||
|
||||
@@ -14,11 +17,14 @@ use super::ChatWidget;
|
||||
const MCP_STARTUP_SINGLE_HEADER_PREFIX: &str = "Booting MCP server:";
|
||||
const MCP_STARTUP_MULTI_HEADER_PREFIX: &str = "Starting MCP servers";
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) enum McpStartupStatus {
|
||||
Starting,
|
||||
Ready,
|
||||
Failed { error: String },
|
||||
Failed {
|
||||
error: String,
|
||||
failure_reason: Option<McpServerStartupFailureReason>,
|
||||
},
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
@@ -82,23 +88,34 @@ impl ChatWidget {
|
||||
// Normal path: fold the update into the active round and surface
|
||||
// per-server failures immediately.
|
||||
let mut startup_status = self.mcp_startup_status.take().unwrap_or_default();
|
||||
if let McpStartupStatus::Failed { error } = &status {
|
||||
let already_reported = matches!(
|
||||
startup_status.get(&server),
|
||||
Some(McpStartupStatus::Failed { error: previous }) if previous == error
|
||||
if let McpStartupStatus::Failed {
|
||||
error,
|
||||
failure_reason,
|
||||
} = &status
|
||||
&& startup_status.get(&server) != Some(&status)
|
||||
{
|
||||
self.add_mcp_startup_warning(
|
||||
vec![error.clone()],
|
||||
[server.clone()],
|
||||
*failure_reason,
|
||||
);
|
||||
if !already_reported {
|
||||
self.on_warning(error);
|
||||
}
|
||||
}
|
||||
startup_status.insert(server, status);
|
||||
startup_status
|
||||
};
|
||||
if activated_pending_round {
|
||||
// A promoted buffered round may already contain terminal failures.
|
||||
for state in startup_status.values() {
|
||||
if let McpStartupStatus::Failed { error } = state {
|
||||
self.on_warning(error);
|
||||
for (server, state) in &startup_status {
|
||||
if let McpStartupStatus::Failed {
|
||||
error,
|
||||
failure_reason,
|
||||
} = state
|
||||
{
|
||||
self.add_mcp_startup_warning(
|
||||
vec![error.clone()],
|
||||
[server.clone()],
|
||||
*failure_reason,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,17 +201,25 @@ impl ChatWidget {
|
||||
|
||||
pub(super) fn finish_mcp_startup(&mut self, failed: Vec<String>, cancelled: Vec<String>) {
|
||||
if !cancelled.is_empty() {
|
||||
self.on_warning(format!(
|
||||
"MCP startup interrupted. The following servers were not initialized: {}",
|
||||
cancelled.join(", ")
|
||||
));
|
||||
self.add_mcp_startup_warning(
|
||||
vec![format!(
|
||||
"MCP startup interrupted. The following servers were not initialized: {}",
|
||||
cancelled.join(", ")
|
||||
)],
|
||||
cancelled,
|
||||
/*failure_reason*/ None,
|
||||
);
|
||||
}
|
||||
let mut parts = Vec::new();
|
||||
if !failed.is_empty() {
|
||||
parts.push(format!("failed: {}", failed.join(", ")));
|
||||
}
|
||||
if !parts.is_empty() {
|
||||
self.on_warning(format!("MCP startup incomplete ({})", parts.join("; ")));
|
||||
self.add_mcp_startup_warning(
|
||||
vec![format!("MCP startup incomplete ({})", parts.join("; "))],
|
||||
failed,
|
||||
/*failure_reason*/ None,
|
||||
);
|
||||
}
|
||||
|
||||
let mcp_startup_owned_status = self.status_header_is_mcp_startup_owned();
|
||||
@@ -262,6 +287,25 @@ impl ChatWidget {
|
||||
.starts_with(MCP_STARTUP_MULTI_HEADER_PREFIX)
|
||||
}
|
||||
|
||||
fn add_mcp_startup_warning(
|
||||
&mut self,
|
||||
messages: Vec<String>,
|
||||
servers: impl IntoIterator<Item = String>,
|
||||
failure_reason: Option<McpServerStartupFailureReason>,
|
||||
) {
|
||||
if self.warning_display_state.startup_complete {
|
||||
for message in messages {
|
||||
self.on_warning(message);
|
||||
}
|
||||
} else {
|
||||
self.add_to_history(crate::history_cell::StartupWarningsCell::mcp(
|
||||
messages,
|
||||
servers,
|
||||
failure_reason,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Update startup state and retry installed-app discovery when its MCP server becomes ready.
|
||||
pub(super) fn on_mcp_server_status_updated(
|
||||
&mut self,
|
||||
@@ -273,6 +317,7 @@ impl ChatWidget {
|
||||
McpServerStartupState::Starting => McpStartupStatus::Starting,
|
||||
McpServerStartupState::Ready => McpStartupStatus::Ready,
|
||||
McpServerStartupState::Failed => McpStartupStatus::Failed {
|
||||
failure_reason: notification.failure_reason,
|
||||
error: notification.error.unwrap_or_else(|| {
|
||||
format!("MCP client for `{}` failed to start", notification.name)
|
||||
}),
|
||||
|
||||
@@ -66,6 +66,7 @@ impl ChatWidget {
|
||||
self.turn_lifecycle.last_turn_id = Some(notification.turn.id);
|
||||
self.last_non_retry_error = None;
|
||||
if !matches!(replay_kind, Some(ReplayKind::ResumeInitialMessages)) {
|
||||
self.warning_display_state.startup_complete = true;
|
||||
self.on_task_started();
|
||||
}
|
||||
}
|
||||
@@ -194,12 +195,18 @@ impl ChatWidget {
|
||||
ServerNotification::DeprecationNotice(notification) => {
|
||||
self.on_deprecation_notice(notification.summary, notification.details)
|
||||
}
|
||||
ServerNotification::ConfigWarning(notification) => self.on_warning(
|
||||
notification
|
||||
ServerNotification::ConfigWarning(notification) => {
|
||||
let message = notification
|
||||
.details
|
||||
.map(|details| format!("{}: {details}", notification.summary))
|
||||
.unwrap_or(notification.summary),
|
||||
),
|
||||
.unwrap_or(notification.summary);
|
||||
if self.warning_display_state.startup_complete {
|
||||
self.on_warning(message);
|
||||
} else if self.warning_display_state.should_display(&message) {
|
||||
self.add_to_history(history_cell::StartupWarningsCell::new(vec![message]));
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
ServerNotification::McpServerStatusUpdated(notification) => {
|
||||
self.on_mcp_server_status_updated(notification)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ impl ChatWidget {
|
||||
/// avoid triggering side effects. Event ids are passed as `None` to
|
||||
/// distinguish replayed events from live ones.
|
||||
pub(crate) fn replay_thread_turns(&mut self, turns: Vec<Turn>, replay_kind: ReplayKind) {
|
||||
if matches!(replay_kind, ReplayKind::ThreadSnapshot) && !turns.is_empty() {
|
||||
self.warning_display_state.startup_complete = true;
|
||||
}
|
||||
let latest_turn_id = turns.last().map(|turn| turn.id.clone());
|
||||
let hidden_nested_review_turns = std::iter::once(/*value*/ false)
|
||||
.chain(turns.windows(/*size*/ 2).map(|turns| {
|
||||
@@ -48,6 +51,7 @@ impl ChatWidget {
|
||||
duration_ms,
|
||||
} = turn;
|
||||
if matches!(status, TurnStatus::InProgress) {
|
||||
self.warning_display_state.startup_complete = true;
|
||||
self.turn_lifecycle.last_turn_id = Some(turn_id.clone());
|
||||
self.last_non_retry_error = None;
|
||||
self.on_task_started();
|
||||
|
||||
-2
@@ -3,8 +3,6 @@ source: tui/src/chatwidget/tests/mcp_startup.rs
|
||||
expression: normalized_backend_snapshot(terminal.backend())
|
||||
---
|
||||
" "
|
||||
"• Booting MCP server: alpha (0s • esc to interrupt) "
|
||||
" "
|
||||
" "
|
||||
"› Ask Codex to do anything "
|
||||
" "
|
||||
|
||||
@@ -935,6 +935,29 @@ async fn live_app_server_strict_review_required_notification_renders_message() {
|
||||
assert!(chat.bottom_pane.is_task_running());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn config_warning_during_turn_remains_inline() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
handle_turn_started(&mut chat, "turn-1");
|
||||
chat.handle_server_notification(
|
||||
ServerNotification::ConfigWarning(ConfigWarningNotification {
|
||||
summary: "Invalid configuration; using defaults.".into(),
|
||||
details: Some("Check the project configuration.".into()),
|
||||
path: None,
|
||||
range: None,
|
||||
}),
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
let cells = drain_insert_history(&mut rx);
|
||||
insta::assert_snapshot!(
|
||||
"runtime_config_warning",
|
||||
cells
|
||||
.iter()
|
||||
.map(|lines| lines_to_single_string(lines))
|
||||
.collect::<String>()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn live_app_server_config_warning_prefixes_summary() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
@@ -949,7 +972,7 @@ async fn live_app_server_config_warning_prefixes_summary() {
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
|
||||
let cells = drain_insert_history(&mut rx);
|
||||
let cells = drain_insert_history_transcript(&mut rx);
|
||||
assert_eq!(cells.len(), 1, "expected one warning history cell");
|
||||
let rendered = lines_to_single_string(&cells[0]);
|
||||
assert!(
|
||||
|
||||
@@ -330,11 +330,24 @@ pub(crate) async fn make_chatwidget_manual_with_sender() -> (
|
||||
|
||||
pub(super) fn drain_insert_history(
|
||||
rx: &mut tokio::sync::mpsc::UnboundedReceiver<AppEvent>,
|
||||
) -> Vec<Vec<ratatui::text::Line<'static>>> {
|
||||
drain_insert_history_with(rx, |cell| cell.display_lines(/*width*/ 80))
|
||||
}
|
||||
|
||||
pub(super) fn drain_insert_history_transcript(
|
||||
rx: &mut tokio::sync::mpsc::UnboundedReceiver<AppEvent>,
|
||||
) -> Vec<Vec<ratatui::text::Line<'static>>> {
|
||||
drain_insert_history_with(rx, |cell| cell.transcript_lines(/*width*/ 80))
|
||||
}
|
||||
|
||||
fn drain_insert_history_with(
|
||||
rx: &mut tokio::sync::mpsc::UnboundedReceiver<AppEvent>,
|
||||
render: impl Fn(&dyn HistoryCell) -> Vec<ratatui::text::Line<'static>>,
|
||||
) -> Vec<Vec<ratatui::text::Line<'static>>> {
|
||||
let mut out = Vec::new();
|
||||
while let Ok(ev) = rx.try_recv() {
|
||||
if let AppEvent::InsertHistoryCell(cell) = ev {
|
||||
let mut lines = cell.display_lines(/*width*/ 80);
|
||||
let mut lines = render(cell.as_ref());
|
||||
if !cell.is_stream_continuation() && !out.is_empty() && !lines.is_empty() {
|
||||
lines.insert(0, "".into());
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use super::helpers::drain_insert_history_transcript as drain_insert_history;
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
@@ -134,6 +135,8 @@ async fn mcp_startup_header_booting_snapshot() {
|
||||
|
||||
notify_mcp_status(&mut chat, "alpha", McpServerStartupState::Starting);
|
||||
|
||||
assert!(chat.bottom_pane.is_task_running());
|
||||
assert!(!chat.bottom_pane.status_indicator_visible());
|
||||
let height = chat.desired_height(/*width*/ 80);
|
||||
let mut terminal = ratatui::Terminal::new(ratatui::backend::TestBackend::new(80, height))
|
||||
.expect("create terminal");
|
||||
@@ -146,6 +149,55 @@ async fn mcp_startup_header_booting_snapshot() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mcp_startup_updates_preserve_streaming_status_suppression() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.set_mcp_startup_expected_servers(["alpha".into(), "beta".into()]);
|
||||
handle_turn_started(&mut chat, "turn-1");
|
||||
chat.on_agent_message_delta("Partial response\n".into());
|
||||
chat.on_commit_tick();
|
||||
assert!(!chat.bottom_pane.status_indicator_visible());
|
||||
|
||||
notify_mcp_status(&mut chat, "alpha", McpServerStartupState::Ready);
|
||||
assert!(chat.bottom_pane.is_task_running());
|
||||
assert!(!chat.bottom_pane.status_indicator_visible());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mcp_startup_summary_distinguishes_initial_resume_from_task_switch() {
|
||||
use AppServerTurnStatus::Completed;
|
||||
use AppServerTurnStatus::InProgress;
|
||||
use ReplayKind::ResumeInitialMessages;
|
||||
use ReplayKind::ThreadSnapshot;
|
||||
|
||||
for (replay_kind, status, compact) in [
|
||||
(ResumeInitialMessages, Completed, true),
|
||||
(ResumeInitialMessages, InProgress, false),
|
||||
(ThreadSnapshot, Completed, false),
|
||||
] {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.replay_thread_turns(
|
||||
vec![app_server_turn(
|
||||
"previous-turn",
|
||||
status,
|
||||
/*duration_ms*/ None,
|
||||
/*error*/ None,
|
||||
)],
|
||||
replay_kind,
|
||||
);
|
||||
while rx.try_recv().is_ok() {}
|
||||
chat.set_mcp_startup_expected_servers(["alpha".into()]);
|
||||
notify_mcp_status_error(&mut chat, "alpha", "connection failed");
|
||||
let mut compact_cells = Vec::new();
|
||||
while let Ok(event) = rx.try_recv() {
|
||||
if let AppEvent::InsertHistoryCell(cell) = event {
|
||||
compact_cells.push(cell.as_any().is::<history_cell::StartupWarningsCell>());
|
||||
}
|
||||
}
|
||||
assert_eq!(compact_cells, vec![compact; 2]);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn mcp_startup_complete_does_not_clear_running_task() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
@@ -257,6 +309,7 @@ async fn pending_mcp_startup_does_not_unblock_external_review() {
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
|
||||
handle_entered_review_mode(&mut chat, "current changes");
|
||||
assert!(chat.bottom_pane.status_indicator_visible());
|
||||
chat.queue_user_message("queued follow-up".into());
|
||||
|
||||
assert!(chat.review.is_review_mode);
|
||||
@@ -270,6 +323,7 @@ async fn pending_mcp_startup_does_not_unblock_external_review() {
|
||||
|
||||
chat.finish_mcp_startup(Vec::new(), Vec::new());
|
||||
assert!(chat.bottom_pane.is_task_running());
|
||||
assert!(chat.bottom_pane.status_indicator_visible());
|
||||
assert_eq!(chat.input_queue.queued_user_messages.len(), 1);
|
||||
assert_no_submit_op(&mut op_rx);
|
||||
}
|
||||
@@ -450,7 +504,14 @@ async fn mcp_startup_failure_restores_running_status_header() {
|
||||
"MCP client for `alpha` failed to start: handshake failed",
|
||||
);
|
||||
notify_mcp_status(&mut chat, "beta", McpServerStartupState::Ready);
|
||||
let _ = drain_insert_history(&mut rx);
|
||||
let warnings = super::helpers::drain_insert_history(&mut rx);
|
||||
insta::assert_snapshot!(
|
||||
"runtime_mcp_warning",
|
||||
warnings
|
||||
.iter()
|
||||
.map(|lines| lines_to_single_string(lines))
|
||||
.collect::<String>()
|
||||
);
|
||||
|
||||
assert!(chat.bottom_pane.is_task_running());
|
||||
assert!(chat.bottom_pane.status_indicator_visible());
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/app_server.rs
|
||||
expression: "cells.iter().map(|lines| lines_to_single_string(lines)).collect::<String>()"
|
||||
---
|
||||
⚠ Invalid configuration; using defaults.: Check the project configuration.
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/mcp_startup.rs
|
||||
expression: "warnings.iter().map(|lines| lines_to_single_string(lines)).collect::<String>()"
|
||||
---
|
||||
⚠ MCP client for `alpha` failed to start: handshake failed
|
||||
|
||||
⚠ MCP startup incomplete (failed: alpha)
|
||||
@@ -36,6 +36,12 @@ impl ChatWidget {
|
||||
|| self.review.is_review_mode
|
||||
|| self.mcp_startup_status.is_some(),
|
||||
);
|
||||
if self.mcp_startup_status.is_some()
|
||||
&& !self.turn_lifecycle.agent_turn_running
|
||||
&& !self.review.is_review_mode
|
||||
{
|
||||
self.bottom_pane.hide_status_indicator();
|
||||
}
|
||||
self.refresh_status_surfaces();
|
||||
}
|
||||
|
||||
@@ -83,6 +89,7 @@ impl ChatWidget {
|
||||
self.quit_shortcut_expires_at = None;
|
||||
self.quit_shortcut_key = None;
|
||||
self.update_task_running_state();
|
||||
self.bottom_pane.ensure_status_indicator();
|
||||
self.bottom_pane.reset_status_timer(Duration::ZERO);
|
||||
self.status_state.retry_status_header = None;
|
||||
self.clear_active_hook_cell();
|
||||
|
||||
@@ -6,6 +6,8 @@ const FALLBACK_MODEL_METADATA_WARNING_SUFFIX: &str =
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct WarningDisplayState {
|
||||
/// Completed resume history does not end startup; active work does.
|
||||
pub(super) startup_complete: bool,
|
||||
fallback_model_metadata_slugs: HashSet<String>,
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user