Repository navigation
internal/jsonrpc2: reply with -32600 and omitted ID on duplicate in-flight ID - #1550
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The SDK decoder rejects the ID-less error response, stopping the IO read loop and failing all outstanding calls, so decoding must allow it and a regression test must verify the original response is still processed.
1 open issue
What changed in this PR
Addresses #1541 by making the SDK’s JSON-RPC layer return a -32600 error with the ID omitted when a request reuses an in-flight ID, while preserving the original request’s tracking.
Changes:
- Reject duplicate IDs without mutating the incoming request.
- Extract shared response-writing and request-cleanup helpers.
- Add regression tests for error encoding, original-call completion and cancellation, and sequential ID reuse.
| File | Description |
|---|---|
mcp/transport_test.go |
Adds an IO transport test for duplicate rejection and continued session use. |
internal/jsonrpc2/conn.go |
Sends ID-less duplicate errors and extracts shared response and cleanup logic. |
internal/jsonrpc2/conn_test.go |
Tests duplicate rejection, original-call tracking, cancellation, and later ID reuse. |
Review effort: Balanced
chrikrah
left a comment
There was a problem hiding this comment.
@nahapetyan-serob nothing blocks this. With the base conn.go and messages.go the duplicate call hangs the jsonrpc2 package until the test timeout.
$ go test ./internal/jsonrpc2/ ./mcp/ # head 5f948e1, git archive export, go1.27.1
ok internal/jsonrpc2 0.006s
ok mcp 36.445s
# conn.go and messages.go from 4b1a524 (merge base), tests kept
FAIL internal/jsonrpc2 600.130s (timeout)
--- FAIL: TestIOConnDuplicateInFlightRequestID (2.01s)
FAIL mcp 38.492s
$ go vet ./... && gofmt -l internal mcp # clean
non-blocking: #1392 edits the same DecodeMessage branch in messages.go to accept an error with no ID, so the second of the two to merge will conflict there. Do you plan to rebase if #1392 lands first?

internal/jsonrpc2/conn.go, track duplicate-ID rejection inacceptRequestwithout mutatingreq.ID, write anErrInvalidRequest(-32600) response withidomittedfixes #1541