Skip to content

fix(net): a read that finds the end settles a waiting live join first - #9810

Merged
kixelated merged 5 commits into
mainfrom
quest/m0/test-flakes-5/finish-go-row-under-load
Nov 28, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/m0/test-flakes-5/finish-go-row-under-load

Conversation

@kixelated

@kixelated kixelated commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m0/test-flakes-5/finish-go-row-under-load.md.

Problem

Under load, a reader of a finished track sometimes got nothing, even though the relay held the tail.
That is the finish go -> * row failing with no health group (seen on #9758) or expected 10 frames, received 0 (seen on #9793), and the finish cpp -> * row the same way (seen on #9813).

The cause is a race in moq-net's Cursor, in the received lite-07 copy a relay (or a client) keeps.

  1. A live join (Start::LATEST) on a copy whose upstream answers joins waits for that answer. It does so only while the copy's end is undeclared, so the window "reaches" and admits nothing.
  2. The read syncs its window, then walks the track.
  3. If SUBSCRIBE_END lands on another tokio thread between those two steps, the walk passes the held group (the window is still reaching) and then finds the track complete.
  4. So the read returns Ok(None). The front ends the read, and the publisher sends the reader START/END with no group.

With the end declared, a re-sync would have placed the join locally over that group. The existing re-sync after the walk ran only when the walk was pending, not when it found the end.

The race needs the end to land mid-poll on another thread, so the single-threaded kio sim can't reach it, even with KIO_SIM_SCHEDULE=random. It shows only under multi-threaded tokio with scheduling jitter. Tracing a failing relay confirmed the order: the copy cursor's feed ended with the window still reaching and group 0 cached, and "place live" came right after.

Approach

When the walk finds the feed ended and re-syncing moves the window, both reads (poll_peek_recv for arrival order, poll_peek_next for group order) now start over. That covers the case the old re-sync missed: it ran only when the walk was pending. Starting over means syncing, probing (which sends any lookup a newly resolved time start needs), and seeking again from the committed next key.

The walks report a private Walked { Found, Ended, Again } and the reads loop on Again, so the stack stays constant. A join that waited on its upstream then places over the held group. Only a read that is still empty after a settled walk ends.

JS needs no change. Its #tryRecvGroup settles and walks synchronously on one thread, so the end can't land between the two.

Impact

  • Public API: none.
  • Wire: none.
  • Behavior: a live reader of a received copy whose end lands mid-read now gets the held tail instead of an empty track.

Caused by

  • moq-dev/moq#9316 - made a live join on a lite-07 copy wait on its upstream only until the end is declared (joins_answered), so a window can move when the end lands, but the reads re-settled only on a pending walk, not on one that found the end (found by check: interop under load).

Validation

  • New unit test a_read_finding_the_end_places_its_waiting_join_first drives the race by hand. It syncs the cursor, declares the end, walks, then reads again, for both read orders. It fails without the fix (the walk reports the end with no group) and passes with it.

  • cargo nextest run -p moq-net --all-features: 4674 passed.

  • cargo clippy -p moq-net --all-features --all-targets -D warnings: clean.

  • just check on the merged head 621bda3: passed. Later heads changed only track.rs, rechecked with the nextest and clippy runs above.

  • Under load, with the interop finish lane (just test interop --finish --all --publishers <row>) looped, three runs in parallel, while a script randomly SIGSTOPped the relay and client processes for up to 900 ms. Plain CPU load (stress-ng, CPU pinning, parallel full runs) never reproduced it in about 60 go rows.

    Build Row Reps Reps that lost data
    Before: this branch with only the fix reverted (control) go 210 8 (3.8%)
    Before: investigation runs on main go 482 12 (2.5%)
    After: first fix, 94fe208 go 210 0
    After: first fix, 94fe208 + main cpp 210 0
    After: final head, e869e9d go 150 0
    After: final head, e869e9d cpp 150 0

    Every before-fix data loss was one of the quest's symptoms: no health group, missing session health group, expected 10 frames, received 0, finish did not drain naturally (frames=0 ...), catalog stream ended without a video and an audio track. They hit the rust, go, python, cpp, c, js-native-bun and js-native-node readers. The final runs passed all 2700 cells.

    The investigation runs also hit finish go -> js-native-node (exited 124) twice: the reader printed finish clean ... health=ok and then didn't exit. That is js-native-finish-reader-exit.md, not this bug, and it didn't recur in any of the 1350 reps above.

  • I confirmed the order of events from a failing relay's trace, using scratch instrumentation that is not in this PR. The copy cursor's feed ended with the window still reaching and group 0 held, then "place live".

Decisions

  • Fix the read at the moment it finds the end, not the producer or the window. Rejected:
    • Marking the join settled when finish_at runs. The end lands on the producer, which doesn't own the readers' windows.
    • Having the walk treat a reaching window as admitting everything. That would serve groups a live join hasn't proven are its answer, which breaks the cache rule in AGENTS.md.
    • Taking the producer lock across sync and walk. That's a wider lock change to fix one ordering.
  • Start the whole read over, not re-walk in place (review round 1). Re-walking in place left a new lookup unsent, and an ordered floor past groups the window now reaches.
  • Loop, not recurse (review round 2's note), so the stack stays constant.
  • Test the race as a deterministic unit test on Cursor, not a sim or interop test. The sim is single-threaded and can't land the end mid-poll, and an interop test reproduces it in only about 3% of reps under SIGSTOP jitter.
  • Declined review round 3's note to inject the end inside a single poll_peek_* call. That needs a test-only hook in the read path, to cover a three-line mapping (Walked::settled).
  • Measured the cpp row (added to the quest on main by #9813) only after the fix: it shares the relay copy path the go control measured. Rejected: a second 17-minute control run for the same code path.
  • No JS change. Its read settles and walks synchronously on one thread.
  • Left gst-finish-late-tail.md open. Its 0 of 10 finished frames on the go row looks like this same race (moqsrc reads the relay's copy too), but its gst failure never reproduced here, so this PR can't claim it. Rejected: deleting it unverified.

Follow-ups

  • gst-finish-late-tail.md: likely the same cause. Its next failure, or a quiet stretch after this lands, decides it.
  • js-native-finish-reader-exit.md: the Node reader's exit-124 hang after success, seen 2 times in 482 jittered reps. It already has a quest, so none was added.

Models

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

Review

Rewritten by quest review after each round.

  • Head: e869e9d

  • Base: origin/main at e1dd5f6

  • Risk: medium, The change is a private read-loop fix in rs/moq-net/src/model/track.rs (new private `Walked` enum, poll loops restarted on a feed end) plus a test and a deleted quest plan, keeping every public API and wire format, so it is a fix the next cut publishes as a patch; if wrong, a read could hang or miss a group for subscribers of shipped relays and clients, but the repository's tests and a revert of the commits undo it.

  • Classified: medium by Claude Code, claude-haiku-5-5, low effort, session 18642fbb-0ab3-4b07-8a55-fe57721c15f7

  • Risk file: bb7b1c0de60b

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

  • Session: 01a221c5-f584-7af3-a666-c9101537cbc1, round 3

  • Score: 10/10, The iterative EOF retries preserve both fixes without growing the stack, and no blocking regressions were found.

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

  • Findings: none

  • Notes, the author's to take or leave:

    • rs/moq-net/src/model/track.rs:21431: Exercise the EOF retry within a single read

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

A received lite-07 copy's live join waits on its upstream only until the
copy's end is declared. When SUBSCRIBE_END landed on another thread between
a read syncing its window and walking the track, the walk passed the held
group (the window still reaching) and then found the track complete, so the
read ended with no group: the interop finish lane's empty health and video
tracks under load. Both reads now re-settle the window when the walk finds
the end, not only when it is pending, and walk again if it moved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title The finish lane's readers get the Go publisher's tail under the full matrix fix(net): a read that finds the end settles a waiting live join first Nov 28, 2026
kixelated and others added 3 commits November 28, 2026 02:37
…5/finish-go-row-under-load

# Conflicts:
#	quest/m0/test-flakes-5/finish-go-row-under-load.md
Review round 1: re-walking in place kept a time start's new lookup unasked
(the arrival read then parked with nothing to wake it) and kept an ordered
walk's floor past groups the moved window now reaches. Both reads now run
again from the top, which syncs, asks lookups, and seeks from the next key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2's note: each start-over recursed, so a burst of window moves
landing between preparation and the walk's end could grow the stack. The
walks now report `Walked::Again` and the reads loop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 28, 2026 11:30
@kixelated
kixelated added this pull request to the merge queue Nov 28, 2026
@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Arrival-order and key-order track reads now retry when end-time synchronization moves the subscription window. A regression test checks both read orders. The change also removes a document that described intermittent interop failures and an investigation plan.

Merge Risk: Minimal · up to e869e

This change makes track reads retry when a received copy ends while a live join's window is still reaching. Before, such a read could end the reader despite a held tail group. The change is private to moq-net, with no public API or wire changes. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title describes the main change: a read that finds the end of a received track now settles a waiting live join before returning. This matches the track.rs changes that restart cursor reads when th…
Description check Passed The description explains the race in moq-net's Cursor, the fix that restarts poll_peek_recv and poll_peek_next when a walk finds the feed ended, the new regression test, and validation results. It als…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title describes the main change: a read that finds the end of a received track now settles a waiting live join before returning. This matches the track.rs changes that restart cursor reads when the feed ends and the window moves, and the regression test for both read orders. The title is specific and follows the fix(net) convention.

Full details: Description check

Explanation

The description explains the race in moq-net's Cursor, the fix that restarts poll_peek_recv and poll_peek_next when a walk finds the feed ended, the new regression test, and validation results. It also covers the deleted quest file and the follow-ups. It relates directly to the changeset.

Finishing Touches

Simplify code

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

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: cc6cac9b-ad3f-40e2-94c9-140a4dbc38ac
Commits

Reviewing files that changed from the base of the PR and between e1dd5f6 and e869e9d.

Files selected for processing: 2

  • quest/m0/test-flakes-5/finish-go-row-under-load.md
  • rs/moq-net/src/model/track.rs
Files with no reviewable changes: 1

  • quest/m0/test-flakes-5/finish-go-row-under-load.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

Merged via the queue into main with commit e91efb9 Nov 28, 2026
6 checks passed
@kixelated
kixelated deleted the quest/m0/test-flakes-5/finish-go-row-under-load branch November 28, 2026 11:37
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