fix(mcp): raise headless discovery timeout and add HERMES_MCP_DISCOVERY_WAIT override - #37301
Open
Kewe63 wants to merge 2 commits into
Open
fix(mcp): raise headless discovery timeout and add HERMES_MCP_DISCOVERY_WAIT override#37301Kewe63 wants to merge 2 commits into
Kewe63 wants to merge 2 commits into
Conversation
…RY_WAIT override — fixes NousResearch#37013 In hermes -z (headless/oneshot) mode, wait_for_mcp_discovery() used a hardcoded 0.75 s timeout. Container- and stdio-backed MCP servers with a real process cold-start (typically 1-2 s) consistently missed this window, leaving the agent with a frozen partial toolset for the entire session. Changes: - hermes_cli/mcp_startup.py: wait_for_mcp_discovery() now resolves the effective timeout in order: HERMES_MCP_DISCOVERY_WAIT env var → mcp.discovery_wait config.yaml key → caller argument. - tui_gateway/entry.py: same resolution logic applied to the duplicate implementation there. - cli.py: both headless call sites now pass timeout=5.0 as the default (overridable via env/config) instead of the 0.75 s legacy default. Tests: 5 new regression tests in test_mcp_discovery_timeout.py, 13/13 passed (8 existing + 5 new).
This was referenced Jun 10, 2026
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for targeting the real slow-MCP discovery failure reported in #37013.
Problems
- Current main already centralizes this setting as
mcp_discovery_timeoutinhermes_cli/mcp_startup.py:53-71, andtui_gateway/entry.py:226-232delegates to that resolver. The proposedHERMES_MCP_DISCOVERY_WAITand duplicatedmcp.discovery_waitlogic would diverge from that design; it also adds a non-secret behavioral environment variable contrary toAGENTS.md. - The
cli.py_init_agenthunk no longer targets current code: it moved tohermes_cli/cli_agent_setup_mixin.py:218-239in094aa85c3. tests/hermes_cli/test_mcp_discovery_timeout.py:90simulates the desired call by directly invoking the mocked helper; it does not verify a realhermes -zcaller.
Suggested changes
- Re-scope onto the existing
mcp_discovery_timeoutresolver and add a real one-shot startup-path regression test. Commitb6e2a54adeliberately reduced the global default to 1.5s after adding cache-safe between-turn refresh, so a 5s one-shot-specific policy needs to be made explicitly against the current architecture.
Automated hermes-sweeper review.
|
|
||
| monkeypatch.setattr(mcp_startup, "wait_for_mcp_discovery", _fake_wait) | ||
|
|
||
| # Simulate what cli.py headless path does |
Contributor
There was a problem hiding this comment.
This only calls the monkeypatched helper directly, so it cannot detect a regression in either real headless caller. Please test the actual hermes -z startup/agent-build path with an in-flight discovery thread.
…meout test Teknium's review noted that test_headless_caller_passes_5s was calling the monkeypatched helper directly, so a regression in the actual cli.py headless caller would go undetected. Now the test drives cli.get_tool_definitions() with an in-flight discovery thread, confirming the real caller passes timeout=5.0.
This was referenced Aug 3, 2026
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.
Description
Problem
When running in
hermes -z(headless/oneshot) mode, Model Context Protocol (MCP) servers that take longer than 0.75 seconds to connect are silently dropped. Container- and stdio-backed servers requiring a real process cold-start (typically 1–2 seconds) consistently miss this narrow initialization window. Because the toolset is frozen at session startup and never refreshed, the agent operates throughout the entire session as if these tools do not exist.Root Cause
The
wait_for_mcp_discovery()function utilized a hardcoded 0.75-second default timeout, offering no mechanism for overrides via environment variables or configuration files. Furthermore, the headless execution path incli.pyinvoked this function without arguments, leaving deployments without any escape hatch to handle slower server spin-ups.Solution
hermes_cli/mcp_startup.py: Refactoredwait_for_mcp_discovery()to resolve the effective timeout dynamically using the following order of precedence:HERMES_MCP_DISCOVERY_WAITenvironment variable (float, in seconds)mcp.discovery_waitkey defined inconfig.yamltimeoutargument provided by the callertui_gateway/entry.py: Applied the identical resolution logic to the duplicate implementation found here.cli.py: Updated both headless call sites to passtimeout=5.0as the new, safer default (which remains fully overridable via env/config).Technical Changes
Testing Handled
Added 5 new regression tests in
tests/hermes_cli/test_mcp_discovery_timeout.pyto validate the fallback hierarchy and behaviors:0skips the wait duration immediately.Test Results: All 13 tests passed successfully (8 existing + 5 new).
Impact
HERMES_MCP_DISCOVERY_WAIT=10or appendmcp: {discovery_wait: 10}toconfig.yamlwithout modifying the codebase.Fixes #37013