Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
19347f3
fix(streaming): run MCP discovery off the turn's critical path
dankkush Aug 13, 2026
3b8a352
fix(streaming): assert profile home via contextvar in MCP discovery t…
dankkush Aug 13, 2026
68a3a42
fix(streaming): use version-gated override resolver in MCP discovery …
dankkush Aug 13, 2026
35d3e97
fix(streaming): bounded join + coalescing for background MCP discovery
dankkush Aug 14, 2026
99ea1a5
fix(streaming): synchronous fallback on agents without the home overr…
dankkush Aug 14, 2026
8228c2a
fix(streaming): profile-scoped MCP readiness instead of timed join
dankkush Aug 14, 2026
e017cf0
fix(streaming): generation-based single-flight MCP readiness
dankkush Aug 14, 2026
e088f4d
fix(commands): reload-mcp asserts the profile home during re-discovery
dankkush Aug 14, 2026
efe6309
fix(commands): reload-mcp authority is deterministic default profile
dankkush Aug 14, 2026
5a9e57b
fix(streaming): physically single-flight owners and canonical readine…
dankkush Aug 15, 2026
8c04b84
fix(commands): fail closed when a discovery owner survives the reload…
dankkush Aug 15, 2026
1fb90fc
fix(streaming): fence owner creation behind the reload teardown window
dankkush Aug 15, 2026
2736411
fix(streaming): hold the reload fence across the entire rebuild
dankkush Aug 15, 2026
118ca77
fix(commands): phase-split the reload fence; never stall first turns
dankkush Aug 17, 2026
9b96ad3
fix(streaming): timeout retirement wakes peer waiters
dankkush Aug 17, 2026
00380f4
fix(streaming): refreshable readiness, canonical keys, wait-loop hard…
dankkush Aug 24, 2026
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
69 changes: 67 additions & 2 deletions api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import annotations
from contextlib import nullcontext
import logging
import os
import threading
from typing import Any

Expand Down Expand Up @@ -270,7 +271,57 @@ def _run_reload_mcp_command() -> str:
old_servers = set(_servers.keys())

shutdown_mcp_servers()
new_tools = discover_mcp_tools()

# Route the re-discovery through the SAME readiness authority
# the stream worker uses (api.streaming), so a subsequent turn
# observes the fresh outcome instead of a stale 'completed' /
# 'failed' readiness recorded before this reload. The command
# waits on the shared readiness event so its synchronous
# report below is still accurate. The profile home is taken
# from the exec-time env: inside a session that is the
# worker's env window; otherwise it resolves to the default
# profile (''), which is the authority the startup kickoff
# and default-profile turns consult.
from api.streaming import _mcp_retry_discovery, _mcp_wait_readiness

def _reload_discover():
"""Re-discover MCP tools; returns bool.

Installs the captured profile-home override exactly like
the stream worker's discovery closure, so a background
reload run can never read another stream's HERMES_HOME
after env mutation (Greptile P1).
"""
_mcp_home_token = None
try:
from api.profiles import _resolve_hermes_home_override
_hc_mod = _resolve_hermes_home_override()
if _hc_mod is not None:
_mcp_home = _profile_home
if not _mcp_home:
_mcp_home = getattr(
_hc_mod, 'get_default_hermes_root', lambda: ''
)()
if _mcp_home:
_mcp_home_token = _hc_mod.set_hermes_home_override(
str(_mcp_home)
)
try:
discover_mcp_tools()
return True
except Exception:
return False
finally:
if _mcp_home_token is not None:
_hc_mod.reset_hermes_home_override(_mcp_home_token)
except Exception:
return False
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

_profile_home = str(os.environ.get("HERMES_HOME", "") or "")
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
_readiness = _mcp_retry_discovery(
_profile_home, _reload_discover, "mcp-reload"
)
_reload_status = _mcp_wait_readiness(_readiness)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

with _lock:
connected_servers = set(_servers.keys())
Expand All @@ -291,10 +342,24 @@ def _run_reload_mcp_command() -> str:
lines.append(f"Removed: {', '.join(sorted(removed))}")

if connected_servers:
lines.append(f"{len(new_tools or [])} tool(s) available across {len(connected_servers)} server(s)")
_tool_count = 0
for _server_name in connected_servers:
try:
_tool_count += len(
getattr(_servers[_server_name], "_registered_tool_names", [])
or []
)
except Exception:
pass
lines.append(
f"{_tool_count} tool(s) available across {len(connected_servers)} server(s)"
)
else:
lines.append("No MCP servers connected")

if _reload_status == "failed":
lines.append("MCP discovery failed during reload — check the server logs")

if not reconnected and not added and not removed:
lines.append("Tooling state was already current")

Expand Down
Loading