Keep MCP startup from showing the TUI as working (#64221)

## Why

MCP startup could show `Working` before a user turn began, and
reloading MCP servers could temporarily hide an unread `Done` status.

## What changed

Derive the terminal program status from user turn activity, active
goals, blocked states, and the stored turn result.

## Testing

Extend the status regression test to check that the TUI stays idle
while MCP starts, reports `Working` when a turn begins before MCP is
ready, and keeps `Done` visible throughout an MCP reload until the
result is acknowledged.

GitOrigin-RevId: f05fab26e54e610743f0f799ef30306835d5cbdd
This commit is contained in:
Eric Traut
2026-11-26 21:46:36 +00:00
committed by copyberry
parent 4e19f0f20b
commit c587ff1f0b
3 changed files with 11 additions and 4 deletions
@@ -305,8 +305,7 @@ impl ChatWidget {
pub(crate) fn desired_program_status(&self) -> ProgramStatus {
if let Some(kind) = self.bottom_pane.program_status_blocked_kind() {
ProgramStatus::Blocked(kind)
} else if self.bottom_pane.is_task_running()
|| self.is_user_turn_pending_or_running()
} else if self.is_user_turn_pending_or_running()
|| (self.status_state.program_status_after_turn == ProgramStatus::Done
&& self
.current_goal_status
@@ -2,7 +2,7 @@ use super::helpers::drain_insert_history_transcript as drain_insert_history;
use super::*;
use pretty_assertions::assert_eq;
fn notify_mcp_status(chat: &mut ChatWidget, name: &str, status: McpServerStartupState) {
pub(super) fn notify_mcp_status(chat: &mut ChatWidget, name: &str, status: McpServerStartupState) {
chat.handle_server_notification(
ServerNotification::McpServerStatusUpdated(McpServerStatusUpdatedNotification {
environment_id: None,
@@ -1,6 +1,7 @@
//! Exercises terminal status across live, interrupted, and replayed turns.
//! Replayed results and work already underway must never appear as new completions.
use super::mcp_startup::notify_mcp_status;
use super::*;
use crate::terminal_program_status::ProgramStatus;
use pretty_assertions::assert_eq;
@@ -24,9 +25,12 @@ async fn program_status_tracks_live_results_and_resolved_approvals() {
let status = chat.desired_program_status();
format!("{status:?} {}", draw.frame.display())
};
// MCP startup alone is idle, even if a turn starts before the server is ready.
notify_mcp_status(&mut chat, "slow", McpServerStartupState::Starting);
let mut statuses = vec![status(&mut chat)];
handle_turn_started(&mut chat, "status-turn");
statuses.push(status(&mut chat));
notify_mcp_status(&mut chat, "slow", McpServerStartupState::Ready);
handle_exec_approval_request(
&mut chat,
"status-approval",
@@ -51,7 +55,10 @@ async fn program_status_tracks_live_results_and_resolved_approvals() {
statuses.push(status(&mut chat));
handle_turn_completed(&mut chat, "status-turn", /*duration_ms*/ None);
statuses.push(status(&mut chat));
// A second draw must leave the unread result in place.
// Reloading MCP must leave the unread result in place throughout the round.
notify_mcp_status(&mut chat, "slow", McpServerStartupState::Starting);
statuses.push(status(&mut chat));
notify_mcp_status(&mut chat, "slow", McpServerStartupState::Ready);
statuses.push(status(&mut chat));
chat.acknowledge_program_status();
statuses.push(status(&mut chat));
@@ -81,6 +88,7 @@ async fn program_status_tracks_live_results_and_resolved_approvals() {
Working frame-56.png
Done frame-64.png
Done frame-64.png
Done frame-64.png
Idle frame-0.png
Idle frame-0.png
Error frame-40.png