perf(mcp): non-blocking startup via background MCP discovery#32811
Open
Prontsevich wants to merge 2 commits into
Open
perf(mcp): non-blocking startup via background MCP discovery#32811Prontsevich wants to merge 2 commits into
Prontsevich wants to merge 2 commits into
Conversation
Collaborator
|
Related competing PRs for #29726 (MCP startup hang):
Also note #25622 (open) — fixes tool registration race on startup. Background discovery may interact with the same race window if tools aren't registered before the first user message arrives. |
418886a to
1c95d71
Compare
This was referenced May 30, 2026
…st path
Fire-and-forget MCP server connections on a daemon thread so the
gateway / CLI / ACP process becomes interactive immediately instead
of blocking on slow remote MCP servers (HTTP timeouts, sluggish
stdio boot). Previously `hermes --tui` waited 2-5 s after the splash
screen before rendering the UI while `discover_mcp_tools()` ran
synchronously on the critical path.
Changes:
- tools/mcp_tool.py: add `discover_mcp_tools_background()` — thin
wrapper that spawns `discover_mcp_tools()` on a named daemon thread
- tui_gateway/entry.py: call `discover_mcp_tools_background()` before
sending gateway.ready (replaces inline call that blocked the JSON-RPC
pipe for the TUI Ink app)
- hermes_cli/main.py:
- skip `\_prepare_agent_startup()` for TUI path — plugins, MCP, and
shell hooks are only needed by the CLI agent loop; the TUI's
gateway subprocess discovers them independently (~370 ms saved)
- fast-path in `\_make_tui_argv()`: when `dist/entry.js` exists and
is fresh, skip npm install / rebuild checks entirely (~350 ms saved)
- cli.py (`\_prepare_deferred_agent_startup`): same background pattern
for deferred startup (Termux interactive CLI)
- acp_adapter/entry.py: same pattern so ACP server launches asyncio
immediately while MCP connects in parallel
Result:
- TUI Python wrapper: ~730 ms → ~80 ms (9× faster)
- gateway.ready: ~2700 ms → ~400 ms (7× faster)
- Total TUI cold start: ~3400 ms → ~480 ms
Related: NousResearch#29726, NousResearch#29184, NousResearch#19326 (closed stale)
Closes NousResearch#29726
1c95d71 to
4e13266
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fire-and-forget MCP server connections on a daemon thread so the gateway / CLI / ACP process becomes interactive immediately.
Previously
hermes --tuiwaited 2-5 s after the splash screen before rendering the UI whilediscover_mcp_tools()ran synchronously on the critical path.Changes:
tools/mcp_tool.py: newdiscover_mcp_tools_background()— daemon thread wrappertui_gateway/entry.py,hermes_cli/main.py,cli.py,acp_adapter/entry.py: use background variantRelated: #29726, #29184, #19326 (closed stale)
Closes: #29726