mirror of
https://github.com/usestrix/strix.git
synced 2026-10-13 03:57:59 +00:00
fix(mcp): replace terminally dead sessions
This commit is contained in:
parent
b3c561ee7b
commit
96e2d74825
2 changed files with 33 additions and 0 deletions
|
|
@ -143,8 +143,10 @@ class McpConnectionEntry:
|
|||
self._status_sink()
|
||||
|
||||
def _on_dead(self) -> None:
|
||||
self.session = None
|
||||
self._catalog = None
|
||||
self._catalog_task = None
|
||||
self._retry_after = time.monotonic() + _RETRY_DELAY_SECONDS
|
||||
self._set_state("unavailable")
|
||||
|
||||
async def ensure_connected(self) -> SupervisedMcpSession:
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ from strix.tools.mcp import (
|
|||
search_mcp_tools,
|
||||
)
|
||||
from strix.tools.mcp import client as mcp_client
|
||||
from strix.tools.mcp import registry as mcp_registry_mod
|
||||
from strix.tools.mcp import session as mcp_session_mod
|
||||
|
||||
|
||||
|
|
@ -578,6 +579,36 @@ async def test_registered_entry_connects_and_lists_once_for_concurrent_catalog_r
|
|||
await registry.close()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_registered_entry_replaces_a_terminally_dead_session(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
config = _config("docs", ["fetch_page"])
|
||||
original = SupervisedMcpSession.adopt(
|
||||
FakeMCPServer("docs", [_mcp_tool("fetch_page")]),
|
||||
name="docs",
|
||||
config=config,
|
||||
)
|
||||
replacement_server = FakeMCPServer("docs", [_mcp_tool("fetch_page")])
|
||||
monkeypatch.setattr(
|
||||
mcp_client,
|
||||
"_build_server",
|
||||
lambda _config: _built_server(replacement_server),
|
||||
)
|
||||
monkeypatch.setattr(mcp_registry_mod, "_RETRY_DELAY_SECONDS", 0)
|
||||
registry = McpRegistry()
|
||||
entry = registry.add(name="docs", session=original, config=config)
|
||||
|
||||
original._mark_dead()
|
||||
|
||||
assert entry.session is None
|
||||
replacement = await entry.ensure_connected()
|
||||
assert replacement is not original
|
||||
assert replacement.server is replacement_server
|
||||
assert entry.state == "connected"
|
||||
await registry.close()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_registry_warmup_bounds_parallel_connections(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue