Skip to content

fix(transcode): finish the open live group when demand ends - #5938

Merged
kixelated merged 7 commits into
mainfrom
quest/m1/transcode-open-group
Oct 19, 2026
Merged

kixelated merged 7 commits into
mainfrom
quest/m1/transcode-open-group

Conversation

@kixelated

@kixelated kixelated commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Since #5820 a fetch is demand on a rung track, so it starts the rung's live loop. The group consumer a fetch resolves to is not demand, though. When the fetch ended mid-group, the loop saw the track unused and aborted the output group it was writing with Cancel:

  • a reader that had already picked the open group up from the cache read Cancel partway through;
  • an aborted group leaves the cache, so a later fetch of that sequence re-transcoded it from source, putting a second encode under the same group name.

two_instances_mirror_source_groups only passed by holding a query across its fetches.

Approach

Per the decision recorded in the quest (finish the group, then leave):

  • On unused with a group open, live sets leaving and rides the group out, the same way retirement already does. It finishes the group at the source's group end and then drops its listener and encoder, which releases the source.
  • If demand comes back before the group ends, the session carries on as if it had never left. If the track closes while the loop is leaving, the group is aborted as before.
  • The loop snapshots demand when the select hands it a feed item and again after the encoder flush at the group end. Demand that returns in either window keeps the session, so a returning viewer does not skip the next group while a new session attaches. Demand that leaves in either window ends the session at once: a queued Group is not opened, and a frame arriving with no group open does not hold the source. A final check after the boundary's flush and cut, right before create_group, covers demand that leaves while the codec works.
  • A group boundary with no end, a lag, or a source end still aborts the open group, since those groups really are incomplete.

Tests:

  • New ended_demand_finishes_the_open_live_group (paused time). A fetch for a group no one serves is the only demand, and the live path claims open source group 0. A reader takes group 0 from the cache, then the fetch is dropped. Without the fix the live path leaves its source mid-group and the reader gets Cancel. With it, the reader reads both frames and the source is released only after the group ends.
  • New ended_demand_opens_no_new_live_group (paused time). Source group 1 is queued just before the last fetch ends, so the live path sees both at once. Without the fix it opened output group 1 and rode it out with nobody asking, about half the rounds; the test runs eight rounds and fails every run without the fix.
  • two_instances_mirror_source_groups no longer holds a query. Before the fix it failed with Cancel without one.
  • Other tests still hold queries. Their own setup needs that demand (they start the live path or assert on demand), so those queries are not workarounds.

Impact

  • Public API: none.
  • Wire: none.
  • Behavior: once the last viewer leaves, a rung keeps its encoder and its source subscription until the end of the current source group. That is at most one GOP, or longer if the source stalls mid-group. Retirement already pays the same cost.

Alternatives

Both were rejected in the quest:

  • Aborting and re-transcoding on the next fetch: that puts two contents under one name.
  • Serving fetches on a separate path: more machinery for the same contract.

Follow-ups

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

kixelated and others added 2 commits October 19, 2026 00:54
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fetch is demand for the rung's live loop, but the group consumer it resolves to is not. When the fetch ended mid-group the loop aborted the group it was writing, under a reader that had already picked it up from the cache, and a later fetch re-transcoded the sequence under the same name. The loop now rides the open group out, as it already does on retirement, and leaves its source at the group boundary; demand returning before then resumes the session.

Drops the held query the mirroring test needed to keep the live path from aborting between fetches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review October 19, 2026 08:04
@kixelated

Copy link
Copy Markdown
Collaborator Author

Outcome of the unattended quest run:

  • I reproduced the bug before fixing it. Without the held query, two_instances_mirror_source_groups failed with Cancel. The new regression test fails without the fix in two ways: the live path leaves its source mid-group, and the reader gets Cancel.
  • just check passes locally. Interop wasn't run because nothing on the wire or in FFI changed.
  • I made two choices without asking:
    1. When demand comes back while the loop is riding out a group, it resumes the same session instead of ending it at the boundary and reopening. Reopening would drop the encoder's rate-control state and could skip the next group.
    2. I removed the held query only from the test where it was a workaround. In the other tests the held query is the demand the test is built on.
  • There are no open decisions.

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-19T18:35:00.505764Z 4bd007f 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.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 3 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
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4a73a99c-5749-44ee-b412-eec91b10334c
📥 Commits

Reviewing files that changed from the base of the PR and between 95ce660 and 4bd007f.

📒 Files selected for processing: 4
  • quest/m1/README.md
  • quest/m1/transcode-open-group.md
  • rs/moq-transcode/src/lib.rs
  • rs/moq-transcode/src/rung.rs

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ca8ef09-4ef3-4f47-9023-0162b505a4c7
📥 Commits

Reviewing files that changed from the base of the PR and between ad87ad3 and 95ce660.

📒 Files selected for processing: 4
  • quest/m1/README.md
  • quest/m1/transcode-open-group.md
  • rs/moq-transcode/src/lib.rs
  • rs/moq-transcode/src/rung.rs
💤 Files with no reviewable changes: 2
  • quest/m1/README.md
  • quest/m1/transcode-open-group.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Walkthrough

The live transcode loop now starts on any demand, including fetches. If demand ends during an open group, the loop completes the group unless demand returns first. A new test checks that the source remains in use until the group ends and that the output contains both frames. The documentation and m1 requirement list reflect the changed behavior.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 95ce6

The change lets the live transcode loop finish an open group after demand ends, rather than cancelling it under a reader. It comes with a regression test, and no actionable merge-blocking risk is evident.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary behavior change: finishing the open live transcode group when demand ends.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files.
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.
Description check Passed The pull request description directly explains the transcode demand bug, the approach to finish an open live group, the affected tests, and the expected behavior changes. It matches the changeset.
✨ 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

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

@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: 8fdd4167cd

ℹ️ 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 rs/moq-transcode/src/rung.rs
A select that picked a feed item over the `used` branch, or demand that
returned during the encoder flush at `Item::End`, left `leaving` stale and
ended the session anyway, so a returning viewer could miss the next group
while a new session attached.

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: 95ce660752

ℹ️ 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 rs/moq-transcode/src/rung.rs Outdated
kixelated and others added 2 commits October 19, 2026 11:11
The post-item demand recheck only cleared `leaving`, so demand that ended during the encoder flush or lost the select to a queued Group let the live path open that group and ride it out with nobody asking. Snapshot demand both ways, and leave on a stray frame with no group open.

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: 64b557d421

ℹ️ 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 rs/moq-transcode/src/rung.rs
kixelated and others added 2 commits October 19, 2026 11:28
Demand that left while the encoder flushed or cut at a group boundary still opened the next output group, which the live path then rode out with nobody asking. Recheck right before create_group.

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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 4bd007f01e

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

@kixelated
kixelated enabled auto-merge October 19, 2026 18:35
@kixelated
kixelated added this pull request to the merge queue Oct 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 19, 2026
@kixelated
kixelated added this pull request to the merge queue Oct 19, 2026
Merged via the queue into main with commit 824179a Oct 19, 2026
11 checks passed
@kixelated
kixelated deleted the quest/m1/transcode-open-group branch October 19, 2026 20:12
kixelated added a commit that referenced this pull request Oct 19, 2026
Port main's live-group finishing (#5938) in moq-transcode and the new
TRACK withdrawal test (#5973) onto the wanted-group Demand API.

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