Skip to content

fix(quic): rerun stuck-window eviction after plain reads and handle window shrinks - #9711

Merged
kixelated merged 3 commits into
mainfrom
quest/m1/quic-eviction-deadlock
Nov 27, 2026
Merged

kixelated merged 3 commits into
mainfrom
quest/m1/quic-eviction-deadlock

Conversation

@kixelated

@kixelated kixelated commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m1/quic-eviction-deadlock.md.

Problem

A full receive window could deadlock with every reader parked, because nothing reran the stuck-window pass or woke over-window readers:

  • A plain read() whose returned credit only paid receive_window_shrink_debt never reran the pass that its unread data had held off.
  • Shrinking receive_window left a lease waiting for more than the new window parked forever, and never reported a MAX_DATA that the smaller batch made due.

Approach

  • Chunks::finalize_inner() reruns evict_if_stuck() after returning credit. When the window has room this returns in O(1).
  • set_receive_window() on a shrink wakes readers whose want exceeds the new window (wake_too_large), so their next lease fails with TooLarge, and returns max_data_due(). It runs no pass: a shrink changes neither window_max_data nor data_recvd, so whether the window is stuck stays the same.
  • Stream::restore() keeps the stuck_waiting gate (rerunning eviction only when an earlier pass waited on that lease while it was out) and documents that a reader parking elsewhere while holding leased bytes must release or stop its stream.
  • ReceiveCredit.tla now models plain-read streams (Plain) and shrink debt (Shrink). The new ReceiveCreditMixed.cfg covers them, and ReceiveCreditMixedGuards.cfg checks Guarded on the new steps.

Choices made without asking

  • The coverage table's sync commit in .claude/skills/verify-credit/SKILL.md was not moved, since rs/moq-net/src/lite/publisher.rs has substantial unrelated changes since 7cab21e65b that this PR does not re-audit.

Impact

  • Public API: none. Wire: none.
  • Behavior: with a full window, eviction can now happen at a plain read's finalize, or (via TooLarge) after a shrink, where before the connection hung.

Validation

  • Unit tests in rs/moq-quic/src/connection/streams/state.rs: read_into_shrink_debt_evicts, shrink_below_a_want_wakes_it, shrink_sends_batched_credit, and restore_mid_decode_does_not_evict_active_reader.
  • just check origin/main: 12,447 Rust tests passed (165 skipped), plus clippy, rustdoc, fmt, biome, markdown, quest, shell, toml, nix, justfile, and coverage_tables checks.
  • sh/tla.sh over all 7 ReceiveCredit*.cfg configs: all passed (ReceiveCreditMixed: 633k states in 11s; ReceiveCreditMixedGuards: 1.1k states in 2s; ReceiveCreditGuards: 10.3k states in 8 min). SendCredit.tla is unchanged.
  • quest check --base origin/main --branch quest/m1/quic-eviction-deadlock: passed (559 documents checked).

Caused by

Decisions

  • Maintainer (2026-11-26, superseding the earlier waiter-rule decision): How should recv::Stream::restore() behave? ✅ Restore the old stuck_waiting gate (rejected: Add Stream::park(lease) and a moq-tokio wrapper; Keep the waiter rule and count parked plain readers too). In moq-net, dropping a Lease calls restore() between poll_has_more/peek and decode, on short reads, and mid-segment in poll_read_frame; rerunning eviction whenever another reader waits evicts active readers mid-decode (round 1 finding 1), and counting parked plain readers would not fix that. No current consumer parks on another connection stream after a restore, so restore() keeps stuck_waiting and documents that a reader parking elsewhere with leased bytes must release or stop them.

Follow-ups

None.

Models

Size: S
Implementer: Claude Code, claude-opus-5-5, unknown (arm A)
Implementer: Antigravity, gemini-4-neon, high effort

(Written by Gemini 4 Neon with high effort)

Review

