fix(tui): scope MCP startup events to emitting thread

Sub-agent McpConnectionManager startup events leaked into the leader
TUI's status header because McpServerStatusUpdated notifications carried
no thread identity and were routed Global, which fell through to the
leader's chat_widget and overwrote its mcp_startup_status map. Once a
sub-agent re-emitted Starting for a server the leader already had as
Ready, the leader's spinner reopened and the settle check could never
pass.

Add an optional thread_id to McpServerStatusUpdatedNotification, set it
from the emitting session in apply_bespoke_event_handling, and route
notifications carrying a thread_id through ServerNotificationThreadTarget
so non-leader threads enqueue to their own buffered store rather than
mutating the leader's map. A missing thread_id keeps the existing Global
behaviour for backward compatibility with older app servers.

Adds:
- routing unit tests covering both presence and absence of thread_id
- an app-level test asserting a sub-agent McpServerStatusUpdated does
  not flip the leader's task-running state
- thread_id assertion in the existing app-server integration test

Closes #18068
Refs #16821, #19542

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Shayne Sweeney
2026-05-02 11:35:26 -04:00
co-authored by Codex
parent 35aaa5d9fc
commit 06fd1307aa
12 changed files with 132 additions and 3 deletions
@@ -10967,6 +10967,14 @@
},
"status": {
"$ref": "#/definitions/v2/McpServerStartupState"
},
"threadId": {
"default": null,
"description": "Identifier of the thread whose `McpConnectionManager` produced this update. Always set on notifications emitted by current servers; remains `Option` so legacy clients that omit the field still deserialise and route as a global event.",
"type": [
"string",
"null"
]
}
},
"required": [