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
@@ -39,10 +39,10 @@ def create_sampling_callback(provider: Provider):
|
||||
if provider.supports_generation:
|
||||
callback = create_sampling_callback(provider)
|
||||
|
||||
async for session in create_mcp_client_session(
|
||||
async with create_mcp_client_session(
|
||||
url="http://localhost:8000/mcp",
|
||||
sampling_callback=callback,
|
||||
):
|
||||
) as session:
|
||||
# Session now supports sampling
|
||||
pass
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user