Skip to content

fix(net): an ordered front read waits for a lost group its serving route still owes - #9846

Draft
kixelated wants to merge 6 commits into
mainfrom
quest/m1/ordered-read-lost-group
Draft

kixelated wants to merge 6 commits into
mainfrom
quest/m1/ordered-read-lost-group

Conversation

@kixelated

@kixelated kixelated commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Claims and finishes quest/m1/ordered-read-lost-group.md.

Waiting

  • Maintainer: The third local review round (Codex, gpt-6.2-sol, high) still reports one medium finding after two rounds of fixes, so quest review stopped for your pick. The finding is at rs/moq-net/src/model/resume.rs:3033. When fill_owes_below sees a group land on a fill during the hand-out, it wakes the read to walk again. That retry can run before the producer notifies the fill's cursor, so the cursor's idle gate (Subscriber::parked, track.rs:13237) returns its cached Pending without peeking. The owed check then counts the group as arrived, and the read hands out the group above it and passes the landed group for good. The window is a thread race between the producer releasing the track lock and waking its waiters. The reviewer recommends disarming the fill cursor's idle gate when a landing is detected, so the retry peeks the copy. I agree: the finding matches the code, and the fix is small and local.
    • Fix as recommended (Recommended) - disarm the fill cursor's idle gate on a detected landing, then run one more review round
    • Accept it - land with the race open; it needs a group to land on a fill in the instant between the lock release and the wake
    • Drop the PR - leave the ordered read passing the lost group, as on main

Problem

An ordered read of a front's logical track passed a group below the serving copy's resume point that a replaced copy held and then lost from its cache. The walk asks the serving route for it with a backfill, but while that backfill had yet to answer, nothing held an ordered candidate above it: the next group went out and the lost one was passed for good. A plain ordered cursor on the route waits for it. Both Rust and JS behaved this way, whether the copy lost the group before the switch or after the switch left it that group to drain.

Approach

Before an ordered hand-out, the reader asks each fill (a backfill copy of the serving route) whether its own ordered read still waits on a group the reader lacks below the candidate. If one does, the read parks.

  • Rust: track::Subscriber::owes reports whether an ordered read of that subscription still waits on a group in a range. That is true for a group a fill it asked has yet to answer (Misses::wants), for one whose head its bounded window is still fetching (Heads::fetching), and for one its received copy's live feed owes within the arrival grace (TrackState::owed). A front's logical track asks its own copies. Reader::fill_owes_below asks this of every fill whose read parked this pass. A fill still unanswered owes what it was asked, and a fill whose track saw a group arrive since its read parked (on another thread) is read again. A key the reader or any kept copy records skipped (Reader::skipped_in) is not waited for; a drop is only the dropping route's, so each fill judges its own. The fill's read, the grace fold, and the fill's budget wake the read.
  • JS: hooks.owes wraps the subscriber's own #waitOwed, which covers the same two cases and arms the read's wakeups. Reader.#fillOwesBelow mirrors the Rust check. Copies now carry fills, as in Rust, and skips come from the reader's existing skippedIn. JS needs no head or race case: a head is asked through the same fills #waitOwed already consults, and reads are single-threaded.

Impact

  • Public API: none. Wire: none.
  • Behavior: an ordered front read waits, within its budget, for a lost group the serving route still owes, instead of passing it.

