Skip to content

internal/jsonrpc2: reply with -32600 and omitted ID on duplicate in-flight ID - #1550

Merged
guglielmo-san merged 3 commits into
mainfrom
serob/reject-duplicate-in-flight-ID
Nov 27, 2026
Merged

guglielmo-san merged 3 commits into
mainfrom
serob/reject-duplicate-in-flight-ID

Conversation

@nahapetyan-serob

Copy link
Copy Markdown
Contributor
  • In internal/jsonrpc2/conn.go, track duplicate-ID rejection in acceptRequest without mutating req.ID, write an ErrInvalidRequest (-32600) response with id omitted

fixes #1541

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread internal/jsonrpc2/conn.go Resolved

@chrikrah chrikrah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

@guglielmo-san
guglielmo-san enabled auto-merge (squash) November 27, 2026 16:11
@guglielmo-san
guglielmo-san merged commit 13d3c71 into main Nov 27, 2026
9 checks passed
@guglielmo-san
guglielmo-san deleted the serob/reject-duplicate-in-flight-ID branch November 27, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jsonrpc2: a reused in-flight request ID gets no response

4 participants