Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10874,7 +10874,7 @@ def _confirm_and_reload_mcp(self, cmd_original: str = "") -> None:

if not confirm_required:
with self._busy_command(self._slow_command_status(cmd_original)):
self._reload_mcp()
self._run_reload_mcp_with_timeout()
return

# Render warning + prompt. Use the same prompt_toolkit-native composer
Expand Down Expand Up @@ -10914,7 +10914,20 @@ def _confirm_and_reload_mcp(self, cmd_original: str = "") -> None:
print("⚠️ Couldn't persist opt-out — reloading once.")

with self._busy_command(self._slow_command_status(cmd_original)):
self._reload_mcp()
self._run_reload_mcp_with_timeout()

def _run_reload_mcp_with_timeout(self, timeout_seconds: float = 30.0) -> bool:
"""Run MCP reload on a worker thread so slash-command input stays recoverable."""
reload_thread = threading.Thread(target=self._reload_mcp, daemon=True)
reload_thread.start()
reload_thread.join(timeout=timeout_seconds)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This join() still blocks the command-processing thread for the default 30 seconds. Current main removed the equivalent config-watcher join in 972aa33d3 because it froze process_loop; please return immediately after starting the daemon worker instead.

if reload_thread.is_alive():
print(
f" ⚠️ MCP reload timed out ({timeout_seconds:g}s). "
"Some servers may still be reconnecting."
)
return False
return True

def _reload_mcp(self):
"""Reload MCP servers: disconnect all, re-read config.yaml, reconnect.
Expand Down
25 changes: 25 additions & 0 deletions tests/cli/test_cli_loading_indicator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Regression tests for loading feedback on slow slash commands."""

import threading
import time
from unittest.mock import patch

from cli import HermesCLI
Expand Down Expand Up @@ -47,6 +49,7 @@ def test_reload_mcp_sets_busy_state_and_prints_status(self, capsys):
def fake_reload():
seen["running"] = cli_obj._command_running
seen["status"] = cli_obj._command_status
seen["thread_id"] = threading.get_ident()
print("reload done")

# /reload-mcp now wraps the actual reload in a prompt-cache-invalidation
Expand All @@ -66,7 +69,29 @@ def fake_reload():
assert seen == {
"running": True,
"status": "Reloading MCP servers...",
"thread_id": seen["thread_id"],
}
assert seen["thread_id"] != threading.get_ident()
assert cli_obj._command_running is False
assert cli_obj._command_status == ""
assert invalidate_mock.call_count == 2

def test_reload_mcp_timeout_warns_without_blocking_forever(self, capsys):
cli_obj = self._make_cli()
stop_event = threading.Event()

def fake_reload():
stop_event.wait(0.1)

with patch.object(cli_obj, "_reload_mcp", side_effect=fake_reload), \
patch.object(cli_obj, "_invalidate"):
start = time.monotonic()
result = cli_obj._run_reload_mcp_with_timeout(timeout_seconds=0.01)
elapsed = time.monotonic() - start

stop_event.set()

output = capsys.readouterr().out
assert result is False
assert elapsed < 0.05
assert "MCP reload timed out (0.01s)." in output
Loading