Repository navigation
Avoid _request_streams key collisions in StreamableHTTPServerTransport - #3982
Closed
aadityabuilds wants to merge 1 commit into
Closed
aadityabuilds wants to merge 1 commit into
aadityabuilds wants to merge 1 commit into
Conversation
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.
Summary
Fixes key collisions in
StreamableHTTPServerTransport._request_streams,_sse_stream_writers, andEventStorestream IDs:"id": "_GET_stream"previously collided withGET_STREAM_KEY = "_GET_stream", hijacking in-flight unsolicited notifications into the POST response and tearing down the active standalone GET SSE stream on completion."id": 1and"id": "1"both mapped tostr(message.id) == "1", overwriting and leaking streams and hanging the displaced request.Changes
_request_stream_id(request_id)mappingintIDs to"int:<id>"andstrIDs to"str:<id>", disjoint fromGET_STREAM_KEY("_GET_stream")._request_streams,_sse_stream_writers,_run_sse_writer,_clean_up_memory_streams, POST handling, and response routing to key byStreamIdvia_request_stream_id()._close_stream(stream_id)soclose_sse_stream(request_id)andclose_standalone_sse_stream()route to their respective namespaces cleanly.tests/server/test_streamable_http_router.pycovering both GET-stream displacement and concurrentint/strID collisions.Verification
uv run --frozen pytest tests/server/test_streamable_http_router.py tests/server/test_streamable_http_manager.py tests/shared/test_streamable_http.py tests/interaction/transports/test_hosting_resume.py -q— 139 passed (both new regression tests failed on unmodifiedmain).ruff,pyright, andstrict-no-coverclean.