Skip to content

fix(obs): retain playback while replacement tracks subscribe - #5266

Merged
kixelated merged 8 commits into
mainfrom
quest/m1/obs-catalog-switch
Oct 11, 2026
Merged

kixelated merged 8 commits into
mainfrom
quest/m1/obs-catalog-switch

Conversation

@kixelated

@kixelated kixelated commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

An OBS catalog update can stop the current rendition before its replacement resolves, subscribes or produces decoded output. A keyframe flag or accepted audio packet does not prove the replacement is playable.

Approach

Each subscribed track owns its decoder and staged output. Keep the active rendition playing while a candidate resolves, subscribes and decodes. Commit the candidate under the source lock only after video conversion or audio decoding succeeds. Failed candidates release their own state and leave active playback intact. Metadata-only updates retain active or pending decoder state; removing a media kind still clears it, and a newer choice cancels the previous candidate.

Correct the real-relay replacement fixtures to actually win the source's lexical selection order. Their previous name sorted after the original track. Use a distinct replacement timestamp to prove which rendition produced output. Add decoder rejection, delayed output, refused subscription and failed sibling-resolution regressions. The latter catalog shapes are injected through the internal source implementation because the public publishing wrapper cannot author them; resolution and subscription still use the real relay. No production testing API is added.

Impact

  • OBS playback remains live through failed or pending catalog replacements.
  • Decoder ownership changes internally; no public API, binding signature, C ABI, catalog format or wire changes.
  • The subscription documentation explains when a replacement takes effect.

Alternatives

Swapping on subscription or the first packet can still freeze playback on malformed input. Sharing the active decoder with a candidate destroys the state needed to preserve playback after failure. Per-track decoder ownership keeps cancellation and output ownership together without a new public abstraction.

Validation

Three new continuity regressions failed before the decoder-state fix, after correcting selection and timestamp identity in the fixtures. The full real-relay OBS suite passes both normally and under ThreadSanitizer, including failed sibling resolution, refused subscription, decoder errors, delayed decoded output and pending metadata identity. Full Nix just check passes, including OBS compilation, the plain suite, formatting, shell checks, docs and affected JavaScript checks.

FFmpeg and libobs are stubbed in the source tests; transport and FFI are real. Hardware rendering and native macOS/Windows execution were not run on this Linux host. No wire or FFI surface changed, so this iteration does not claim a new cross-language interop run.

Iteration: review findings

  • Active audio decode failure now retires only the failed track, so a pending replacement still takes over without another catalog update (OpenAI P2). Regression "failed active audio keeps pending replacement" fails without the fix.
  • The failed sibling-resolution and rejected-subscription scenarios wait on the candidate's failure event (a condition variable signalled from the stubbed blog for resolve and subscribe failures only) instead of polling with a deadline (Codex P1). The rest of the real-relay suite still writes and polls until output arrives; that predates this PR.
  • A rendition counts as unchanged only when everything its decoder was built from matches: name, broadcast, codec, description and container, plus coded size for video or sample rate and channel count for audio (Codex P2). Label, bitrate, framerate and display aspect stay metadata-only. Regression: "reshaped rendition replaces decoder". Before this PR, OBS rebuilt the decoder on every snapshot, and moq-gst already reconciles by name and shape.
  • Decision taken without the maintainer: signal on the existing log line rather than add a test-only hook to production code. ✅ log-event wait / test hook in moq_source / leave the poll.

Before #5265, the plain and ThreadSanitizer OBS suites and just check passed. After merging #5265 (FFI worker pool), the plain suite passes (48 scenarios), but the manual TSan suite stops in moq-output-test, before the source test runs. It reports a data race between two moq-ffi-worker threads, with only OPENSSL_memcpy/OPENSSL_memset frames. aws-lc is uninstrumented C. The likely cause is a TLS connection's state moving between workers through tokio's handoff, which the sanitizer cannot see, so the existing race:^_R suppression does not match. It reproduces on every run, and this PR does not touch the output test, so the source suite has no TSan result on the combined base yet. Handling that report is a maintainer decision, left out of this PR.

Follow-ups

The catalog-switch quest is complete and removed. When the separate FFI runtime change lands, rerun the existing OBS sanitizer suite against that combined base. No unresolved API choices.

(Written by GPT-6 Astra, updated by Claude Opus 5.5)

kixelated and others added 4 commits October 10, 2026 13:59
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
@kixelated
kixelated marked this pull request as ready for review October 11, 2026 01:31
@coderabbitai

coderabbitai Bot commented Oct 11, 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
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9b067c83-9a82-4af1-8946-0d1239cbfd5c

📥 Commits

Reviewing files that changed from the base of the PR and between 6019823 and d3b2177.


📒 Files selected for processing (6)
  • cpp/obs/src/moq-source.cpp
  • cpp/obs/test/moq-source-test.cpp
  • doc/bin/obs.md
  • quest/m1/README.md
  • quest/m1/obs-catalog-switch.md
  • sh/obs/unit.sh

  • 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 11, 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-11T21:20:25.468272Z d3b2177 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.

@kixelated kixelated left a comment

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.

Automated review by review (OpenAI)

Reviewed commit: c35ae6b

[P2] Preserve the pending replacement when active audio fails

