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
+6
View File
@@ -4277,6 +4277,10 @@ pub struct McpStartupUpdateEvent {
pub environment_id: Option<String>,
/// Current startup status.
pub status: McpStartupStatus,
/// Time spent initializing this server, when reporting a measured startup outcome.
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(type = "number | null", optional)]
pub duration_ms: Option<u64>,
}
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, TS)]
@@ -6937,12 +6941,14 @@ mod tests {
error: "boom".to_string(),
reason: Some(McpStartupFailureReason::ReauthenticationRequired),
},
duration_ms: Some(1_250),
}),
};
let value = serde_json::to_value(&event)?;
assert_eq!(value["msg"]["type"], "mcp_startup_update");
assert_eq!(value["msg"]["server"], "srv");
assert_eq!(value["msg"]["duration_ms"], 1_250);
assert_eq!(value["msg"]["status"]["state"], "failed");
assert_eq!(value["msg"]["status"]["error"], "boom");
assert_eq!(