perf(cli): stop eager MCP discovery from blocking agent-capable startup#35397
Merged
Conversation
Contributor
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-assignment |
4 |
unresolved-import |
1 |
First entries
tests/hermes_cli/test_mcp_startup.py:150: [invalid-assignment] invalid-assignment: Object of type `() -> None` is not assignable to attribute `_install_tool_callbacks` of type `def _install_tool_callbacks(self) -> None`
tests/hermes_cli/test_mcp_startup.py:151: [invalid-assignment] invalid-assignment: Object of type `() -> None` is not assignable to attribute `_ensure_tirith_security` of type `def _ensure_tirith_security(self) -> None`
tests/hermes_cli/test_mcp_startup.py:152: [invalid-assignment] invalid-assignment: Object of type `() -> Literal[True]` is not assignable to attribute `_ensure_runtime_credentials` of type `def _ensure_runtime_credentials(self) -> bool`
tests/hermes_cli/test_mcp_startup.py:11: [unresolved-import] unresolved-import: Cannot resolve imported module `pytest`
tests/hermes_cli/test_mcp_startup.py:147: [invalid-assignment] invalid-assignment: Object of type `object` is not assignable to attribute `_session_db` of type `None | SessionDB`
✅ Fixed issues: none
Unchanged: 4934 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
2 tasks
This was referenced May 31, 2026
buptwz
added a commit
to buptwz/hermes-agent
that referenced
this pull request
Jun 4, 2026
…vered PR NousResearch#35397 introduced start_background_mcp_discovery() for hermes -z and hermes chat paths so that slow MCP servers don't block the CLI prompt. However it relied on a 0.75 s bounded wait_for_mcp_discovery() call in cli.py's _init_agent(), which is only reached by the interactive chat path — oneshot bypassed it entirely. The previous ensure_mcp_discovered() would call discover_mcp_tools() directly even when a background thread was already running it, risking a concurrent double-connection attempt against the same servers. Fix: detect the background thread via hermes_cli.mcp_startup and join() it without a timeout (appropriate for non-interactive paths where there is no prompt to display quickly). Fall through to a direct synchronous call only when no background thread exists (batch_runner, delegate_tool, background_review, curator, etc.). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 task
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.
Stops eager MCP discovery from freezing classic CLI startup (
hermes chat,hermes -z) when a configured MCP server is slow or dead.Companion to #35273, which fixed the same hang on the TUI path. This closes the non-TUI half: the classic CLI launcher (
hermes_cli/main.py::_prepare_agent_startup) still randiscover_mcp_tools()synchronously, so a dead server blocked the prompt before it appeared.Salvage of #35360 by @Sylw3ster, cherry-picked onto current
main(authorship preserved).Changes
hermes_cli/mcp_startup.py(new): one shared background discovery thread +wait_for_mcp_discovery(timeout=0.75)bounded join; cheap config probe skips the whole MCP stack for non-MCP users.hermes_cli/main.py: chat/oneshot/rl background discovery; TUI/gateway/ACP/cron keep their own dedicated startup (no double-run).cli.py: bounded wait before the first tool snapshot so fast servers still land.tests/hermes_cli/test_mcp_startup.py(new): backgrounding, TUI skip, bounded-join, init-agent wait.Validation
tests/hermes_cli/test_mcp_startup.py+test_startup_plugin_gating.py+test_chat_skills_flag.py— 45 passed on rebased main.Infographic