Keep AutoDetect channel open after provisional SSE failure - #1768
Open
PranavSenthilnathan wants to merge 2 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c0e71f8e-9302-4c6b-835d-223dec24d37d
Contributor
There was a problem hiding this comment.
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. |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c0e71f8e-9302-4c6b-835d-223dec24d37d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,
SseClientSessionTransportcurrently completes that shared channel. Connect-time protocol fallback may subsequently retry withinitializeusing 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
No public API is added or changed.
How Has This Been Tested?
dotnet buildnet10.0,net9.0,net8.0, andnet472The 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.