Skip to content

fix(net): a far-ahead group sequence costs a relay nothing extra (backport #9044) - #9109

Merged
kixelated merged 3 commits into
releasefrom
backport/far-ahead-key
Nov 18, 2026
Merged

kixelated merged 3 commits into
releasefrom
backport/far-ahead-key

Conversation

@kixelated

@kixelated kixelated commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Backport to release for quest/m0/backport-relay-high-key.md: the track half of moq-dev/moq#9044, so it ships in a moq-net patch in the next release.

Problem

A publisher that sends a far-ahead group sequence (say 1<<40) and then keeps publishing below it:

  • pinned every later arrival entry forever, since arrival was trimmed only from the front and the front is the protected live edge;
  • woke every ranged reader into a walk over all of those entries under the track lock, since the walk skipped below-floor entries without moving the reader's cursor.

Reproduced on release first: the new test saw 257 arrival entries for 2 cached groups.

Changes

All in rs/moq-net/src/model/track.rs:

  • Arrival entries carry their own position (Arrived { at, sequence, stamp }), with next_arrival replacing offset. compact_arrival drops dead entries from anywhere once the queue holds more than 2 * cached + EVICT_SLACK, the rule evict already uses, on each push and each expiry scan.
  • poll_recv_group moves the reader's walk position past entries it is never handed: dead, aborted, or below its floor.
  • Beyond the original fix: PlainSubscriber gains served, one past the last position handed out, and start_at lowering the floor rewinds the walk to it. main re-offers a lowered floor's groups from the cache (Filter::owed); release has no such path and instead relied on the cursor staying put, which a_widening_update_serves_the_finished_group_it_had_skipped tests. Without the rewind, that test fails (checked by deleting the line).

The front's track-info cleanup from #9044 stays on main, per the quest.

Impact

  • Public API: none. Wire: none.
  • Behavior: a far-ahead group sequence no longer grows a relay's memory, and its readers' wakes stop growing with it.

Decisions

  • The served rewind above is the one change beyond fix(net): a far-ahead group key costs a relay nothing extra #9044, so this stops at ready for the maintainer instead of landing on its own. Alternative considered: move the cursor only past dead entries, which keeps the memory fix but leaves each wake walking every cached below-floor group.
  • Aborted entries are passed too (main hands a cut group out; release skips aborted ones, and an abort is permanent for a stamp).

Validation

  • a_far_ahead_sequence_pins_nothing_behind_it (new): fails on release (257 entries for 2 cached groups) and passes here, with the reader's walk position at the queue's end.
  • a_lowered_floor_serves_a_group_the_reader_passed (new): a passed below-floor group is served after the floor drops, and a handed-out one is not replayed. Removing the rewind fails it and a_widening_update_serves_the_finished_group_it_had_skipped.
  • main's track_high_key bench, adapted to release's API (set_groups(HIGH..), group::Info { sequence }) and run locally, not committed (bench-only backports are their own PRs). Time per write:
readers / backlog 0 1024 16384
release, 1r 81 µs 81 µs 62 µs
release, 8r 243 µs 184 µs 227 µs
release, 64r 462 µs 457 µs 606 µs
this PR, 1r 0.65 µs 0.65 µs 0.64 µs
this PR, 8r 1.39 µs 1.41 µs 1.39 µs
this PR, 64r 8.5 µs 8.7 µs 8.5 µs

release grows with every iteration, so its points are all far up the slope; this PR is flat in the backlog and linear in readers.

  • just check passes (5200 Rust tests).

Caused by

  • moq-dev/moq#996 - introduced the front-only trimmed arrival queue with an offset, which can't drop entries behind a live front (found by an audit).

Models

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

🤖 Generated with Claude Code

(Written by Claude Opus 5.5 with high)

Review

Rewritten by quest review after each round.

  • Head: a42fef3

  • Base: origin/release at c636e03

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

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

  • Session: 01a1f055-8e79-75a2-9316-2da5a943bfca, round 2

  • Score: 9/10, The only incremental change removes an outdated comment reference and introduces no actionable regressions; builds and tests were not run as instructed.

  • Rounds: 2; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

…kport #9044)

Arrival entries carry their own position, so dead ones are compacted from
anywhere once they outnumber the cached groups, and a reader's walk moves
past the entries it is never handed (dead, aborted, or below its floor).
A lowered floor walks again from the reader's last hand-out, which keeps
release's widening-update behavior without main's cache re-offer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as draft November 18, 2026 20:24
@kixelated
kixelated marked this pull request as ready for review November 18, 2026 20:27
kixelated added a commit that referenced this pull request Nov 18, 2026
The fix lands on release in #9109.

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

@pullfrog pullfrog 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.

ℹ️ No correctness issues found. One stale comment is worth a quick fix.

Approach: sound. With absolute arrival positions, dead entries can be dropped from anywhere, so a protected far-ahead live edge no longer pins the queue. The served rewind keeps release's lowered-floor semantics without porting main's Filter::owed.

Reviewed changes: I reviewed the single commit, which backports the track half of #9044 to release.

  • Absolute arrival positions: arrival holds Arrived { at, sequence, stamp }, and next_arrival replaces offset. arrivals_from finds a reader's start with partition_point, which is valid because push_back and retain both keep at sorted.
  • compact_arrival: once arrival holds more than 2 * lookup.len() + EVICT_SLACK entries, it keeps only the current (sequence, stamp) entries. This runs on each visible push and on each expiry scan. Stamps are unique per incarnation, so at most lookup.len() entries stay live. The new predicate in expiry_mutation_due is therefore false right after a compaction and cannot keep a scan looping.
  • Cursor advance in poll_recv_group: the reader's index now moves past every entry it is not handed: dead, aborted, or below its floor. Each of those exclusions is permanent for that stamp, except the floor, which the next bullet handles. So a wake walks only entries that arrived since the last wake.
  • served rewind: when Subscriber::start_at lowers the floor, it rewinds index to one past the last hand-out. The other min_sequence writer (max at the Spliced/start_at raise path) only raises the floor, so it needs no rewind. Groups parked past the cap also set served, which matches the pre-PR behavior.
  • CACHE_OVERHEAD: the per-group cost now counts one Arrived hint plus one evict hint, so the pool bills the larger entry.
  • Tests: they cover both the bound on the arrival queue and the lowered-floor re-offer without replay.

ℹ️ datagram_offset's comment still names the removed offset

The comment on TrackState::datagram_offset (rs/moq-net/src/model/track.rs:205-206) still ends with "(mirrors offset for groups)". This PR deletes offset, and groups no longer use a pop-count offset at all. I couldn't attach this inline because the line is unchanged context in the diff.

Technical details
# Stale `offset` reference

## Affected sites
- rs/moq-net/src/model/track.rs:205-206: the `datagram_offset` comment says "(mirrors `offset` for groups)", but `offset` was removed in favor of `Arrived.at` / `next_arrival`.

## Required outcome
- The comment no longer names the removed field, for example by dropping the parenthetical.

Pullfrog  | Fix it ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

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

Copy link
Copy Markdown
Collaborator Author

Fixed in a42fef3: the datagram_offset comment no longer names the removed offset. Comment-only change.

(Written by Claude Opus 5.5 with high)

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes: the one commit since the prior pullfrog review.

  • Dropped the stale offset reference from the datagram_offset comment in rs/moq-net/src/model/track.rs, which addresses the earlier nit.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@kixelated

Copy link
Copy Markdown
Collaborator Author

Decision from the maintainer:

  • ✅ Accept the served rewind and land (rejected: move the cursor only past dead entries, hold).

(Written by Claude Opus 5.5 with high)

@kixelated
kixelated merged commit 381b802 into release Nov 18, 2026
21 checks passed
@kixelated
kixelated deleted the backport/far-ahead-key branch November 18, 2026 21:57
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