[type: bug] Fix concurrent tools/call response correlation by message id (#7041) - #7046
Open
zhang-arvin wants to merge 1 commit into
Open
[type: bug] Fix concurrent tools/call response correlation by message id (#7041)#7046zhang-arvin wants to merge 1 commit into
zhang-arvin wants to merge 1 commit into
Conversation
1 task
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.
Fixes #7041
Problem
StreamableHttpSessionTransportcaptured MCP framework responses in a singlelastSentMessageslot guarded byresponseReady. When multipletools/callrequests are processed concurrently on the same session, the response of request A can be overwritten by the response of request B, and A'sresetCapturedMessage()can then wipe out the response B just wrote. This yields cross-delivered responses, empty responses, or responses with the wrong JSON-RPC id.Fix
ConcurrentHashMap<String, JSONRPCMessage> messageResponseskeyed by the JSON-RPC response id to allow per-message correlation.sendMessage, keep the existinglastSentMessage/responseReadybehaviour (needed by the initialization handshake) and additionally storeJSONRPCResponsemessages inmessageResponseskeyed byresp.id().getLastSentMessage(Object messageId)which looks up the correlated response when a message id is available and falls back tolastSentMessageotherwise; the no-arggetLastSentMessage()andisResponseReady()are kept for existing callers.waitForTransportResponsenow first tries the id-correlated response and returns it with HTTP 200; when no correlated response exists it keeps the previous fallback (lastSentMessageand the synthetic success response).processWithExistingSessionclears only the response captured for the current message id via the newresetCapturedMessage(Object messageId)overload, without disturbing the handshake-related single slot.