Decisions

  • What counts as "may still land" on the fill. Taken: the fill's own ordered verdict, meaning a fill still out or the live feed owing the group. Rejected:
    • The quest's literal rule (any key the fill was asked for and its track has not declared skipped, until the budget passes). It held reads for the whole budget on a group no feed promised and no fill was asked for, and on local publishers, which a plain cursor passes. It broke a_held_back_group_goes_out_once_a_later_copy_places_the_window and an_ordered_read_passes_a_replayed_group_an_arrival_read_handed_out.
    • The fill's peek parking. That also parks a bounded fill whose window holds nothing more.
  • A group a replaced copy skipped is passed even though the backfill asked the serving route for it too, since a skip is the publisher's verdict for the whole track. One a replaced copy dropped still waits on the serving route: a drop without a stale verdict also covers a relay's cache losing the group, which says nothing of another route (review round 1 caught that the first cut let any copy's drop settle it). The JS test an ordered resumed reader keeps an older copy's owed hole until drop now also has the serving route drop the group before the read passes it. Rejected: letting a final drop on any copy settle the group, which loses a group the serving route still delivers.
  • An unanswered fill (Rust Sub::Pending) holds the read, since its route has said nothing yet. Rejected: passing it, which loses the group whenever the serving route is slow to answer.
  • Test shapes differ per language. A JS backfill's demand re-asks the route's feed at once, so a lost group there is owed by the feed. A Rust copy's feed start moves only when its session says so, so the Rust test covers both a fill answering (or dropping) and a feed asked from below. JS covers landing and a publisher skip. Both cover lost-before and lost-after the switch, plain and nested fronts.

Caused by

No single PR. The quest records the in-flight case behaving the same on main at 065a4c1, before moq-dev/moq#9750, and the hold never existed.

Validation

  • New tests, each failing before the fix (checked by disabling the hold):
    • Rust an_ordered_read_waits_for_a_lost_group_the_serving_route_answers_late (lost before or after the switch; fill, fill drop, or feed answer; plain or nested front)
    • Rust an_ordered_read_waits_for_a_lost_group_while_the_serving_route_is_unanswered
    • Rust an_ordered_read_passes_a_group_a_replaced_copy_skipped_but_not_one_it_dropped
    • Rust an_ordered_bounded_read_waits_for_a_lost_groups_head (fails without the Heads::fetching check)
    • JS an ordered resumed reader keeps an older copy's owed hole until drop, extended to hold until the serving route drops the group too
    • JS an ordered read waits for a lost group its serving route answers late (6 cases)
  • just ci passes on the review-round head too.
  • The cross-thread landing recheck (poll_arrived in fill_owes_below, checked after the owed check so a landing cannot fall between them) has no deterministic test, because the landing must fall inside one poll.
  • /verify-resume: ResumeReader.tla default, ThreeRoutes.cfg, and Evict.cfg all pass (the default explores 20.1M distinct states). The model leaves ordered reads out, so this only confirms the arrival path is unchanged. Run on the first head; the review fixes touch only the ordered hold, which the model leaves out.
  • cargo mutants --in-diff on the new owes/fill_owes_below code: 9 of 10 caught. The one missed (< to <= on a run starting at the candidate's key) is equivalent, since that run clips to empty. It joins the existing exhausted|lacking exclusion in .cargo/mutants.toml.

Alternatives

See Decisions.

Follow-ups

None.

Models

Size: M
Implementer: Claude Code, claude-opus-5-5, unknown (arm A)

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

Review

Rewritten by quest review after each round.

  • Head: ebdf9bd, named in full once no reviewer reports a finding

  • Base: origin/main at e91efb9

  • Risk: medium, If the new ordered-read wait is wrong, a relay or JS consumer that reads ordered from a resumed front may stall on a lost group or hand out a group late, which affects subscribers of the shipped rs/moq-net and js/net packages; it changes no public API, wire format, or stored data, the internal additions are crate-private or unexported, and a revert fully undoes it, so this is a fix that the next cut publishes as a patch.

  • Classified: medium by Claude Code, claude-haiku-5-5, low effort, session 001b5963-f8c3-48af-8798-d20d84ac0401

  • Risk file: bb7b1c0de60b

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

  • Session: 01a221e1-ff08-7ef3-b520-17f527e65a61, round 3

  • Score: 8/10, The reordered checks detect the late arrival, but an ordered reader can still skip the group if it polls again before the backfill cursor is notified.

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

  • Findings, open until the next round settles them:

    • Medium, rs/moq-net/src/model/resume.rs:3033: Force the backfill cursor to re-peek after detecting a landing
  • The last round's findings, at 42e6a50:

    • Open: medium, rs/moq-net/src/model/resume.rs:3011: Check for new arrivals and owed groups under the same lock; The wake at `rs/moq-net/src/model/resume.rs:3033` can trigger a retry before the producer notifies the backfill cursor at `rs/kio/src/channel.rs:355`, so the cursor can still return its cached `Pending` at `rs/moq-net/src/model/track.rs:13237`.

kixelated and others added 4 commits November 28, 2026 00:45
…ute still owes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s, in Rust and JS

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t mutant

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title An ordered front read waits for a group a replaced copy lost fix(net): an ordered front read waits for a lost group its serving route still owes Nov 28, 2026
kixelated and others added 2 commits November 28, 2026 03:51
…te landings

An ordered front read passed a group the serving route still owed when a
replaced route dropped it (as a relay losing it does), when the fill's
bounded read was still asking for its head, or when it landed on another
thread between the fill's read parking and the check. Only a skip now
settles a group across routes; a fill still fetching a head owes it, and
a fill whose track saw a group arrive since its read parked is read again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A group landing between the arrival check and the owed check read as
neither. Checking arrivals after closes the window: a landing counts as
arrived in the same step it stops being owed. A found landing wakes the
read to walk again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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