From 65f74c63f799636556dc4e89b63b2c13e143719d Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 28 Jun 2026 19:46:34 -0400 Subject: [PATCH] Track MCP-only startup tasks --- codex-rs/tui/src/chatwidget.rs | 2 ++ codex-rs/tui/src/chatwidget/constructor.rs | 1 + codex-rs/tui/src/chatwidget/mcp_startup.rs | 6 +++++ codex-rs/tui/src/chatwidget/slash_dispatch.rs | 3 ++- .../tui/src/chatwidget/tests/mcp_startup.rs | 22 +++++++++++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index a204bc5ff6..12b58ec432 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -596,6 +596,8 @@ pub(crate) struct ChatWidget { /// as "running" while this is populated, even if no agent turn is currently /// executing. mcp_startup_status: Option>, + /// Whether the active MCP startup round began while no other task was running. + mcp_startup_started_while_idle: bool, /// Expected MCP servers for the current startup round, seeded from enabled local config. mcp_startup_expected_servers: Option>, /// After startup settles, ignore stale updates until enough notifications confirm a new round. diff --git a/codex-rs/tui/src/chatwidget/constructor.rs b/codex-rs/tui/src/chatwidget/constructor.rs index 05698e9cfb..b08f948f2f 100644 --- a/codex-rs/tui/src/chatwidget/constructor.rs +++ b/codex-rs/tui/src/chatwidget/constructor.rs @@ -158,6 +158,7 @@ impl ChatWidget { task_complete_pending: false, unified_exec_processes: Vec::new(), mcp_startup_status: None, + mcp_startup_started_while_idle: false, mcp_startup_expected_servers: None, mcp_startup_ignore_updates_until_next_start: false, mcp_startup_allow_terminal_only_next_round: false, diff --git a/codex-rs/tui/src/chatwidget/mcp_startup.rs b/codex-rs/tui/src/chatwidget/mcp_startup.rs index bb2b84dd30..92e2bae2ee 100644 --- a/codex-rs/tui/src/chatwidget/mcp_startup.rs +++ b/codex-rs/tui/src/chatwidget/mcp_startup.rs @@ -42,6 +42,7 @@ impl ChatWidget { return; } + let mcp_startup_was_inactive = self.mcp_startup_status.is_none(); let mut activated_pending_round = false; let startup_status = if self.mcp_startup_ignore_updates_until_next_start { // Ignore-mode buffers the next plausible round so stale post-finish @@ -106,6 +107,9 @@ impl ChatWidget { } } } + if mcp_startup_was_inactive { + self.mcp_startup_started_while_idle = !self.bottom_pane.is_task_running(); + } self.mcp_startup_status = Some(startup_status); self.update_task_running_state(); @@ -202,6 +206,7 @@ impl ChatWidget { let mcp_startup_owned_status = self.status_header_is_mcp_startup_owned(); self.mcp_startup_status = None; + self.mcp_startup_started_while_idle = false; self.mcp_startup_ignore_updates_until_next_start = true; self.mcp_startup_allow_terminal_only_next_round = false; self.mcp_startup_pending_next_round.clear(); @@ -220,6 +225,7 @@ impl ChatWidget { self.mcp_startup_allow_terminal_only_next_round = false; self.mcp_startup_pending_next_round.clear(); self.mcp_startup_pending_next_round_saw_starting = false; + self.mcp_startup_started_while_idle = false; if self.mcp_startup_status.is_none() { return; } diff --git a/codex-rs/tui/src/chatwidget/slash_dispatch.rs b/codex-rs/tui/src/chatwidget/slash_dispatch.rs index 92c06357db..34adea23e2 100644 --- a/codex-rs/tui/src/chatwidget/slash_dispatch.rs +++ b/codex-rs/tui/src/chatwidget/slash_dispatch.rs @@ -139,7 +139,8 @@ impl ChatWidget { fn slash_command_blocked_by_active_task(&self, cmd: SlashCommand) -> bool { if cmd == SlashCommand::Review { - let mcp_startup_is_only_task = self.mcp_startup_status.is_some() + let mcp_startup_is_only_task = self.mcp_startup_started_while_idle + && self.mcp_startup_status.is_some() && !self.turn_lifecycle.agent_turn_running && !self.input_queue.user_turn_pending_start && !self.has_queued_follow_up_messages() diff --git a/codex-rs/tui/src/chatwidget/tests/mcp_startup.rs b/codex-rs/tui/src/chatwidget/tests/mcp_startup.rs index 9eb4ebca4a..b20918ee90 100644 --- a/codex-rs/tui/src/chatwidget/tests/mcp_startup.rs +++ b/codex-rs/tui/src/chatwidget/tests/mcp_startup.rs @@ -300,6 +300,28 @@ async fn queued_prompt_blocks_review_during_mcp_startup() { assert_eq!(chat.bottom_pane.composer_text(), "/review"); } +#[tokio::test] +async fn compact_task_blocks_review_when_mcp_startup_arrives() { + let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + chat.dispatch_command(SlashCommand::Compact); + assert!(chat.bottom_pane.is_task_running()); + assert_matches!(rx.try_recv(), Ok(AppEvent::CodexOp(Op::Compact))); + notify_mcp_status(&mut chat, "alpha", McpServerStartupState::Starting); + + chat.bottom_pane + .set_composer_text("/review".to_string(), Vec::new(), Vec::new()); + chat.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE)); + chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)); + chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)); + + let error = drain_insert_history(&mut rx) + .into_iter() + .map(|lines| lines_to_single_string(&lines)) + .collect::(); + assert!(error.contains("'/review' is disabled while a task is in progress.")); + assert_eq!(chat.bottom_pane.composer_text(), "/review"); +} + #[tokio::test] async fn mcp_startup_dedupes_same_round_duplicate_failure_warning() { let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;