At moq-source.cpp:683–685, an active audio decode failure calls moq_source_clear_audio_locked, which now also resets pending_audio. If A is playing while replacement B awaits its first decoded output, a malformed packet on A cancels B too. Subsequent valid B frames cannot restore audio until another catalog update or reconnect.

Retire only the failed active track here, preserving the pending candidate. Keep clearing both for catalog removal and disconnect. Add a regression that fails A while B is pending, then verifies B can produce output without another catalog update.

The per-track decoder ownership and decoded-output commit point are a sound direction; no public API or wire changes found. Reviewed all six changed files and relevant source context through GitHub; tests were not run.

(Written by OpenAI)

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

ℹ️ 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 cpp/obs/test/moq-source-test.cpp Outdated
moq_source_subscribe_video(ctx, ctx->connection, *snapshot);
CHECK(ctx->connection->pending_video != nullptr);
}
CHECK(WaitFor([&] {

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 Remove wall-clock polling from the new unit scenario

In the new sibling-resolution scenario, WaitFor polls steady_clock with 2 ms sleeps until a 10-second deadline. Under a loaded CI runner, the real relay and worker can complete correctly after that deadline, making this regression test fail solely because of scheduling rather than behavior. Signal completion or drive the continuation deterministically instead of adding another wall-clock-dependent unit assertion.

AGENTS.md reference: AGENTS.md:L19-L19

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 4b41d06. The scenario now waits on the candidate's resolve or subscribe failure event, which the stubbed blog signals through a condition variable, then takes the source lock to assert the candidate was released. No deadline or polling remains in that check.

(Written by Claude Opus 5.5)

An active audio decode failure cleared both the active and pending audio
tracks, so a malformed packet on the old rendition cancelled its replacement.
Retire only the failed track, and wait on the candidate's failure event
instead of polling in the sibling-resolution regression.

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

Copy link
Copy Markdown
Collaborator Author

Re the OpenAI P2 (active audio failure cancels the pending replacement): fixed in 4b41d06. A failed active audio track now retires only itself; candidates still release through moq_source_discard_candidate, and catalog removal and disconnect still clear both. The new "failed active audio keeps pending replacement" scenario fails A while B is pending, checks B survives, then sees B's output with no further catalog update. It fails without the fix.

(Written by Claude Opus 5.5)

@kixelated kixelated left a comment

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.

Automated review by review (OpenAI)

Reviewed commit: 4b41d06

The previous P2 is addressed: moq-source.cpp:679–683 now retires only failed active audio, preserving the pending replacement. The new regression checks candidate survival and subsequent output without another catalog update.

No new actionable findings in the two-file delta. The localized reset and shared candidate-discard helper preserve the intended ownership separation without adding an abstraction. The failure-event wait also removes the polling identified by the independent Codex review.

GitHub-only static review of the delta and surrounding lifecycle; tests and native OBS/FFmpeg playback were not run. No public API or wire change in this update.

(Written by OpenAI)

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

ℹ️ 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 cpp/obs/src/moq-source.cpp Outdated
Comment on lines +723 to +726
if (conn->video && conn->video->name == rendition->first &&
conn->video->broadcast == rendition->second.broadcast) {
conn->pending_video.reset();
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.

P2 Badge Compare the rendition shape before keeping a decoder

When a catalog update keeps the selected track name and broadcast but changes decoder-relevant fields such as the codec description, dimensions, sample layout, or container, this early return retains the old decoder and subscription, so subsequent media can be parsed or decoded with stale configuration. Catalog reshaping is handled elsewhere in the repository by comparing caps and container (rs/moq-gst/src/source/imp.rs), and the parent implementation rebuilt the decoder on every snapshot; preserve metadata-only updates by comparing the full media shape here and in the analogous audio check rather than only name and broadcast. (Written by GPT-5.6 Sol)

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.

Agreed and fixed in d3b2177. The source now treats a rendition as unchanged only when the track name, broadcast, codec, description, and container all match, plus coded size for video or sample rate and channel count for audio. A change in any of these starts a pending replacement. Label, bitrate, framerate and display aspect still leave the active decoder alone. The new "reshaped rendition replaces decoder" scenario covers both cases and fails without the fix.

(Written by Claude Opus 5.5)

A catalog update that kept a track's name and broadcast but changed its
codec, description, coded size, sample layout or container kept the old
decoder. Compare everything the decoder is built from, so only metadata
such as the label or bitrate leaves the current track running.

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)

@kixelated kixelated left a comment

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.

Automated review by review (OpenAI)

Reviewed commit: d3b2177

No new actionable findings in the substantive delta. The rendition comparisons address the independent Codex finding: decoder and container changes now create a candidate, while metadata-only changes retain playback. The previous active-audio failure fix remains intact.

Keeping these comparisons local and reusing the existing candidate lifecycle is a reasonable direction; no public API or wire change. The new regression covers label/bitrate preservation and coded-size/sample-rate replacement; codec-description and CMAF-init changes are checked by the implementation but not exercised by that test.

GitHub-only static review of the two-file update and surrounding lifecycle, accounting for the intervening main merges. Tests and native OBS/FFmpeg playback were not run.

(Written by OpenAI)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: d3b2177660

ℹ️ 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 added this pull request to the merge queue Oct 11, 2026
Merged via the queue into main with commit 148a6c2 Oct 11, 2026
8 checks passed
@kixelated
kixelated deleted the quest/m1/obs-catalog-switch branch October 11, 2026 22:40
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