fix(tests): convert create_mcp_client_session to asynccontextmanager
The multi-user-basic integration job was consistently failing with `CancelledError: Cancelled via cancel scope ... by <async_generator_athrow>` followed by a cascade of `anyio.ClosedResourceError` in every subsequent test. Root cause: `create_mcp_client_session` was declared as an async generator driven by `async for session in ...:`, so Python's generator finalizer (`aclose`) ran under pytest-asyncio's cleanup task instead of the task that owned the nested `streamablehttp_client` cancel scope. anyio then raised when the inner task group saw its scope being exited from a foreign task, leaving the memory object streams half-closed and poisoning the rest of the session. Switching to `@asynccontextmanager` + `async with ... as session:` makes `__aenter__`/`__aexit__` run in the frame that owns the context manager, satisfying anyio's structured concurrency requirements. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
9b6b554155
commit
3935f45be8
@@ -227,11 +227,11 @@ async def nc_mcp_client_with_sampling(
|
||||
"""
|
||||
sampling_callback = create_sampling_callback(generation_provider)
|
||||
|
||||
async for session in create_mcp_client_session(
|
||||
async with create_mcp_client_session(
|
||||
url="http://localhost:8000/mcp",
|
||||
client_name=f"Sampling MCP ({provider_name})",
|
||||
sampling_callback=sampling_callback,
|
||||
):
|
||||
) as session:
|
||||
yield session
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user