Skip to content

fix(tui): suppress MCP discovery in slash_worker to prevent duplicate serve children (#15275)#15440

Closed
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/tui-slash-worker-skip-mcp-discovery
Closed

fix(tui): suppress MCP discovery in slash_worker to prevent duplicate serve children (#15275)#15440
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/tui-slash-worker-skip-mcp-discovery

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

The TUI spawns duplicate hermes mcp serve child processes per session. Both tui_gateway/server.py (agent creation path) and tui_gateway/slash_worker.py (slash command worker) independently bootstrap MCP tools, each triggering discover_mcp_tools() and spawning its own set of MCP server processes. The slash worker only needs CLI command processing, not MCP-backed tools.

Related Issue

Fixes #15275

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • tui_gateway/slash_worker.py: Set HERMES_MCP_DISCOVERY=0 unconditionally before importing/constructing HermesCLI, suppressing MCP discovery in the worker process.
  • tui_gateway/server.py: When spawning the slash worker subprocess, explicitly set HERMES_MCP_DISCOVERY=0 in the subprocess environment to prevent parent env leakage (e.g., if parent has HERMES_MCP_DISCOVERY=1).
  • model_tools.py: Added a guard in the MCP discovery path that checks HERMES_MCP_DISCOVERY env var — skips discover_mcp_tools() when set to "0".

How to Test

  1. Run:
    python -m pytest tests/tui_gateway/test_slash_worker_mcp.py -v
  2. 6 tests cover:
    • Env var is set before CLI import in worker
    • CLI is not imported at module level (AST check)
    • Guard logic for both suppressed and default paths
    • Subprocess env override at spawn time

Tested on macOS (Python 3.11).

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15 (Darwin 24.6.0)

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

python -m pytest tests/tui_gateway/test_slash_worker_mcp.py -v
# 6 tests pass

… serve children (NousResearch#15275)

The slash_worker creates a HermesCLI which imports model_tools, triggering
discover_mcp_tools() at module scope.  Meanwhile, the TUI server also calls
MCP discovery independently.  Both paths spawn ``hermes mcp serve`` child
processes per session.

Fix: defer the cli import in slash_worker to main() and set
HERMES_MCP_DISCOVERY=0 beforehand.  model_tools now checks this env var
and skips MCP discovery when suppressed.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tui Terminal UI (ui-tui/ + tui_gateway/) tool/mcp MCP client and OAuth labels Apr 25, 2026
@Tranquil-Flow

Copy link
Copy Markdown
Contributor Author

Closing — the duplicate-MCP-child symptom can't reproduce on main: tui_gateway/slash_worker.py no longer touches MCP at all.

Verified by grep -c mcp tui_gateway/slash_worker.py → 0. The slash-worker is now 76 lines with zero MCP references; the discovery side-effect that was spawning a parallel set of hermes mcp serve children is gone. model_tools.py:183 confirms the module-level call was removed upstream (per a different fix — #16856 area, the 120s freeze via blocking future.result). The HERMES_MCP_DISCOVERY=0 env-var this PR introduced is no longer needed since the path doesn't exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: TUI session eagerly spawns duplicate 'hermes mcp serve' children from both tui_gateway.entry and slash_worker

2 participants