fix(mcp): rediscover dead cached servers on session startup - #50184
Closed
izumi0uu wants to merge 1 commit into
Closed
fix(mcp): rediscover dead cached servers on session startup#50184izumi0uu wants to merge 1 commit into
izumi0uu wants to merge 1 commit into
Conversation
A dead MCPServerTask could remain parked in _servers after keepalive/reconnect failure, so later session startup treated the server name as already connected and skipped fresh discovery. Reconnect only when the cached entry has neither a live session nor a live background task, while preserving in-flight in-process reconnect ownership. Constraint: Keep the fix narrow to stale _servers startup gating for issue NousResearch#50170 Rejected: Force fresh connect whenever session is None | would race legitimate in-flight reconnects and duplicate a live server task Confidence: high Scope-risk: narrow Directive: Treat _servers membership as authoritative only while the cached task is still live or the session is still attached Tested: ./.venv/bin/pytest -q tests/tools/test_mcp_tool.py -k "reconnects_server_entry_that_exists_but_is_not_connected or skips_server_that_is_mid_reconnect_with_live_background_task or skips_already_connected_servers or connects_new_servers or logs_summary_on_success"; ./.venv/bin/pytest -q tests/agent/test_turn_context.py -k "between_turns_refresh"; ./.venv/bin/pytest -q tests/test_get_tool_definitions_cache_isolation.py Not-tested: full pytest tests/ -q
teknium1
added a commit
that referenced
this pull request
Jul 6, 2026
register_mcp_servers now nudges cached entries whose session is None via _signal_reconnect, so a new agent session recovers a parked server immediately instead of waiting up to _PARKED_RETRY_INTERVAL for the next self-probe (#50170). Gate-check idea credit: @izumi0uu (#50184), @LeonSGP43 (#37772), @Tranquil-Flow (#37899).
teknium1
added a commit
that referenced
this pull request
Jul 6, 2026
register_mcp_servers now nudges cached entries whose session is None via _signal_reconnect, so a new agent session recovers a parked server immediately instead of waiting up to _PARKED_RETRY_INTERVAL for the next self-probe (#50170). Gate-check idea credit: @izumi0uu (#50184), @LeonSGP43 (#37772), @Tranquil-Flow (#37899).
Contributor
|
Closing with credit — the best-engineered PR in this cluster. Your |
habarmc1223-sudo
pushed a commit
to habarmc1223-sudo/hermes-agent-fluxmem
that referenced
this pull request
Jul 8, 2026
register_mcp_servers now nudges cached entries whose session is None via _signal_reconnect, so a new agent session recovers a parked server immediately instead of waiting up to _PARKED_RETRY_INTERVAL for the next self-probe (NousResearch#50170). Gate-check idea credit: @izumi0uu (NousResearch#50184), @LeonSGP43 (NousResearch#37772), @Tranquil-Flow (NousResearch#37899).
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
register_mcp_servers now nudges cached entries whose session is None via _signal_reconnect, so a new agent session recovers a parked server immediately instead of waiting up to _PARKED_RETRY_INTERVAL for the next self-probe (NousResearch#50170). Gate-check idea credit: @izumi0uu (NousResearch#50184), @LeonSGP43 (NousResearch#37772), @Tranquil-Flow (NousResearch#37899).
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
register_mcp_servers now nudges cached entries whose session is None via _signal_reconnect, so a new agent session recovers a parked server immediately instead of waiting up to _PARKED_RETRY_INTERVAL for the next self-probe (NousResearch#50170). Gate-check idea credit: @izumi0uu (NousResearch#50184), @LeonSGP43 (NousResearch#37772), @Tranquil-Flow (NousResearch#37899).
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
register_mcp_servers now nudges cached entries whose session is None via _signal_reconnect, so a new agent session recovers a parked server immediately instead of waiting up to _PARKED_RETRY_INTERVAL for the next self-probe (NousResearch#50170). Gate-check idea credit: @izumi0uu (NousResearch#50184), @LeonSGP43 (NousResearch#37772), @Tranquil-Flow (NousResearch#37899).
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.
What does this PR do?
Fixes a stale-MCP startup bug where a dead
MCPServerTaskcould remain parked intools.mcp_tool._serversafter keepalive/reconnect failure. Later session startup only checkedname in _servers, so it skipped fresh MCP discovery and the new session silently lost that server's tools.This change only treats a cached MCP server as already connected when it still has a live
sessionor a live background reconnect task. If the cached task is dead and detached, startup rediscovery reconnects it and re-registers its tools.Related Issue
Fixes #50170
Type of Change
Changes Made
_server_is_connected(...)intools/mcp_tool.pyso startup gating distinguishes live/recovering MCP tasks from dead cached entries.register_mcp_servers()anddiscover_mcp_tools()to rediscover only dead cached servers, while preserving legitimate in-flight reconnect ownership.tests/tools/test_mcp_tool.pyfor both:How to Test
_serverswithsession=Noneand no live background task../.venv/bin/pytest -q tests/tools/test_mcp_tool.py -k "reconnects_server_entry_that_exists_but_is_not_connected or skips_server_that_is_mid_reconnect_with_live_background_task or skips_already_connected_servers or connects_new_servers or logs_summary_on_success".Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Targeted validation:
./.venv/bin/pytest -q tests/tools/test_mcp_tool.py -k "reconnects_server_entry_that_exists_but_is_not_connected or skips_server_that_is_mid_reconnect_with_live_background_task or skips_already_connected_servers or connects_new_servers or logs_summary_on_success"./.venv/bin/pytest -q tests/agent/test_turn_context.py -k "between_turns_refresh"./.venv/bin/pytest -q tests/test_get_tool_definitions_cache_isolation.py