You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stdio transport: a request over the maximum line length gets no answer #1395
Since #1049 (rmcp 3.6.0) AsyncRwTransport drops a line that is longer than the maximum line length (16 MiB by default). It only writes a log entry. When that line is a request, the peer never gets an answer and waits until its own timeout. From the client side this looks like a server that hangs.
I found this while writing an MCP server that takes large inline files. A tools/call with a large base64 file in the arguments is enough.
To reproduce:
Start any stdio server built on rmcp 3.7.0.
Send initialize and notifications/initialized.
Send one tools/call request whose line is larger than 16 MiB, for example with a 17 MiB string in arguments.
The server logs "Incoming message exceeded the maximum line length, discarding it". The client gets nothing for this id.
Expected: an error answer for the request id, like the -32600 Invalid Request answer rmcp already sends for valid JSON with the wrong shape.
Lines without an id, responses and input that is not JSON should stay unanswered, so this does not bring back the error storm from #938.
I have a fix ready that builds on #1370. I can open it after that PR is merged.
@jordiboehme I looked at this after #1370 merged (28 Oct) and didn't find a follow-up PR. If you still have the patch, I'd rather review it and help with tests than open a competing one.
I didn't run a 17 MiB stdio session, but the current code matches the report. In AsyncRwTransport::receive (crates/rmcp/src/transport/async_rw.rs:283-289), LineRead::Oversized only logs Incoming message exceeded the maximum line length, discarding it and continues. The line is never parsed, so nothing is queued on pending_error_response and the peer gets no reply for that id. Transport::receive has no error channel, so the service loop never sees the dropped request either.
crates/rmcp/tests/test_async_rw_max_line_length.rs already covers drop, recovery, and the default 16 MiB bound, but the test helper builds the transport with tokio::io::sink(), so those tests don't assert what the client would read.
Repro is the one in the issue: start a stdio server on current main, send initialize and notifications/initialized, then one single-line tools/call whose frame is just over 16 MiB (for example a ~17 MiB string in arguments). The server logs the discard line; nothing comes back for that request id.
If we can recover the id from a prefix of the discarded line, the reply I'd expect is the same -32600 the wrong-shape path already sends, but with that id:
If the id isn't in the prefix — or the line is a response, a notification, or not JSON — stay silent, same as #938. One open question: when a request-shaped line is oversized but the id can't be recovered, do you want that same id-less -32600 the current protocol-error path already writes ({"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid request"}}, id omitted), or silence?
Happy to help add tests that actually read the write side (id present, id after a large field, stay-silent cases) against whichever patch lands.
I checked this against current main (9b3ec05); the code matches the report, and there is one detail that constrains any fix: the id is gone before receive sees the oversized line.
Where it breaks
AsyncRwTransport::read_line (crates/rmcp/src/transport/async_rw.rs:157-167) hits the limit, calls self.line_buf.clear(), and does not append the chunk that tripped it. So the bytes before the limit point — which is where a normal request carries "id" — are discarded inside read_line.
receive then only sees LineRead::Oversized and logs + continues (async_rw.rs:283-289). PendingErrorResponse is Queue | Flush (async_rw.rs:73-76) and the queued error is built with id: None, so there is no way to answer a specific request today even if the id were known.
So "recover the id from a prefix" requires a change in read_line, not just in the error path.
Sketch that fits the existing structure
Keep a bounded prefix while discarding: cap at something like 8 KiB (min(max_line_length, 8 * 1024)). It has to live on the struct next to discarding (async_rw.rs:64-67) rather than in read_line, because receive is polled inside a select! and the read can be cancelled mid-line; a local buffer would lose the prefix on cancellation.
When the terminating newline finally arrives (i.e. after the EndDiscard step), inspect the prefix: it is request-shaped only if it has a top-level "method" and neither "result" nor "error". Notifications and responses therefore stay silent, same as rmcp shouldn't respond to unparseable messages #938. This also means the reply is delayed until the whole oversized line has been drained — which is the right trade-off, you don't want to emit anything before you know what the line was.
Extract the id from the prefix. The prefix is truncated JSON, so serde_json::from_slice::<RxJsonRpcMessage<_>> can't work, but a streaming parse of just the id value does: locate the "id" key, then serde_json::Deserializer::from_slice(&prefix[after_colon..]).into_iter::<RequestId>() and take the first complete value. Number and short-string ids parse without needing the rest of the document.
Carry it on the pending state: PendingErrorResponse::Queue(Option<RequestId>), and pass that id to TxJsonRpcMessage::error(...) instead of None.
On your open question — if the line is request-shaped but the id is not in the bounded prefix, I'd stay silent rather than send the id-less -32600. An id-less error cannot be correlated by the client (it still times out), and it reopens the #938 error-storm surface for no benefit. If the id is in the prefix, answer -32600 with that id; everything else stays unanswered.
Tests
The existing helper in crates/rmcp/tests/test_async_rw_max_line_length.rs:34-37 builds the transport with tokio::io::sink() as the writer, so none of those tests can observe a reply. A fix needs a duplex write half (or a shared buffer) and four cases: id early in the line, id only after a large field (expect silence), notification (silent), response (silent). The padded_request helper already puts the id near the front, so the first case is cheap.
Unknowns — I have not validated step 3 against ids containing escapes (a "id" string with \"), and I don't know whether the maintainers prefer tying prefix retention to max_line_length or a fixed cap. Both are worth settling before the patch lands.
Thanks @jokemanfire, that's a much clearer picture. I missed that read_line clears the buffer before receive sees anything, so yes, the prefix has to be kept in read_line and live on the struct.
Agree on silence when the id isn't in the prefix. An id-less -32600 doesn't help the client and just reopens #938.
One thing on step 3: a plain search for "id" in the prefix could match a nested key inside params, or the text "id" inside a string value. I think it needs a small top-level scan that tracks depth and string state, and only takes id/method/result/error keys at depth 1. Escaped ids themselves should be fine since serde's streaming deserializer handles the escapes once you're at the right offset.
A fixed cap (8 KiB) seems simpler to reason about than tying it to max_line_length, but happy either way.
@jordiboehme if you're still on this I'm glad to review. If not, I can put up the four tests with a duplex writer (id early, id after a big field, notification, response) so whichever patch lands has something real to run against.
Thanks @sai-softwareforest and @jokemanfire for the analysis. Sorry, I did not get to open my PR after #1370 was merged. #1471 now does the same as my patch did, and it follows the design from this thread: a bounded prefix, a top-level scan for id and method, and silence when the id is not in the prefix. So I will not open a second PR. I will review #1471 instead.
@sai-softwareforest thanks for the offer. #1471 already has the four cases with a duplex writer: id early (oversized_request_with_early_numeric_id_gets_invalid_request), id after the retained prefix (oversized_request_with_id_after_retained_prefix_stays_silent), and notification and response (oversized_notification_and_response_stay_silent).
jordiboehme@5267a9d fixes a flaky test. oversized_line_is_logged_once_when_peer_closes failed in about one run of four on macOS, also on the head of fix(transport): reply to oversized stdio requests #1471 (ab9e1d5). Each test set its own subscriber with set_default, and a test on another thread could cache the log call site as never wanted. One global subscriber now counts the events of the thread that asked for them. 40 runs in a row passed.
jordiboehme@ff439c0 covers the TypeScript key order from my review on fix(transport): reply to oversized stdio requests #1471 ({"method":...,"params":...,"jsonrpc":"2.0","id":5}). It keeps a short tail (128 bytes) of the oversized line. When the prefix shows a top-level method but no id, it reads the id from the member right before the final }. Only integers and strings without escapes are read. Tests: id last as a number and as a string, the same read in 7 byte chunks, and silence for an id inside params, an id-like text in a string, a response, no method, an escaped id and a fraction.
@jonxsong feel free to cherry-pick both into #1471, or tell me if you want them as a separate PR after #1471 is merged.
Thanks for tracking down the tracing race and putting both commits together, @jordiboehme. I reproduced the unterminated-close assertion failure on Windows at ab9e1d5 in 1 of 40 runs of the all-features line-length suite. One subscriber with per-thread counts makes sense here, and I'd keep 5267a9d as a test-only fix so it can land independently of late-ID recovery. Your test report and patches
The TypeScript-order tests are worth carrying forward. Before using the ID from the tail, I'd want to verify the top-level JSON context across the discarded bytes. PR discussion
@jordiboehme. Let’s handle this in one follow-up PR after #1471 merges. That follow-up can cover the flaky logging test, late IDs in TypeScript requests, and a clearer error message that includes the configured line limit. Your proposed commits
Thanks @jonxsong, agreed. I will open one follow-up PR after #1471 is merged. Instead of the tail, the reader will follow the JSON structure through the discarded bytes with a small fixed state (depth, string and escape state, the current top-level key and at most 128 bytes of a top-level id). A second top-level id, or a top-level result or error, keeps the line unanswered. It will also carry the flaky test fix, the TypeScript order tests and an error message that names the line limit.
Activity
github-actions commentedon Oct 26, 2026
@gocamille is on triage rotation this week and is the reviewer for this one.
Codex labeled this bug / P1 (T-transport). Please confirm or correct those labels.
Automated triage. Labels are a first pass and the assigned maintainer has the final say.
sai-softwareforest commentedon Nov 12, 2026
@jordiboehme I looked at this after #1370 merged (28 Oct) and didn't find a follow-up PR. If you still have the patch, I'd rather review it and help with tests than open a competing one.
I didn't run a 17 MiB stdio session, but the current code matches the report. In
AsyncRwTransport::receive(crates/rmcp/src/transport/async_rw.rs:283-289),LineRead::Oversizedonly logsIncoming message exceeded the maximum line length, discarding itandcontinues. The line is never parsed, so nothing is queued onpending_error_responseand the peer gets no reply for that id.Transport::receivehas no error channel, so the service loop never sees the dropped request either.crates/rmcp/tests/test_async_rw_max_line_length.rsalready covers drop, recovery, and the default 16 MiB bound, but the test helper builds the transport withtokio::io::sink(), so those tests don't assert what the client would read.Repro is the one in the issue: start a stdio server on current main, send
initializeandnotifications/initialized, then one single-linetools/callwhose frame is just over 16 MiB (for example a ~17 MiB string inarguments). The server logs the discard line; nothing comes back for that request id.If we can recover the id from a prefix of the discarded line, the reply I'd expect is the same
-32600the wrong-shape path already sends, but with that id:{"jsonrpc":"2.0","id":,"error":{"code":-32600,"message":"Invalid request"}}
If the id isn't in the prefix — or the line is a response, a notification, or not JSON — stay silent, same as #938. One open question: when a request-shaped line is oversized but the id can't be recovered, do you want that same id-less
-32600the current protocol-error path already writes ({"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid request"}}, id omitted), or silence?Happy to help add tests that actually read the write side (id present, id after a large field, stay-silent cases) against whichever patch lands.
jokemanfire commentedon Nov 17, 2026
I checked this against current
main(9b3ec05); the code matches the report, and there is one detail that constrains any fix: the id is gone beforereceivesees the oversized line.Where it breaks
AsyncRwTransport::read_line(crates/rmcp/src/transport/async_rw.rs:157-167) hits the limit, callsself.line_buf.clear(), and does not append the chunk that tripped it. So the bytes before the limit point — which is where a normal request carries"id"— are discarded insideread_line.receivethen only seesLineRead::Oversizedand logs +continues (async_rw.rs:283-289).PendingErrorResponseisQueue | Flush(async_rw.rs:73-76) and the queued error is built withid: None, so there is no way to answer a specific request today even if the id were known.So "recover the id from a prefix" requires a change in
read_line, not just in the error path.Sketch that fits the existing structure
min(max_line_length, 8 * 1024)). It has to live on the struct next todiscarding(async_rw.rs:64-67) rather than inread_line, becausereceiveis polled inside aselect!and the read can be cancelled mid-line; a local buffer would lose the prefix on cancellation.EndDiscardstep), inspect the prefix: it is request-shaped only if it has a top-level"method"and neither"result"nor"error". Notifications and responses therefore stay silent, same as rmcp shouldn't respond to unparseable messages #938. This also means the reply is delayed until the whole oversized line has been drained — which is the right trade-off, you don't want to emit anything before you know what the line was.serde_json::from_slice::<RxJsonRpcMessage<_>>can't work, but a streaming parse of just the id value does: locate the"id"key, thenserde_json::Deserializer::from_slice(&prefix[after_colon..]).into_iter::<RequestId>()and take the first complete value. Number and short-string ids parse without needing the rest of the document.PendingErrorResponse::Queue(Option<RequestId>), and pass that id toTxJsonRpcMessage::error(...)instead ofNone.On your open question — if the line is request-shaped but the id is not in the bounded prefix, I'd stay silent rather than send the id-less
-32600. An id-less error cannot be correlated by the client (it still times out), and it reopens the #938 error-storm surface for no benefit. If the id is in the prefix, answer-32600with that id; everything else stays unanswered.Tests
The existing helper in
crates/rmcp/tests/test_async_rw_max_line_length.rs:34-37builds the transport withtokio::io::sink()as the writer, so none of those tests can observe a reply. A fix needs a duplex write half (or a shared buffer) and four cases: id early in the line, id only after a large field (expect silence), notification (silent), response (silent). Thepadded_requesthelper already puts the id near the front, so the first case is cheap.Unknowns — I have not validated step 3 against ids containing escapes (a
"id"string with\"), and I don't know whether the maintainers prefer tying prefix retention tomax_line_lengthor a fixed cap. Both are worth settling before the patch lands.sai-softwareforest commentedon Nov 19, 2026
Thanks @jokemanfire, that's a much clearer picture. I missed that
read_lineclears the buffer beforereceivesees anything, so yes, the prefix has to be kept inread_lineand live on the struct.Agree on silence when the id isn't in the prefix. An id-less
-32600doesn't help the client and just reopens #938.One thing on step 3: a plain search for
"id"in the prefix could match a nested key insideparams, or the text"id"inside a string value. I think it needs a small top-level scan that tracks depth and string state, and only takesid/method/result/errorkeys at depth 1. Escaped ids themselves should be fine since serde's streaming deserializer handles the escapes once you're at the right offset.A fixed cap (8 KiB) seems simpler to reason about than tying it to
max_line_length, but happy either way.@jordiboehme if you're still on this I'm glad to review. If not, I can put up the four tests with a duplex writer (id early, id after a big field, notification, response) so whichever patch lands has something real to run against.
jordiboehme commentedon Nov 19, 2026
Thanks @sai-softwareforest and @jokemanfire for the analysis. Sorry, I did not get to open my PR after #1370 was merged. #1471 now does the same as my patch did, and it follows the design from this thread: a bounded prefix, a top-level scan for
idandmethod, and silence when the id is not in the prefix. So I will not open a second PR. I will review #1471 instead.jordiboehme commentedon Nov 19, 2026
@sai-softwareforest thanks for the offer. #1471 already has the four cases with a duplex writer: id early (
oversized_request_with_early_numeric_id_gets_invalid_request), id after the retained prefix (oversized_request_with_id_after_retained_prefix_stays_silent), and notification and response (oversized_notification_and_response_stay_silent).I added two commits on top of #1471, in the branch https://github.com/jordiboehme/rust-sdk/commits/test/oversized-id-after-params
oversized_line_is_logged_once_when_peer_closesfailed in about one run of four on macOS, also on the head of fix(transport): reply to oversized stdio requests #1471 (ab9e1d5). Each test set its own subscriber withset_default, and a test on another thread could cache the log call site as never wanted. One global subscriber now counts the events of the thread that asked for them. 40 runs in a row passed.{"method":...,"params":...,"jsonrpc":"2.0","id":5}). It keeps a short tail (128 bytes) of the oversized line. When the prefix shows a top-levelmethodbut noid, it reads theidfrom the member right before the final}. Only integers and strings without escapes are read. Tests: id last as a number and as a string, the same read in 7 byte chunks, and silence for an id insideparams, an id-like text in a string, a response, no method, an escaped id and a fraction.@jonxsong feel free to cherry-pick both into #1471, or tell me if you want them as a separate PR after #1471 is merged.
jonxsong commentedon Nov 19, 2026
Thanks for tracking down the tracing race and putting both commits together, @jordiboehme. I reproduced the unterminated-close assertion failure on Windows at
ab9e1d5in 1 of 40 runs of the all-features line-length suite. One subscriber with per-thread counts makes sense here, and I'd keep5267a9das a test-only fix so it can land independently of late-ID recovery. Your test report and patchesThe TypeScript-order tests are worth carrying forward. Before using the ID from the tail, I'd want to verify the top-level JSON context across the discarded bytes. PR discussion
jonxsong commentedon Nov 19, 2026
@jordiboehme. Let’s handle this in one follow-up PR after #1471 merges. That follow-up can cover the flaky logging test, late IDs in TypeScript requests, and a clearer error message that includes the configured line limit. Your proposed commits
jordiboehme commentedon Nov 19, 2026
Thanks @jonxsong, agreed. I will open one follow-up PR after #1471 is merged. Instead of the tail, the reader will follow the JSON structure through the discarded bytes with a small fixed state (depth, string and escape state, the current top-level key and at most 128 bytes of a top-level
id). A second top-levelid, or a top-levelresultorerror, keeps the line unanswered. It will also carry the flaky test fix, the TypeScript order tests and an error message that names the line limit.