Skip to content

Keep AutoDetect channel open after provisional SSE failure - #1768

Open
PranavSenthilnathan wants to merge 2 commits into
modelcontextprotocol:mainfrom
PranavSenthilnathan:pranavsenthilnathan-fix-http-transport-fallback-infrastructu
Open

Keep AutoDetect channel open after provisional SSE failure#1768
PranavSenthilnathan wants to merge 2 commits into
modelcontextprotocol:mainfrom
PranavSenthilnathan:pranavsenthilnathan-fix-http-transport-fallback-infrastructu

Conversation

@PranavSenthilnathan

Copy link
Copy Markdown
Contributor

Motivation and Context

When AutoDetect tries Streamable HTTP and then provisionally falls back to SSE, both transports use the message channel owned by the AutoDetectingClientSessionTransport.

If the provisional SSE connection fails, SseClientSessionTransport currently completes that shared channel. Connect-time protocol fallback may subsequently retry with initialize using the same AutoDetect instance, but its reader can no longer receive the response because the channel has already completed.

Streamable HTTP already distinguishes provisional use from an adopted transport. This change gives SSE equivalent behavior.

This is a prerequisite for handling the AutoDetect scenario in #1765.

Changes

  • Track whether SSE has been adopted based on a successful initial POST.
  • Leave AutoDetect’s message channel open when a provisional SSE attempt fails.
  • Preserve existing channel completion behavior for explicit SSE and successfully adopted SSE transports.
  • Add a regression test that fails Streamable HTTP and provisional SSE, then successfully retries using the same AutoDetect transport and message channel.

No public API is added or changed.

How Has This Been Tested?

  • dotnet build
  • AutoDetect transport tests on net10.0, net9.0, net8.0, and net472
  • Full core test suites

The ASP.NET conformance suite could not start locally because Node.js 21.6.2 does not provide fs.globSync, which is required by the pinned conformance package.

Breaking Changes

None.

This pull request description was generated with GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c0e71f8e-9302-4c6b-835d-223dec24d37d

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an AutoDetect transport failure mode where a provisional SSE fallback attempt could complete the shared message channel, preventing subsequent retries (e.g., retrying initialize) from receiving responses via the same AutoDetectingClientSessionTransport. It aligns SSE behavior with Streamable HTTP’s “provisional vs adopted” distinction.

Changes:

  • Track when SSE is “adopted” (after a successful POST) and only complete the shared channel on disconnect once adopted.
  • Update SSE disconnect handling to avoid completing AutoDetect’s shared channel during provisional SSE probe failures.
  • Add a regression test covering Streamable HTTP failure + provisional SSE failure + successful retry using the same AutoDetect instance/channel.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/ModelContextProtocol.Tests/Transport/HttpClientTransportAutoDetectTests.cs Adds regression coverage ensuring the shared message channel remains usable after provisional SSE failure in AutoDetect mode.
src/ModelContextProtocol.Core/Client/SseClientSessionTransport.cs Introduces “adoption” tracking and conditional disconnect completion to keep AutoDetect’s shared channel open during provisional SSE failures.

Comment thread src/ModelContextProtocol.Core/Client/SseClientSessionTransport.cs
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c0e71f8e-9302-4c6b-835d-223dec24d37d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants