Skip to content

fix(watch): decode a reordered subscription head in timestamp order - #6523

Merged
kixelated merged 1 commit into
mainfrom
fix/audio-decode-order
Oct 23, 2026
Merged

kixelated merged 1 commit into
mainfrom
fix/audio-decode-order

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

Summary

The moq.dev Voice demo still clipped the first reply intermittently on @moq/watch 0.6.4, after #6425.

A subscription's head groups can reach the decoder newest-first. A trace of a clipped run showed decoder inputs at 140, 120, ... 0, then 160 ms. Chrome's AudioDecoder stamps outputs contiguously from its first input, so every output landed 140 ms late. Backpressure then admitted 140 ms past the floor. With #6217's fixed 100 ms delay, the ring holds 200 ms, so it overflowed on every frame. 0.6.2 hid this because its floor grew to about 400 ms.

Both decode loops now skip a frame older than the newest one already sent to the decoder since its last reset. The ring anchors at its first insert and drops those frames anyway, so playback loses nothing it would have kept.

Testing

  • New decoder.test.ts cases (legacy and CMAF) feed the reversed head; both fail without this change and pass with it.
  • just js check passes.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

A subscription's head groups can arrive newest-first. Chrome's AudioDecoder
stamps every output contiguously from its first input, so decoding the older
frames after the newest shifts the whole track forward by the reorder. With a
fixed 100 ms delay that pushes the gate past the ring's capacity and overflows
it on every frame. Skip frames older than the newest one already decoded: the
ring, anchored at the first insert, drops them anyway.

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

coderabbitai Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ 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: af36c4d6-d463-4677-8790-4b9146d4ad20
📥 Commits

Reviewing files that changed from the base of the PR and between 69b9130 and 1f8701d.

📒 Files selected for processing: 2
  • js/watch/src/audio/decoder.test.ts
  • js/watch/src/audio/decoder.ts
  • 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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T07:02:27.526157Z 1f8701d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f8701db0b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// alongside them, and the ring, anchored at the first decoded frame, cannot place audio
// before it. Chrome's AudioDecoder would also stamp every later output from its first
// input, shifting the rest of the track by the reorder and overflowing a buffered ring.
if (newest !== undefined && frame.timestamp < newest) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain playable history when the ring is reused

When a replacement subscription reuses the existing ring, such as after a rendition swap or temporary absence, its playhead can still precede the older head frames that arrive after the live edge. The ring is explicitly preserved across these replacements and can place such frames by timestamp (decoder.ts:400-404), but this check permanently discards every frame older than the first replacement frame, producing an avoidable audio hole. The comment's anchoring premise applies only to a new ring; the initial subscription head needs to be reordered before decoding, or filtered against the reused ring's playhead rather than the decoder's newest timestamp. The duplicated CMAF check has the same problem.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real, but narrow, and decoding those frames doesn't fill the hole on Chrome either: its AudioDecoder stamps every output from its first input, so before this change the older head frames landed after the newest one, in the wrong slots, and shifted everything after them. Skipping them trades that misplacement for a gap.

On a rendition swap the predecessor was live through that span, so its audio already covers the slots below the replacement's first frame. The hole appears only on a return from an absence, where the predecessor stopped short of the new head. Even then it is bounded by the head's span, and only non-Chrome decoders (which keep input timestamps) placed those frames correctly before.

Reordering the head before decoding would hold the live edge until the older groups arrive, which defeats delivering it first. Resetting the decoder on every backward frame to make Chrome restamp would cost an Opus state reset per head frame. Neither seems worth it for this case, so I'm keeping the skip.

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit 1696858 Oct 23, 2026
9 checks passed
@kixelated
kixelated deleted the fix/audio-decode-order branch October 23, 2026 07:20
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