Repository navigation
fix(lsp): do not delay the next reply after a zero-length frame - #8666
Conversation
… is not delayed The tower-lsp codec answers an empty body with Ok(None) and leaves later bytes buffered; FramedRead does not re-decode until more input arrives, so a request sharing a read with a Content-Length: 0 frame was answered only after another message or EOF. BoundedStdinReader now withholds bytes after an empty frame to the next read (bytes unmodified and ordered). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019KJRFj19yBcxVrsuTFe4Y2
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019KJRFj19yBcxVrsuTFe4Y2
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019KJRFj19yBcxVrsuTFe4Y2
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 22 minutes. View limit details
Comment |
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
riprsensor failed with exit code 2 (sensors/ripr/); nocargo-check/cargo-clippyreceipts because the gh-runner profile disables build leases. PR claim correctness therefore relies on the scheduled-latecargo-testreceipt landing before the gate.
Verification questions
- Confirm header scanner only splits at
Content-Length: 0, not at every empty body produced by length>=1 reads; siblings like oversized-length and header-bounds paths remain unchanged. - Confirm state stays in Header(Vec::new()) when Content-Length:0 is parsed, so any pre-collected 'rest' suffix bytes are dropped only when return Ok(offset - rest.len()) fires; on the empty-frame branch those bytes are not retained into
carryunless present infreshpost-deliver. Verify the state path during split doesn't lose midpoint rest bytes.
Refuted
- A second LSP transport (TCP/websocket/piped-subprocess) inherits the same zero-length-frame stall and needs a parallel fix.; refuted because: No second LSP transport exists under
crates/ripr/src/lsp/;BoundedStdinReaderis the only framed stdin reader, andFramedReadis layered on it for--stdio. Repo-wide scan ofcrates/ripr/src/**shows no sibling reader.
Parked follow-ups
- No coverage for multiple non-empty frames packed behind an empty frame, nor for EOF arriving mid-carry - delta is scoped.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
… EOF Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019KJRFj19yBcxVrsuTFe4Y2
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- If poll_read's inner source returns Ok(0) while carry is non-empty (EOF mid-carry), the carry-serving branch drains carry into buf and never re-polls inner or surfaces trip; tests do not cover inner-EOF with non-empty carry explicitly, relying on tokio::io::sink writing the full payload first.
Verification questions
- Confirm carry bytes served on a subsequent poll are re-observed so an oversized-length in them still trips the bound, but the trip is reported on the poll AFTER they are delivered (consistent with existing comment).
- Confirm observe() returns Ok(offset - rest.len()) on Content-Length:0 branch, leaving state in Header(Vec::new()); verify that pre-collected
restbytes from an oversized-length trip-then-recover path are not silently dropped when the split fires (PR review summary flagged this state path). - Confirm unit test frames_packed_behind_an_empty_frame_survive_small_reads_and_eof re-observes carry bytes on each subsequent read because the read loop always calls observe(&fresh) on the delivered slice; confirm that when carry bytes alone are served (no fresh inner read), they are NOT re-observed and thus a malformed carry cannot trip the bound on a future read.
- Confirm observe() Some(0) arm returns Ok(offset - rest.len()), which equals offset only when 'rest' was empty in that header line; offset already advanced past Content-Length:0 bytes, so the withheld trailing buffer is captured by poll_read's fresh[deliver..].
Refuted
- observe() splitting at offset - rest.len() when Content-Length: 0 is parsed may discard trailing bytes already inside the just-completed header parse that belong to the next frame, losing order.; refuted because: Header parsing advances offset only past full terminators; rest is defined as bytes after the consumed header. On Some(0) we return Ok(offset - rest.len()), which equals the byte position right after the empty frame header. Those rest bytes are saved into fresh[deliver..] and moved to carry, then served on the next poll - preserving order and unmodified bytes (asserted by tests).
- Box::from(slice) / Box::<[u8]>::from(slice) allocation-failure path can drop carry bytes silently.; refuted because: PR diff does not introduce any Box::from(slice) on the carry slice; carry is a Vec with drain(..take) that returns owned values, and Vec allocation failure is handled by Rust's default OOM path, not silently dropped. No allocation-failure analysis is raised by this diff.
- The fix duplicates frame-splitting logic by adding a second mechanism (carry) alongside the existing Body state that already withholds bytes via rest.split_off(leftover).; refuted because: Body-state withholding keeps bytes for the same frame's next read; carry withholds across frames after a zero-length frame. Distinct purposes; no duplication of the decode/codec state.
- Returning 'deliver < fresh.len()' would corrupt in-order delivery because carry appends a freshly reallocated Vec instead of reusing the buffer; refuted because: poll_read copies fresh[deliver..] into carry in declared order and serves carry via put_slice before future inner polls; new tests assert byte-equality and splitting invariants at chunk sizes 1, 5, 7, 64, all of which pass per PR claim.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019KJRFj19yBcxVrsuTFe4Y2
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Landed as dc7436d (squash of head 54c5dea, hosted required checks green). Verified: lifecycle regression fails before the fix (15s timeout) and passes after; 19 Generated by Claude Code |
Requested by Steven · project thread
Before: a
Content-Length: 0frame followed by a valid request in the same read left the request's reply unsent (>10s) until another message or EOF arrived.After: the reply to the valid request is sent immediately; the empty frame is still ignored by the codec, and bytes reach it unmodified and in order.
How: tower-lsp's codec returns
Ok(None)for an empty body but leaves later bytes buffered, andFramedReaddoes not re-run the decoder until more input arrives.BoundedStdinReader(lsp/transport_bounds.rs) now ends each read right after a zero-length frame and carries the remaining bytes to the next read, so the codec drains and asks for more. Tests: unit test on the reader (read splitting, byte equality) and a stdio lifecycle test that sends the empty frame plusinitializein one write (fails before with a 15s timeout, passes after).Source-of-truth Links
Governing issue or accepted claim: fuzz finding "lsp_cl0_lag" (zero-length frame delays next reply); no issue filed, duplicate search of all-state PRs found none.
Acceptance delta (one sentence): a valid request following a
Content-Length: 0frame is answered without waiting for further input.Scope Classification
Production delta:
BoundedStdinReaderread splitting at zero-length frames.Evidence/support delta: two regression tests.
Single acceptance criterion: reply to a request after an empty frame arrives promptly.
Non-goals: replying Parse error for empty frames; changing tower-lsp.
Proof
cargo test -p ripr --lib transport_boundsand--test lsp_lifecycle zero_lengthpass; lifecycle test fails with the fix disabled.Claim Boundary
Only the empty-frame lag; no other framing behavior changed.
Rollback
Revert this PR.
Generated by Claude Code