fix(client): treat a JSON-RPC error response as a terminal response - #2638
Open
latent-9 wants to merge 1 commit into
Open
fix(client): treat a JSON-RPC error response as a terminal response#2638latent-9 wants to merge 1 commit into
latent-9 wants to merge 1 commit into
Conversation
_handleSseStream only marked receivedResponse for result responses, so a request whose SSE POST stream ended with a JSON-RPC error response was treated as incomplete. The client then scheduled needless reconnections and, on the resume path, failed to remap the message id. An error response is a terminal response just like a result, so include isJSONRPCErrorResponse in the guard, matching the behavior already on main. Add a regression test with an error response as the terminal message.
|
commit: |
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
In
StreamableHTTPClientTransport,_handleSseStreammarks a request as complete only for result responses:A JSON-RPC 2.0 error response is a terminal response to a request just like a result response (a Response Object carries either
resultorerror). Because the guard omits the error case, when a request's SSE POST stream ends with an error response and closes gracefully,receivedResponsestaysfalse, soneedsReconnect = canResume && !receivedResponseistrue.The client then schedules needless GET-SSE reconnections (up to
maxRetries, replaying withLast-Event-ID) for a request that is already complete, and on the resume path it never remapsmessage.idtoreplayMessageId, so a resumed error response can miss request/response correlation.The v2 code on
mainalready handles this correctly (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)); this backports the same fix tov1.x.Fix
Include
isJSONRPCErrorResponsein the guard so an error response also stops reconnection and gets its id remapped.Test
Added a regression test alongside the existing "should NOT reconnect a POST stream when response was received" case, using a JSON-RPC error response as the terminal message. It fails before the fix (fetch is called twice, the second being the needless reconnect) and passes after.