Skip to content

fix(scene): a lost group stalls a layer no longer than it plays behind - #231

Draft
kixelated wants to merge 4 commits into
mainfrom
quest/m2/compose/layer-delay
Draft

kixelated wants to merge 4 commits into
mainfrom
quest/m2/compose/layer-delay

Conversation

@kixelated

@kixelated kixelated commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

A lost group stalls a composition layer only as long as the layer plays behind, not for the fixed LAYER_DELAY (4 s) every layer held. Holds quest/m2/compose/layer-delay.md open, now waiting on a moq investigation (see Waiting); the PR that lands it deletes the quest.

Changes

rs/moq-scene/src/source.rs:

  • LAYER_DELAY is gone. Each layer track keeps a Reach: the longest wait between a frame arriving (Consumer::arrival) and coming due on the program's clock, plus LEEWAY (VIDEO_DELAY, 100 ms). The reach grows at once when a wait gets within a frame of it. It shrinks only after a whole second of shorter waits, so the late frames a loss leaves behind don't shrink it. It is capped at moq_mux::container::DELAY_MAX, however a peer stamps its frames.
  • Video (follow_video): moq_video's decoder has no set_max_delay at this pin, so when the reach moves, the layer subscribes again with Delay { min: reach, max: reach }. That join starts where the layer plays. The old subscription keeps playing until the new one opens. Pictures the join repeats (at or before the newest queued picture) are dropped.
  • Audio (follow_audio): set_max_delay(reach + STRETCH) in place, as moq play does.
  • Tests:
    • a_reach_follows_the_longest_wait covers the estimator's edge cases.
    • a_lost_group_stalls_a_layer_no_longer_than_it_plays_behind uses a paused clock and a forwarder that delivers only the first frame of one group and never finishes it. It asserts that the next group shows within the layer's lag of when it is due. It fails on the base commit (the next group showed 3.6 s after due) and passes 40/40 under --stress-count.

A choice that differs from the quest's wording

The Plan says to set Delay::max "from its own composition offset plus the viewer's playout". A layer's offset maps one broadcast's timestamps onto another's, so it also includes how far apart the two publishers' clocks sit. That can be any size; plays_a_guest_where_the_studio_did shows offset = apart + playout. Measuring each frame's arrival-to-due wait gives the intended quantity directly: the studio's playout, which the offset carries, plus the viewer's playout and the path difference. It needs no wall-clock agreement between machines, and it follows offset and playout changes without watching either.

Validation

  • just ci passes (523 tests).
  • The real surface, over a lossy link. A scratch harness (not committed: about 60 s per run, and it needs a network namespace) runs a moq_relay::test_relay, two 320x180 30 fps openh264 broadcasts (1 s GOP) in-process, and a player whose Sources connect over QUIC. Loopback is shaped with netem inside unshare -rn. The layer has offset 300 ms, so it plays about 400 ms behind. "Stalled" sums the gaps over 100 ms between new pictures, per 60 s after a 5 s warmup. All variants are release builds.
    • Random loss (20±5 ms delay, 2% and 5% loss): QUIC retransmits inside the 400 ms lag, so no variant stalls the layer beyond the program's own stalls. Base: 0 and 0.75 s stalled; this branch: 0 and 0.

    • Outages (1% loss plus 600 ms of 100% loss every 5 s), 5 runs each. Layer stall ÷ the program's stall in the same run:

      Variant Layer ÷ program Max gap p99 gap Reach changes / min
      Base (LAYER_DELAY = 4 s) 0.63 0.47–1.1 s 69–117 ms 0
      This PR (wait + 100 ms leeway, resubscribe) 0.77 0.79–0.87 s 70–79 ms 35–53
      Wait alone, no leeway 0.77 0.58–1.0 s 160–370 ms 33–40
      Wait + 500 ms leeway 0.69 0.73–0.91 s ~70 ms 17–27
      Alternative C: wait alone, max moved in place (scratch set_max_delay in moq_video) ~0.87 (1 run) 0.80 s 317 ms 36
    • 1.2 s outages (1 run each): layer stalled 17.8 s on the base, 15.8 s on the wait-alone variant, and 18.5 s on C. Max gap 2.26 s, 1.54 s, and 1.77 s.

    • Reading: resubscribing (A) and moving the max in place (C) stall alike, so a moq-side set_max_delay buys no measurable stall improvement here, only fewer decoder reopens. Under outages, where the "lost" data is retransmitted rather than gone, holding the max close to the lag stalls the layer more than a 4 s max does, and more leeway narrows the gap. The maintainer's decision on it is under Decisions.

  • Not exercised on the lossy link: layer audio (the harness publishes video only). The existing layer sound tests pass.

Public API and wire impact

None. Everything changed is private to moq-scene::source. On the wire, a layer's subscriptions state a smaller Subscriber Max Age and a non-default Subscriber Min Age, and video layers subscribe again (SUBSCRIBE_UPDATE for audio) as the reach moves.

Caused by

  • moq-dev/studio#146 - introduced the fixed LAYER_DELAY of two playouts for every layer (found by person, the quest's planning)

Decisions

Maintainer, via /quest-run (comment):

  • Lost-group stall vs outage cost: ✅ hold this PR and first find out in moq why a short Delay::max drops video that retransmission would deliver in time (rejected: land as is; land with a 500 ms LEEWAY). The PR stays a draft until that lands.
  • In-place set_max_delay on moq_video::decode::Consumer: ✅ not needed for this quest (rejected: plan it in moq now). Revisit in moq only if decoder reopen CPU shows up.

Both are recorded in the quest's Plan.

Waiting

  • moq-dev/moq: the investigation into why a short Delay::max drops video that retransmission would deliver in time lands. Check: a moq quest named for it has merged on moq's main, deleting its file, with a moq-side test that a group arriving late within the reader's lag is delivered, not skipped; then bump the moq gitlink here and re-measure the outage runs above. A quest file that moved, or went away without its work landing, does not count.

Follow-ups

For /quest-plan in moq-dev/moq's tree (its quest tree owns the work, so none is added here):

  • Why does a short Delay::max drop video that retransmission would deliver in time? Evidence from this PR's lossy-link harness (loopback netem inside unshare -rn, a moq_relay::test_relay, two 320x180 30 fps openh264 broadcasts with a 1 s GOP, a layer playing about 400 ms behind, release builds; "stalled" sums gaps over 100 ms between new pictures per 60 s after a 5 s warmup):
    • Random loss (20±5 ms delay, 2% and 5% loss): QUIC retransmits inside the 400 ms lag; no stall beyond the program's own.
    • Outages (1% loss plus 600 ms of 100% loss every 5 s, 5 runs): layer stall ÷ program stall is 0.63 with Delay::max = 4 s, 0.77 with max = the layer's wait + 100 ms, 0.69 with + 500 ms, and about 0.87 with the max moved in place (1 run). Max gap 0.47–1.1 s at 4 s against 0.79–0.87 s at the short max.
    • 1.2 s outages (1 run each): layer stalled 17.8 s at 4 s max, 15.8 s at the short max, 18.5 s with the in-place max.
    • Hypothesis: the outage's data is retransmitted, so it arrives late but intact. With a short max, moq-net skips the late group, and with it that group of pictures' tail, which would have been on time, so the decoder waits for the next keyframe (up to 1 s) instead. A test: a group whose frames arrive late within the reader's lag, delivered whole, not skipped; and one whose first frames are late past the max, where the on-time tail still plays or the skip is by frame, not by group. Check the skip's unit in moq-net (group vs frame) first.

Models

Size: S
Implementer: Claude Code, claude-opus-5-5, unknown effort (arm A)
Implementer: Claude Code, claude-sonnet-5-5, high effort (iterate, XS, arm A)

🤖 Generated with Claude Code

(Written by Claude Sonnet 5.5 with high effort)

kixelated and others added 3 commits November 22, 2026 15:39
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A lost group stalls a layer no longer than its offset fix(scene): a lost group stalls a layer no longer than it plays behind Nov 23, 2026
@kixelated

Copy link
Copy Markdown
Contributor Author

Maintainer decision (via /quest-run):

  • Lost-group stall vs outage cost: ✅ 3, hold this PR and first find out in moq why a short Delay::max drops video that retransmission would deliver in time (rejected: 1, land as is; 2, land with a 500 ms LEEWAY). The PR stays a draft, waiting on that moq investigation.
  • In-place set_max_delay on moq_video::decode::Consumer: ✅ not needed for this quest (rejected: plan it in moq now). Revisit in moq only if decoder reopen CPU shows up once this lands.

(Written by Claude Opus 5.5)

…max drops retransmittable video

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

Copy link
Copy Markdown
Contributor Author

Applied the maintainer's decision on head b100663: both answers are recorded under ## Decisions and in the quest's Plan, the two Maintainer items are replaced by one moq-dev/moq ## Waiting item, and the moq investigation is listed under ## Follow-ups with the outage measurements and the group-of-pictures-tail hypothesis. The quest file stays until this lands. The PR remains a draft; no code changed.

(Written by Claude Sonnet 5.5 with high effort)

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