Report per-server MCP startup durations (#63613)

## Why

Required MCP servers can finish at different times even when their startup
notifications arrive together. Notification arrival times cannot show how long
each server took to start.

## What changed

Measure each startup attempt and expose its elapsed milliseconds as
`durationMs` on `ready` and `failed` updates from
`mcpServer/startupStatus/updated`. Successful Codex Apps reconnects report
their own duration. Reused connections, `starting`, and `cancelled` updates
carry `null`. The protocol accepts notifications from older servers that omit
the field.

## Testing

Cover distinct durations for fast and slow required servers, timing through
lease registration for newly opened shared connections, and a fresh duration
after Codex Apps recovery.

GitOrigin-RevId: 39c0c418149dd2b220828be04d998085f57acf2d
This commit is contained in:
JonLuca De Caro
2026-11-24 11:05:19 +00:00
committed by copyberry
parent 32119bac26
commit abc92e6bd4
34 changed files with 344 additions and 61 deletions
@@ -333,6 +333,7 @@ mod tests {
thread_id: Some(thread_id.to_string()),
name: "sentry".to_string(),
status: McpServerStartupState::Failed,
duration_ms: None,
error: Some("sentry is not logged in".to_string()),
failure_reason: None,
});
@@ -350,6 +351,7 @@ mod tests {
thread_id: None,
name: "sentry".to_string(),
status: McpServerStartupState::Failed,
duration_ms: None,
error: Some("sentry is not logged in".to_string()),
failure_reason: None,
});
+2 -33
View File
@@ -8408,6 +8408,7 @@ async fn primary_thread_ignores_child_mcp_startup_notifications() {
thread_id: Some(child_thread_id.to_string()),
name: "sentry".to_string(),
status: McpServerStartupState::Failed,
duration_ms: None,
error: Some("sentry is not logged in".to_string()),
failure_reason: None,
}),
@@ -8468,39 +8469,6 @@ async fn primary_thread_ignores_child_mcp_startup_notifications() {
);
}
#[tokio::test]
async fn app_scoped_mcp_startup_notifications_do_not_render_in_active_thread() {
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
while app_event_rx.try_recv().is_ok() {}
let app_server = crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref())
.await
.expect("embedded app server");
let thread_id = ThreadId::new();
app.primary_thread_id = Some(thread_id);
app.active_thread_id = Some(thread_id);
app.handle_app_server_event(
&app_server,
codex_app_server_client::AppServerEvent::ServerNotification(Box::new(
ServerNotification::McpServerStatusUpdated(McpServerStatusUpdatedNotification {
environment_id: None,
thread_id: None,
name: "sentry".to_string(),
status: McpServerStartupState::Failed,
error: Some("sentry is not logged in".to_string()),
failure_reason: None,
}),
)),
)
.await;
assert!(app_event_rx.try_recv().is_err());
assert_eq!(
app.chat_widget.active_cell_transcript_lines(/*width*/ 120),
None
);
}
#[tokio::test]
async fn active_side_thread_renders_live_mcp_startup_notifications() {
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
@@ -8568,6 +8536,7 @@ async fn active_side_thread_renders_live_mcp_startup_notifications() {
thread_id: Some(side_thread_id.to_string()),
name: name.to_string(),
status,
duration_ms: None,
error: matches!(status, McpServerStartupState::Failed)
.then(|| "sentry is not logged in".to_string()),
failure_reason: None,
@@ -67,6 +67,7 @@ async fn backend_sessions_parked_request_does_not_hide_disconnect() -> Result<()
thread_id: Some(thread_id.to_string()),
name: "tools".into(),
status: McpServerStartupState::Failed,
duration_ms: None,
error: Some("startup failed".into()),
failure_reason: None,
},
@@ -756,6 +756,7 @@ async fn daemon_ctrl_c_during_mcp_startup_does_not_show_background_exit_menu() -
thread_id: Some(thread_id.to_string()),
name: "slow".to_string(),
status: McpServerStartupState::Starting,
duration_ms: None,
error: None,
failure_reason: None,
}),
+39
View File
@@ -45,6 +45,7 @@ async fn remote_mcp_startup_settles_when_attaching_mid_round() -> Result<()> {
thread_id: Some(id.to_string()),
name: name.to_string(),
status,
duration_ms: None,
error: None,
failure_reason: None,
})
@@ -162,6 +163,7 @@ async fn remote_mcp_startup_reports_terminal_only_failures_and_cancellations() -
environment_id: None,
thread_id: Some(id.to_string()),
name: name.to_string(),
duration_ms: None,
error: (status == Failed).then(|| error.to_string()),
failure_reason: (status == Failed).then_some(ReauthenticationRequired),
status,
@@ -267,6 +269,7 @@ async fn subagent_mcp_startup_settles_while_cached_servers_remain_deferred() {
thread_id: Some(subagent_thread_id.to_string()),
name: name.to_string(),
status,
duration_ms: None,
error: None,
failure_reason: None,
}),
@@ -317,6 +320,7 @@ async fn resumed_subagent_mcp_startup_settles_while_cached_servers_remain_deferr
thread_id: Some(subagent_thread_id.to_string()),
name: "eager".to_string(),
status,
duration_ms: None,
error: None,
failure_reason: None,
}),
@@ -348,6 +352,7 @@ async fn side_conversations_settle_despite_unreported_locally_configured_servers
thread_id: Some(side_thread_id.to_string()),
name: "eager".to_string(),
status,
duration_ms: None,
error: None,
failure_reason: None,
}),
@@ -357,3 +362,37 @@ async fn side_conversations_settle_despite_unreported_locally_configured_servers
assert!(!app.chat_widget.is_task_running_for_test());
}
#[tokio::test]
async fn app_scoped_mcp_startup_notifications_do_not_render_in_active_thread() {
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
while app_event_rx.try_recv().is_ok() {}
let app_server = crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref())
.await
.expect("embedded app server");
let thread_id = ThreadId::new();
app.primary_thread_id = Some(thread_id);
app.active_thread_id = Some(thread_id);
app.handle_app_server_event(
&app_server,
codex_app_server_client::AppServerEvent::ServerNotification(Box::new(
ServerNotification::McpServerStatusUpdated(McpServerStatusUpdatedNotification {
environment_id: None,
thread_id: None,
name: "sentry".to_string(),
status: McpServerStartupState::Failed,
duration_ms: None,
error: Some("sentry is not logged in".to_string()),
failure_reason: None,
}),
)),
)
.await;
assert!(app_event_rx.try_recv().is_err());
assert_eq!(
app.chat_widget.active_cell_transcript_lines(/*width*/ 120),
None
);
}
+2
View File
@@ -1576,6 +1576,7 @@ async fn startup_thread_started_discards_another_threads_buffered_events() {
thread_id: Some(other_thread_id.to_string()),
name: "other".to_string(),
status: McpServerStartupState::Starting,
duration_ms: None,
error: None,
failure_reason: None,
},
@@ -1790,6 +1791,7 @@ async fn send_failed_mcp_startup(
thread_id: Some(thread_id.to_string()),
name: "fixture".to_string(),
status: McpServerStartupState::Failed,
duration_ms: None,
error: Some("fixture failed".to_string()),
failure_reason: None,
}),
@@ -205,6 +205,7 @@ async fn mcp_startup_summary_counts_servers_and_sign_in_subset() -> Result<()> {
thread_id: None,
name: name.into(),
status,
duration_ms: None,
error: (status == Failed).then(|| format!("MCP {name}: connection unavailable")),
failure_reason,
}),
@@ -220,6 +220,7 @@ async fn unavailable_thread_new_and_clear_start_a_writable_session() -> Result<(
thread_id: Some(id.to_string()),
name: "slow".into(),
status: McpServerStartupState::Starting,
duration_ms: None,
error: None,
failure_reason: None,
}),
+1
View File
@@ -1135,6 +1135,7 @@ mod tests {
thread_id: Some(thread_id.to_string()),
name: "sentry".to_string(),
status: codex_app_server_protocol::McpServerStartupState::Failed,
duration_ms: None,
error: Some("sentry is not logged in".to_string()),
failure_reason: None,
},
@@ -808,6 +808,7 @@ async fn guardian_cleanup_drops_stale_reviews_and_restores_mcp_status() {
thread_id: None,
name: "alpha".to_string(),
status: McpServerStartupState::Starting,
duration_ms: None,
error: None,
failure_reason: None,
});
@@ -9,6 +9,7 @@ fn notify_mcp_status(chat: &mut ChatWidget, name: &str, status: McpServerStartup
thread_id: Some("thread-1".to_string()),
name: name.to_string(),
status,
duration_ms: None,
error: None,
failure_reason: None,
}),
@@ -23,6 +24,7 @@ fn notify_mcp_status_error(chat: &mut ChatWidget, name: &str, error: &str) {
thread_id: Some("thread-1".to_string()),
name: name.to_string(),
status: McpServerStartupState::Failed,
duration_ms: None,
error: Some(error.to_string()),
failure_reason: None,
}),
@@ -54,6 +56,7 @@ async fn mcp_startup_ignores_status_for_other_thread() {
thread_id: Some(child_thread_id.to_string()),
name: "sentry".to_string(),
status,
duration_ms: None,
error: matches!(status, McpServerStartupState::Failed)
.then(|| "sentry is not logged in".to_string()),
failure_reason: None,
@@ -85,6 +88,7 @@ async fn mcp_apps_readiness_retries_an_in_flight_installed_mention_lookup() {
thread_id: None,
name: "codex_apps".to_string(),
status: McpServerStartupState::Ready,
duration_ms: None,
error: None,
failure_reason: None,
});
@@ -552,6 +556,7 @@ async fn app_server_mcp_startup_failure_renders_warning_history() {
name: "notes".to_string(),
environment_id: Some(environment_id.to_string()),
status: McpServerStartupState::Starting,
duration_ms: None,
error: None,
failure_reason: None,
});
@@ -570,6 +575,7 @@ async fn app_server_mcp_startup_failure_renders_warning_history() {
name: "notes".to_string(),
environment_id: Some("env-a".to_string()),
status: McpServerStartupState::Failed,
duration_ms: None,
error: Some("MCP client for `notes` failed to start: handshake failed".to_string()),
failure_reason: None,
});
@@ -595,6 +601,7 @@ async fn app_server_mcp_startup_failure_renders_warning_history() {
name: "notes".to_string(),
environment_id: Some("env-b".to_string()),
status: McpServerStartupState::Ready,
duration_ms: None,
error: None,
failure_reason: None,
});