fix: correlate invalid JSON-RPC envelope errors with the original request id - #2852
anneheartrecord wants to merge 1 commit into
Conversation
|
For reviewers — summary to ease review: Bug: when an incoming message is valid JSON but fails JSON-RPC envelope validation (e.g. Fix: a shared Two deliberate calls worth a look:
Both repro cases covered on both transports + null-id fallbacks. Full suite (1785), ruff, pyright all pass. If you'd rather land just the id-correlation core and split the stdio parse-error / error-code changes, I'm glad to narrow it. |
384b532 to
9ab7b71
Compare
…uest id When an incoming message is valid JSON but fails JSON-RPC envelope validation, the error response previously could not be correlated with the originating request: the stdio server transport dropped the message with no response at all, and the Streamable HTTP transport replied with a null id. Extract the request id best-effort from the raw parsed payload and preserve it in the error response on both transports, falling back to a null id (per the JSON-RPC 2.0 spec) when no valid id can be extracted. The stdio transport now also answers unparseable lines with a Parse error (-32700, null id), and both transports report envelope-invalid messages as Invalid Request (-32600) instead of Invalid params (-32602), matching the JSON-RPC 2.0 error code semantics.
9ab7b71 to
f52691d
Compare
|
Rebased onto On the
Same numbers @Parker-Fawcett got on the issue. One thing worth deciding before this lands. This PR covers stdio and the 2025-era streamable HTTP entry; the 2026-07-28 entry still answers an envelope-invalid body with Local on |
|
Thanks for the PR, and sorry it sat here without a proper review. We're closing most of the open PR backlog. v2 is out and changed a lot of the SDK, so many older PRs no longer apply as written, and we're a small team that realistically doesn't have the capacity to work through the rest. If this still matters to you on v2, the most useful thing you can do is open an issue (or comment on the existing one) with your use case and a repro. Hearing why it matters to you is what we use to decide what to prioritise. |
Fixes #2848
When an incoming message is valid JSON but fails JSON-RPC envelope validation (e.g.
"jsonrpc": "1.0", a missingjsonrpcfield, or a non-stringmethod), the error response could not be correlated with the originating request:"server-error"on v1.x), breaking client-side request/response correlation.This PR extracts the request id best-effort from the raw parsed payload (shared helper
extract_raw_request_id; only spec-valid id types are accepted — strings and non-bool integers) and preserves it in the error response on both transports, falling back to a null id per the JSON-RPC 2.0 spec when no valid id can be extracted. The stdio transport now also answers unparseable lines with-32700 Parse error(null id), matching the HTTP transport's existing parse-error behavior. Envelope-invalid messages are now reported as-32600 Invalid Requestinstead of-32602 Invalid params, matching JSON-RPC 2.0 error code semantics (the issue's three repro cases are envelope violations, not parameter errors).Tests cover all three repro cases from the issue on both transports, plus the null-id fallback (unextractable id and unparseable body). Full suite,
ruff, andpyrightpass.