fix(mcp): propagate profile HERMES_HOME override into shared discovery owner; restore stdio startup + WSTransport tests

Follow-up to @LionGateOS's #72135 salvage:
- Route ensure_mcp_discovery_started through hermes_cli.mcp_startup's
  shared owner instead of a hand-rolled bare thread, keeping the start
  lock, retry-after-zero-connected allowance, and interactive-OAuth
  suppression. The shared owner now captures the caller's context-local
  HERMES_HOME override and re-installs it inside the discovery thread,
  so discovery reads the selected profile's mcp_servers (#67605).
- Restore stdio TUI startup discovery in main() and the
  _mcp_discovery_enabled retry gate in wait_for_mcp_discovery, both
  dropped by the original branch.
- Restore the 3 WSTransport regression tests (send serialization,
  cross-batch ordering, drained-token ordering) deleted by the PR.
- Harden the profile-scoped discovery test against sibling-state leaks.
This commit is contained in:
teknium1
2026-07-26 14:02:33 -07:00
committed by Teknium
parent a7bb123b4a
commit af8d698b41
4 changed files with 220 additions and 58 deletions
+28
View File
@@ -58,7 +58,28 @@ def start_background_mcp_discovery(*, logger, thread_name: str) -> None:
if not _has_configured_mcp_servers():
return
# Capture the caller's context-local HERMES_HOME override (profile
# scoping in multi-profile processes like the dashboard/desktop
# backend) and re-install it inside the discovery thread. ContextVars
# do not propagate into bare threads, so without this a session
# "switched" to profile X would discover the LAUNCH profile's
# mcp_servers instead (#67605). The config gate above already runs on
# the caller's thread, so it sees the same override.
try:
from hermes_constants import get_hermes_home_override
home_override = get_hermes_home_override()
except Exception:
home_override = None
def _discover() -> None:
token = None
try:
from hermes_constants import set_hermes_home_override
token = set_hermes_home_override(home_override)
except Exception:
token = None
try:
_discover_mcp_tools_without_interactive_oauth()
try:
@@ -73,6 +94,13 @@ def start_background_mcp_discovery(*, logger, thread_name: str) -> None:
except Exception:
logger.debug("Background MCP tool discovery failed", exc_info=True)
finally:
if token is not None:
try:
from hermes_constants import reset_hermes_home_override
reset_hermes_home_override(token)
except Exception:
pass
with _mcp_discovery_lock:
global _mcp_discovery_thread, _mcp_discovery_started
_mcp_discovery_thread = None