Echo the request JSON-RPC id in session-not-found 404s#6031
Open
JAORMX wants to merge 2 commits into
Open
Conversation
JAORMX
requested review from
ChrisJBurns,
amirejaz,
blkt,
jhrozek and
rdimitrov
as code owners
July 27, 2026 15:57
rdimitrov
previously approved these changes
Jul 27, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6031 +/- ##
==========================================
- Coverage 72.18% 72.18% -0.01%
==========================================
Files 721 721
Lines 75025 75071 +46
==========================================
+ Hits 54158 54191 +33
- Misses 17005 17019 +14
+ Partials 3862 3861 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
10 tasks
JAORMX
force-pushed
the
echo-jsonrpc-id-in-session-404
branch
from
July 27, 2026 16:22
d3a7ee8 to
1bd0d48
Compare
5 tasks
jhrozek
previously approved these changes
Jul 27, 2026
The transparent proxy's unknown-session guard returned a -32001 404 whose body hardcoded a null id, while the classification-error path on the very same RoundTrip already echoed the incoming id. A client correlating responses by id got null for this one error class. The id was parsed a few lines above the guard but scoped to the classification block, so the guard could not reach it. Hoist it. Only set it when parseRPCRequest reports a single request, which by construction means the id is present and non-null -- notifications, batches and bodiless GET/DELETE keep the null id JSON-RPC requires. The three sibling WriteNotFound call sites were audited and are correct as-is: standalone-SSE GET, DELETE, and the httpsse GET all carry no body and therefore no id. The streamable POST path already echoed it. So this was the only site discarding an id it had. NotFoundBody's doc comment listed the transparent proxy as an id-unavailable case, which this makes untrue, so it is updated to say when nil is legitimate. Closes #5945
JAORMX
force-pushed
the
echo-jsonrpc-id-in-session-404
branch
from
July 27, 2026 17:07
1bd0d48 to
abd7af2
Compare
This was referenced Jul 27, 2026
The hostile-input proxy spec carried a hostileCase.idNotEchoed flag whose only true case was the foreign-session 404, and whose doc comment spelled out the very asymmetry the previous commit removes: session.NotFoundResponse hardcoding a nil id while ClassificationErrorResponse on the same RoundTrip echoed it. With the id now threaded through to the guard, the spec's Expect(resp.ID).To(BeNil()) failed -- correctly. The flag has no remaining true case: all five rejections are single JSON-RPC requests posted to /mcp, so RoundTrip parses an id for every one of them. Drop the field and the conditional so each case asserts the echoed id uniformly, and record on the foreign-session case why its 404 now carries one.
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
Closes #5945. The transparent proxy's unknown-session guard returned a
-32001404 whose body hardcoded a null id, while the classification-error path on the very sameRoundTripalready echoed the incoming id. A client correlating responses by id gotnullfor this one error class.The cause is scoping, not intent: the id is parsed a few lines above the guard, but inside the classification block, so the guard could not reach it.
sawInitializewas already hoisted out of that block for the same reason; the id now is too.It is set only when
parseRPCRequestreports a single request — and that predicate is alreadymethod != "" && len(id) > 0 && id != "null", so by construction a set id is present and non-null. Notifications, batches, and bodiless GET/DELETE keep the null id JSON-RPC requires.Audit of the sibling call sites
The issue names one site; I checked all four before changing anything, because fixing one and leaving three inconsistent would be half a fix. The transparent proxy was the only site discarding an id it actually had:
transparent_proxy.goguardstreamable_proxy.go:1096req.ID.Raw()streamable_proxy.go:433nilcorrectstreamable_proxy.go:484nilcorrecthttpsse/http_proxy.go:555session_idquery paramnilcorrectConsequently
NotFoundBody's doc comment — which listed "transparent proxy" as an id-unavailable case — became untrue, so it now states whennilis legitimate instead of implying it is a free choice.Type of change
Test plan
task test) —pkg/transport/sessionandpkg/transport/proxy/transparentgreen with-racetask lint) — 0 issues;go vet ./...cleanTestRoundTrip404EchoesRequestIDis the end-to-end pin, table-driven over numeric id, string id, notification, and explicit-null id. It also decodes the body to assert the envelope stays a valid JSON-RPC object, since echoing a raw id could otherwise corrupt it.Mutation-verified. Setting
requestID = nilinside thesingleRequestblock (semantically pre-fix, build intact) fails exactly the two id-bearing subtests and correctly leaves the two null-id subtests passing. Restored, all four pass. My first attempt at this mutation was invalid — deleting the argument broke the build on an unused variable rather than failing the test — so the reported result is from the second, valid attempt.Why the existing test could not have caught this:
TestRoundTripReturns404ForUnknownSessionsends{"method":"tools/list"}with noid, so it renders a null id before and after the fix. That is precisely why the bug survived having a test on this path.TestNotFoundResponsealso became table-driven, coveringjson.RawMessageids — the shape the proxy actually passes — so a numeric id stays numeric rather than being coerced to a float or string. It additionally assertsContentLengthmatches the body, since a client reading exactly that many bytes would truncate or block if it drifted.API Compatibility
v1beta1API.session.NotFoundResponsegains arequestIDparameter. It is an internal Go helper with a single production caller; no operator API surface is touched.Does this introduce a user-facing change?
Yes, narrowly. A session-not-found 404 from the transparent proxy now echoes the request's JSON-RPC id instead of always sending
null, so a client correlating by id can match this error to its request. Requests that carry no id are unchanged.Special notes for reviewers
The 404 behaviour is deliberately untouched. As the issue notes, the guard keying on
Mcp-Session-Idpresence rather than the client-forgeable revision is a fail-safe by design — this changes only the id in the error body.Rebased onto
mainand retargeted from its original base. It was briefly stacked on my own #6030, which fixed a build break onmain; #6029 landed an equivalent (and cleaner) fix first, so #6030 is closed as superseded and this now sits directly onmainas a single commit.Closes #5945
Generated with Claude Code