Rewritten by quest review after each round.

  • Head: 6933ee0

  • Base: origin/main at 54c862e

  • Risk: medium, A wrong eviction or credit change in moq-quic's receive path (lease.rs, recv.rs, state.rs) could stall or evict streams for relay and client users once a release cut ships it, and it is easy to undo by reverting the commits, since the public API and wire format are unchanged and the verify and quest files are docs or models.

  • Classified: medium by Claude Code, claude-haiku-5-5, low effort, session c794b7c9-9d40-46d1-8c8e-00027b9fa76f

  • Risk file: bb7b1c0de60b

  • Reviewer: Codex, gpt-6.2-sol, medium effort

  • Session: 01a21a8b-66d1-7633-87ac-0ad81508cf0b, round 3

  • Score: 10/10, The head is ready to land because the peek race already exists at the merge base and no findings remain in the branch’s changes.

  • Rounds: 3; first round 2 (high 1, medium 1); findings 2 (medium 2): fixed 1, refuted 1, open 0

  • Findings: none

  • The last round's findings, at 6933ee0:

    • Refuted: medium, rs/moq-quic/src/connection/streams/lease.rs:420: Keep a peeked header readable when an arrival fills the window; The merge-base patch for `rs/moq-quic/src/connection/streams/lease.rs:420` shows that the branch changes only the `restore()` documentation and comments, leaving both the eviction guard and the logic that arms it unchanged.

kixelated and others added 2 commits November 26, 2026 11:16
…nd shrinks

A restore reran the stuck pass only when a pass had found that lease out, so a
pass held off by a ready or unleased stream never reran once its reader looked
and parked elsewhere. A restore now reruns it while any reader waits
(StreamsState::waiting). A plain read whose credit only pays a shrunk window's
debt reruns it too. Shrinking the window wakes leases waiting for more than it
now holds, and reports a MAX_DATA the smaller batch makes due.

ReceiveCredit.tla models plain-read streams, shrink debt, and readers parking
on another reader after a restore; ReceiveCreditMixed.cfg fails with either
fix reverted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Fix stuck_waiting and Chunks::finalize_inner receive-window eviction deadlocks fix(quic): rerun stuck-window eviction after restores, plain reads, and shrinks Nov 27, 2026
Rerunning stuck-window eviction in restore() whenever another reader waits evicts active moq-net readers mid-decode (between poll_has_more/peek and decode, or mid-segment in poll_read_frame) while another stream waits on a full window. Restore the stuck_waiting gate so restore() reruns eviction only when a pass waited on that lease while it was out, document the parking contract on restore(), replace the waiter-rule test with restore_mid_decode_does_not_evict_active_reader, and drop Idle from ReceiveCredit.tla while keeping plain-read and shrink-debt coverage.
@kixelated kixelated changed the title fix(quic): rerun stuck-window eviction after restores, plain reads, and shrinks fix(quic): rerun stuck-window eviction after plain reads and handle window shrinks Nov 27, 2026
@kixelated
kixelated marked this pull request as ready for review November 27, 2026 02:23
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 622ad6f2-fbb8-4fd1-917e-25d73317b2bf
Commits

Reviewing files that changed from the base of the PR and between b97c585 and 6933ee0.

Files selected for processing: 14

  • .claude/skills/verify-credit/SKILL.md
  • quest/m1/quic-eviction-deadlock.md
  • quest/m2/quic-lease-ownership.md
  • rs/moq-net/verify/credit/ReceiveCredit.cfg
  • rs/moq-net/verify/credit/ReceiveCredit.tla
  • rs/moq-net/verify/credit/ReceiveCreditGuards.cfg
  • rs/moq-net/verify/credit/ReceiveCreditMixed.cfg
  • rs/moq-net/verify/credit/ReceiveCreditMixedGuards.cfg
  • rs/moq-net/verify/credit/ReceiveCreditSegments.cfg
  • rs/moq-net/verify/credit/ReceiveCreditThree.cfg
  • rs/moq-net/verify/credit/ReceiveCreditWide.cfg
  • rs/moq-quic/src/connection/streams/lease.rs
  • rs/moq-quic/src/connection/streams/recv.rs
  • rs/moq-quic/src/connection/streams/state.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@kixelated
kixelated added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 2573e5b Nov 27, 2026
7 checks passed
@kixelated
kixelated deleted the quest/m1/quic-eviction-deadlock branch November 27, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant