Skip to content

fix(lsp): do not delay the next reply after a zero-length frame - #8666

Merged
EffortlessSteven merged 5 commits into
mainfrom
fuzz/lsp-zero-length-frame
Oct 18, 2026
Merged

EffortlessSteven merged 5 commits into
mainfrom
fuzz/lsp-zero-length-frame

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Requested by Steven · project thread

Before: a Content-Length: 0 frame 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, and FramedRead does 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 plus initialize in 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: 0 frame is answered without waiting for further input.

Scope Classification

  • One production behavior

Production delta: BoundedStdinReader read 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_bounds and --test lsp_lifecycle zero_length pass; 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

… 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
@gemini-code-assist

Copy link
Copy Markdown

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

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 82 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: d01e67b3-496e-4739-91b4-3dbb76cda0d1
📥 Commits

Reviewing files that changed from the base of the PR and between 4fb6e95 and 54c5dea.

📒 Files selected for processing: 3
  • changelog.d/8666-lsp-zero-length-frame.md
  • crates/ripr/src/lsp/transport_bounds.rs
  • crates/ripr/tests/lsp_lifecycle.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@EffortlessSteven EffortlessSteven self-assigned this Oct 18, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Decision

  • Needs reviewer attention before upstream: findings remain.

Confirmed findings

  • ripr sensor failed with exit code 2 (sensors/ripr/); no cargo-check / cargo-clippy receipts because the gh-runner profile disables build leases. PR claim correctness therefore relies on the scheduled-late cargo-test receipt 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 carry unless present in fresh post-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/; BoundedStdinReader is the only framed stdin reader, and FramedRead is layered on it for --stdio. Repo-wide scan of crates/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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 rest bytes 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.

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 18, 2026 04:12
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@EffortlessSteven
EffortlessSteven merged commit dc7436d into main Oct 18, 2026
48 checks passed
@EffortlessSteven
EffortlessSteven deleted the fuzz/lsp-zero-length-frame branch October 18, 2026 04:56

Copy link
Copy Markdown
Member Author

Landed as dc7436d (squash of head 54c5dea, hosted required checks green). Verified: lifecycle regression fails before the fix (15s timeout) and passes after; 19 transport_bounds unit tests pass, including packed frames behind an empty frame at read sizes 1/5/7/64 and bound trips (oversized length, over-cap header) behind an empty frame; cargo clippy -p ripr --all-targets -D warnings clean; independent exact-head review found no blocking issues. Not verified: cargo xtask precommit did not complete locally (the covered_by instrument step timed out on shared-target lock contention; earlier gates fmt/no-panic/allow-attributes/local-context passed); the "ripr sensor exit 2" lead was not reproduced in any hosted check on the final head (no failing check); an empty frame is still ignored rather than answered with a Parse error (non-goal).


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants