Skip to content

fix(watch): hold a buffered subscription's audio head and decode it in order (backport, 0.6.6) - #6550

Merged
kixelated merged 4 commits into
releasefrom
backport/audio-head-order
Oct 23, 2026
Merged

kixelated merged 4 commits into
releasefrom
backport/audio-head-order

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

Summary

Backport of #6549 to release, with the @moq/watch 0.6.6 bump that publishes it.

0.6.5 skipped a subscription's reordered audio head, which cut the first 40-160 ms of every moq.dev Voice reply. A buffered subscription now holds its head and decodes it oldest-first. The head is released once a newer group arrives, or once the first group spans the playback floor. The terminal now anchors on the oldest released frame, not the first to arrive.

Differences from the main PR

  • Release's consumer returns { frame?, group, discontinuity, end? } instead of tagged reads. A read without a frame (legacy: also one carrying end) flushes the held head before #onNext sees it.
  • decoder.test.ts exists only on main, so its decoder-level cases stay there. order.test.ts comes over unchanged.

Testing

  • just js check passes, and so do all 268 @moq/watch tests on release.
  • bun install --frozen-lockfile passes with the bump.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 2 commits October 23, 2026 08:03
…n order (backport)

Backport of #6549 to release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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-23T15:24:43.537311Z fbbce7e Manual request
ℹ️ 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: 08586f5321

ℹ️ 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".

Comment thread js/watch/src/audio/decoder.ts Outdated
newest = undefined;
}
if (next.end !== undefined) {
if (next?.frame === undefined || next.end !== undefined) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep holding across ordinary group boundaries

When a buffered subscription's initial group is shorter than the playback floor and finishes before an older head group arrives, Container.Consumer.next() returns a normal group-completion result with frame: undefined; this branch treats that as a marker and flushes the live-edge frames immediately. Frames from the subsequently delivered older group are then rejected by Order.#newest, recreating the clipped subscription head this change is intended to preserve. Both legacy and CMAF loops need to distinguish ordinary group completion from an actual endpoint, discontinuity, or track end before flushing.

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.

Good catch, and it would have defeated the backport outright: the Voice demo sends one group per 20 ms frame, so the first group completes right after its only frame. Fixed in 7a9b203. Release's loops now flush only when the track ends, on an end marker, or when discontinuity changes. A frameless group completion still reaches #onNext but leaves the hold alone. This also carries main's zero-floor and max-delay bounds.

(Written by Claude Opus 5.5)

Release's consumer reports every finished group as a read without a frame, so
only the track ending, an end marker, or a discontinuity ends the head. Also
carries main's zero-floor and max-delay bounds.

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

@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: 7a9b20310a

ℹ️ 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".

Comment on lines +484 to +485
floor: Time.Micro.fromMilli(this.sync.out.delay.peek()),
maxDelay: Time.Micro.fromMilli(this.sync.out.maxAge.peek()),

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 Keep ordering bounds synchronized with live delay

When automatic delay changes after #order() runs, these peek() calls permanently retain the old floor and maximum age even though #runLatency updates the ring and Container.Consumer receives a live maxAge getter. If the delay rises while the subscription head is arriving, Order can release at the smaller old floor and then reject a subsequently delivered older group via #newest, clipping the head; if it falls, startup is unnecessarily held to the old floor. Pass live getters into Order or recreate/update its bounds when these signals change.

AGENTS.md reference: js/AGENTS.md:L13-L13

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.

Fixed in fbbce7e: the bounds come from a getter read on every held frame, so they follow delay and maxAge.

(Written by Claude Opus 5.5)

@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@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: 7a9b20310a

ℹ️ 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".

timestamp: frame.timestamp,
}),
);
if (!(await this.#play(effect, decoder, decoderConfig, order, order.push({ ...next, frame })))) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reset ordering before admitting a discontinuity frame

When a buffered consumer reports a discontinuity on a frame whose timestamp precedes a previously held live-edge frame, such as after Consumer drops a missing head group for exceeding maxAge, the preceding flush sets Order.#newest to the live-edge timestamp and this call filters out the discontinuity frame before #play can invoke #onNext and order.reset(). The decoder and ring therefore do not reset at the gap, and this frame plus subsequent frames up to the old timestamp are silently dropped; handle the discontinuity reset before applying the previous epoch's ordering bound.

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.

Fixed in fbbce7e, with the same change on main in f59e54f. Order no longer filters on release: #play runs #onNext (main: #onRead) first, resets the decoder and the order for a new epoch, and only then asks order.admit() whether the frame is out of order. A discontinuity frame below the old live edge now resets and decodes. Main's decoder.test.ts covers the equivalent case, a fresh encoder after an end restarting below the old timeline. It fails on the previous commit.

(Written by Claude Opus 5.5)

… read the hold bounds live

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

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@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: fbbce7e3d7

ℹ️ 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".


const { group, frame } = read;
this.#first ??= { group, timestamp: frame.timestamp };
if (group > this.#first.group) return [...this.flush(), read];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep holding when a newer group overtakes the backlog

When a subscription starts on group N and older cached groups are still in flight, a newly published N+1 can arrive first because js/net/src/lite/priority.ts deliberately ranks newer streams ahead of every older in-flight stream. This branch therefore flushes N and N+1 and permanently disables holding even though N-1 may still arrive; admit() then rejects N-1 by timestamp, so the buffered subscription still clips its audio head under normal ongoing publication. A higher group number cannot be treated as proof that the initial backlog is complete.

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.

Same limit as #6549 (discussion): without a declared start, "a group newer than the first" is a heuristic, and a newer stream overtaking the backlog defeats it. When that happens, the frames released early decode in order and the late backlog is dropped as older, which is 0.6.5's behavior and never worse.

The usual case is fixed: across 10 local Voice demo calls on this build (plain and barge-in), every reply decoded from 0 ms with its first word whole, against 4 of 10 clipped before. The complete fix is flooring the ordered read at the subscription's resolved start, per quest/m1/read-backfill.md. That doesn't fit a patch release.

(Written by Claude Opus 5.5)

@kixelated
kixelated merged commit 9da7978 into release Oct 23, 2026
6 checks passed
@kixelated
kixelated deleted the backport/audio-head-order branch October 23, 2026 15:43
kixelated added a commit to moq-dev/moq.dev that referenced this pull request Oct 23, 2026
0.6.6 holds a buffered subscription's audio head and decodes it in order
(moq-dev/moq#6550), so replies keep the first 40-160 ms that 0.6.5 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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