Repository navigation
fix: Reject null-ID results on message streams - #414
Open
EhsanAzish80 wants to merge 2 commits into
Open
EhsanAzish80 wants to merge 2 commits into
EhsanAzish80 wants to merge 2 commits into
Conversation
The server decoded responses before classifying the wire message, so a result with id null was read as an empty-string response and left unanswered. Use the shared JSON-RPC classifier before handling a response, and turn the known-issue test into a regression test. JSON-RPC 2.0 section 5 reserves null for an unknown response ID.
varun06
reviewed
Dec 4, 2026
| } | ||
| } | ||
| } else if let response = try? decoder.decode(AnyResponse.self, from: data) { | ||
| } else if JSONRPCMessageKind(data: data)?.isResponse == true, |
Contributor
There was a problem hiding this comment.
Reuse the server's decoder (matching the .invalid branch below) instead of allocating a fresh JSONDecoder per message:
Suggested change
| } else if JSONRPCMessageKind(data: data)?.isResponse == true, | |
| } else if (try? decoder.decode(JSONRPCMessageKind.self, from: data))?.isResponse == true, |
Comment on lines
+1574
to
+1575
| #"{"jsonrpc":"2.0","id":null,"result":{}}"#, | ||
| #"{"jsonrpc":"2.0","id":null,"method":"tools/list","result":{}}"#, |
Contributor
There was a problem hiding this comment.
This change also makes null-ID error messages carrying method receive -32600 (matching HTTP and batch handling); consider adding a case for it:
Suggested change
| #"{"jsonrpc":"2.0","id":null,"result":{}}"#, | |
| #"{"jsonrpc":"2.0","id":null,"method":"tools/list","result":{}}"#, | |
| #"{"jsonrpc":"2.0","id":null,"result":{}}"#, | |
| #"{"jsonrpc":"2.0","id":null,"method":"tools/list","result":{}}"#, | |
| #"{"jsonrpc":"2.0","id":null,"method":"tools/list","error":{"code":-32603,"message":"x"}}"#, |
Contributor
Author
Use the server decoder when classifying stream messages. Cover a null-ID error that also carries a method in the existing wire test.
Contributor
|
Nice catch, thanks! We're doing a API consolidation on our end and hope to get that on GitHub in the next couple of days. We can rebase your branch onto it once it's there. |
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
The server read a response before checking whether it was valid on the wire. A successful result with
id: nullwas treated as a response with an empty string ID, so the server sent nothing back. This follows up on #401 and makes stream handling match the HTTP and batch paths.How Has This Been Tested?
methodfield.swift buildandswift testpassed: 1,958 tests, no known issues.AI helped write the tests; I ran them.
Breaking Changes
None. No public API changes.
Types of changes