Skip to content

fix: retry transient streamable-http MCP failures on isolated session#2699

Closed
elainegan-openai wants to merge 1 commit intomainfrom
dev/elainegan/streamable-http-isolated-transient-retry
Closed

fix: retry transient streamable-http MCP failures on isolated session#2699
elainegan-openai wants to merge 1 commit intomainfrom
dev/elainegan/streamable-http-isolated-transient-retry

Conversation

@elainegan-openai
Copy link
Contributor

@elainegan-openai elainegan-openai commented Mar 17, 2026

Summary

  • retry a streamable-HTTP MCP tool call on a fresh isolated session when the shared session hits a transient transport failure
  • keep shared-session healthy-path parallelism; only isolate on the failure path
  • add focused regression tests for cancelled sibling calls, 5xx retry, 4xx no-retry, and preserved outer cancellation

Why

The likely remaining bug is earlier in the chain than MCPUtil.invoke_mcp_tool(): one shared-session streamable-HTTP request failure can still fan out into sibling request cancellations. This patch keeps the normal shared session on the healthy path, but retries just the affected call on an isolated session when the shared session sees a transient transport failure.

Concretely, the isolated retry triggers for:

  • asyncio.CancelledError
  • httpx.ConnectError
  • httpx.TimeoutException
  • httpx.HTTPStatusError with status >= 500
  • BaseExceptionGroup containing one of the above

It does not retry 4xx errors.

Validation

  • uv run pytest -q tests/mcp/test_client_session_retries.py
  • uv run mypy src/agents/mcp/server.py tests/mcp/test_client_session_retries.py
  • ruff check src/agents/mcp/server.py tests/mcp/test_client_session_retries.py

@github-actions github-actions bot added bug Something isn't working feature:mcp labels Mar 17, 2026
@seratch
Copy link
Member

seratch commented Mar 18, 2026

Closing this in favor of #2703

@seratch seratch closed this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:mcp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants