Skip to content

test(interop): the native JS audio reader joins at the live edge and drains before a gap - #9811

Merged
kixelated merged 2 commits into
mainfrom
quest/m0/test-flakes-5/js-native-aac-gap-under-load
Nov 28, 2026
Merged

kixelated merged 2 commits into
mainfrom
quest/m0/test-flakes-5/js-native-aac-gap-under-load

Conversation

@kixelated

@kixelated kixelated commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Under CPU load, rust -> js-native-node failed its audio check with a gap (audio gap after 4096 samples, at 2090666.333us for 917333.667us, 1 of 270 Rust cells in a full-width loop). The relay had delivered the group whole and the reader logged no skip warning.

Reproduced by pinning the Node subscriber to one CPU shared with 3 stress-ng workers and looping the Rust media round: 6 of 40 rounds failed (15%). A log line on the consumer's truncated-group branch named every failure: the start group of the read failed with group exceeded the subscription max delay budget (StreamCode.Old), set by @moq/net's #expire while the group still had frames in flight to the starved reader.

The cause is the reader's subscription, not the library. It joined its live range at { min: 5s, max: 5s }. A join that reaches back the whole budget starts on the group covering edge - 5s. That group goes stale once the live edge passes its successor's start plus 5 s, which is less than one group (1 s) after the join. Each backlog group after it has only one more second of slack. A reader slower than real time through that backlog loses the oldest group to its own budget. The consumer then correctly reports it as a gap. In every failing round, the group lost was the first one the relay served. The library did what the subscription asked. The client's comment says the 5 s budget exists for a reader that falls behind, but the join used all of it up before the first read.

The original AAC failure also matches quest/m0/interop-js-native-gap-drain.md. The edge of 2090666 us is past what the 4096 decoded samples cover. The reader had read ahead of libav's async output, so the frames it had already queued may have held the 600 ms it needed when the gap arrived. This PR does both quests.

Approach

test/interop/clients/js-native/subscribe.ts:

  • The audio reader joins at the live edge with the same 5 s budget: one AUDIO_DELAY = { min: 0, max: 5s } builds the subscription through Container.subscription and is the consumer's delay, so the two cannot disagree. The reader needs only 600 ms of audio, and now has the whole 5 s budget to fall behind in.
  • On a gap, the reader flushes the decoder first and fails only if the queued frames still fall short of the requested audio. This matches the Rust reader, whose synchronous decode never reads past want. tone.py judges only that window.

Deletes both quests.

Impact

None. This changes only the test client: no public API, no wire format.

Caused by

  • moq-dev/moq#6284 - subscribed the audio read with maxDelay: 5s, which reached back the whole budget and left the join's first group under one group from stale (found by check)
  • moq-dev/moq#9769 - threw on a gap immediately, before libav delivered frames already queued that could cover the requested audio (found by reviewer)

Decisions

  • Fix the client's subscription, not the library. Rejected: exempting a started group from @moq/net's max-delay expiry while its frames are in flight. The library cannot tell a starved event loop from a stalled wire, and for a real player those frames are past their playout deadline. Rejected: a unit test that fails first in @moq/hang or @moq/net. No library branch is wrong, so the failing-first test is the starved interop loop below.
  • Join at the live edge (min: 0). Rejected: keeping min and raising max, which is a longer timeout and is clamped by the Rust publisher's 5 s max-age anyway. Rejected: a min just under max, which is an arbitrary margin.
  • Leave the moq-audio readers (Rust, Python, Go, C, C++) at min = max. They have the same narrow first-group slack, but they decode natively and showed no failures in 540 cells. For them min is also the playout delay that sets how long a hole is waited for, so changing it changes what they test.
  • Leave video at min = max = 1s. A video gap is not a failure: the reader only needs one non-empty frame.
  • Do the gap-drain quest here, since it is the same observed failure and the same file.

Validation

  • Starved loop (.tmp copy of interop.sh looping start_publisher/run_round for rust -> js-native-node, the subscriber pinned with taskset -c 0, stress-ng --cpu 3 --taskset 0): 6/40 failed before, 0/60 after. Every passing round includes tone.py's judged audio. P(0/60 at 15%) is about 6e-5.
  • just test interop --publishers rust,python,go,cpp,js --subscribers js-native-node,js-native-bun: all passed, including the swapped-tone negative control, the finishes, and the tails.
  • just ci and just check passed.

Follow-ups

None.

Models

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

(Written by Claude Opus 5.5)

Review

Rewritten by quest review after each round.

  • Head: 0feab83
  • Base: origin/main at fb7990e
  • Risk: low, The change deletes two quest plan files and edits one interop test client (test/interop/clients/js-native/subscribe.ts) to flush the decoder before failing on a gap; if it is wrong, only the js-native interop test cell could flake or wrongly pass, and no shipped package, API, wire format, or consumer reads any of it, so a revert undoes it fully.
  • Classified: low by Claude Code, claude-haiku-5-5, low effort, session 878ecd9d-ede9-4c80-9967-0a596c8a8b9d
  • Risk file: bb7b1c0de60b
  • Local review: none, since the head is low risk

kixelated and others added 2 commits November 27, 2026 18:34
…drains before a gap

The js-native audio reader joined its live range at `min = max = 5s`, so its
first group (and each backlog group after it) started less than one group from
its own staleness budget. A Node reader starved on CPU, still draining that
backlog when the live edge moved on, lost the group as "exceeded the
subscription max delay budget", which the consumer reports as a gap. It now
joins at the live edge with the same 5 s budget, built by
`Container.subscription` from the one `Delay` the consumer reads too.

A gap also no longer fails a reader whose queued frames already hold the
requested audio: it flushes the decoder first, as libav's async output lags
what was read under load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A loaded Node reader keeps a whole Rust AAC group it has started test(interop): the native JS audio reader joins at the live edge and drains before a gap Nov 28, 2026
@kixelated
kixelated marked this pull request as ready for review November 28, 2026 05:08
@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The JS-native audio test client now uses a 5-second subscription delay for both the subscription and consumer. When the audio feed encounters a gap, it flushes the decoder and returns if the requested sample count has been decoded. Otherwise, it raises the existing gap error. Two investigation notes about the reported audio-gap scenario were deleted.

Merge Risk: Minimal · up to 0feab

This change adjusts how the JS-native interop audio test client joins the stream and handles gaps. It affects only test code, and the author reports passing stress and CI runs. No merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the native JS audio reader joins at the live edge and drains the decoder before a gap is raised. The description and raw summary both confirm this. The prefix 'test(in…
Description check Passed The description is detailed and directly related to the changeset. It explains the CPU-load failure, the subscription join at min 5s and max 5s, the change to a shared AUDIO_DELAY with min 0 and max 5…
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 names the main change: the native JS audio reader joins at the live edge and drains the decoder before a gap is raised. The description and raw summary both confirm this. The prefix 'test(interop):' fits the changed files, which are an interop test client and two deleted quest notes. The title is 88 characters, slightly long, but specific and accurate.

Full details: Description check

Explanation

The description is detailed and directly related to the changeset. It explains the CPU-load failure, the subscription join at min 5s and max 5s, the change to a shared AUDIO_DELAY with min 0 and max 5s, the decoder flush on gap, the deletion of both quest files, and the validation results. It fully matches the changes in subscribe.ts and the deleted quest notes.

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: 908b10ce-0df6-45e5-b0ef-abded1294f09
Commits

Reviewing files that changed from the base of the PR and between 065a4c1 and 0feab83.

Files selected for processing: 3

  • quest/m0/interop-js-native-gap-drain.md
  • quest/m0/test-flakes-5/js-native-aac-gap-under-load.md
  • test/interop/clients/js-native/subscribe.ts
Files with no reviewable changes: 2

  • quest/m0/interop-js-native-gap-drain.md
  • quest/m0/test-flakes-5/js-native-aac-gap-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.

@kixelated
kixelated added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit f24ac50 Nov 28, 2026
7 checks passed
@kixelated
kixelated deleted the quest/m0/test-flakes-5/js-native-aac-gap-under-load branch November 28, 2026 05:49
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