Skip to content

fix(studio): start the sources with the engine, so the cue test stops flaking - #225

Merged
kixelated merged 3 commits into
mainfrom
quest/m0/cue-test-flake
Nov 21, 2026
Merged

kixelated merged 3 commits into
mainfrom
quest/m0/cue-test-flake

Conversation

@kixelated

@kixelated kixelated commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Finishes quest/m0/cue-test-flake.md: engine::tests::a_cue_waits_for_take no longer flakes on a loaded runner.

Root cause

Engine::start returned with no source running: State::stale started true, and only the program thread's first tick synced the sources. The test runs in about 150 ms, so when the host starves that thread for longer, controls::sounds finds no running host feed (so no strip) and the palette refuses Mute("host") with "host has no sound". The same race reached any caller, such as the window's first frames or a phone remote.

Changes

  • Engine::sync holds what the program thread did on a stale tick: sync the sources, spawn their drivers, update the recorder, pick the audio.
  • Engine::start calls it once the audio clock runs and before spawning the program thread, and stale starts false. Ordering is unchanged otherwise: the recording line opens and the audio clock starts before the sources do, as before.
  • a_lost_picture_is_reported_once no longer polls for its source to start; it asserts it runs as start returns.

Decisions

  • The engine holds the sources at start, rather than the test waiting for the first sync. A waiting test would only paper over the race for that one test, while every other holder of a fresh engine would still see none running. Reviewers can push back on this and go with the waiting test instead.

Validation

  • Reproduced deterministically: a 2 s sleep before the program thread's first tick made the test fail with the CI message (left: Some("\host` has no sound")). With the fix and the same sleep, it and a_lost_picture_is_reported_once` both pass.
  • Independently, under load: 2x nproc busy loops and --stress-count 30 on lavapipe. Before the fix, 18 passed and 12 failed with the CI message. After the fix, 30 of 30 passed.
  • just render-sw's engine/watch/setup filter: 22 of 22 passed. just ci passed.

Public API

None: Engine::sync is private. No wire impact.

Caused by

  • moq-dev/studio#219 - added the Mute("host") assertion, which assumed the sources were already running before the program thread's first sync (found by check)

Follow-ups

None.

Models

Size: S
Implementer: Claude, claude-opus-5-5, unknown effort (arm A)

🤖 Generated with Claude Code

(Written by Claude Opus 5.5)

Review

Rewritten by quest review after each round.

  • Head: 5b1a73c

  • Base: origin/main at 9291483

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

  • Reviewer: Codex, gpt-6.1-sol, medium effort

  • Session: 01a1fd96-ab6d-7d13-bbc4-edd5ce9d79ff, round 1

  • Score: 9/10, Source initialization completes before Engine::start returns, removing the scheduling race while preserving subsequent synchronization; no actionable defects were found, though builds and tests were not run.

  • Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

  • Reviewer: Codex, gpt-6.1-sol, low effort, shadow

  • Session: 01a1fd96-ab6c-7961-a7ca-bcd4d3f41416, round 1

  • Score: 9/10, The focused source-initialization fix addresses the startup race while preserving frame-driven synchronization, with no actionable defect identified by source inspection; builds and tests were not run.

  • Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

kixelated and others added 2 commits November 21, 2026 02:00
Quest-Claim: 8d6fbcbbe1175ac2
…first frame

The engine synced its sources only on the program thread's first tick, so
a caller of Engine::start could find none running when that thread was
slow to be scheduled, as a_cue_waits_for_take did on a loaded runner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title The cue test passes every time on CI fix(studio): start the sources with the engine, so the cue test stops flaking Nov 21, 2026
@kixelated
kixelated marked this pull request as ready for review November 21, 2026 10:12
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

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: 52bc0e1f-a83f-4213-804c-91152e9bc64b
Commits

Reviewing files that changed from the base of the PR and between 5b1a73c and f2e2803.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Engine::sync now handles collection-source synchronization, recorder updates, source-thread cleanup and driver spawning, and audio-pick updates. Startup calls it before starting the program thread, and the stale-state branch uses it. Initial State.stale is now false. The red source test now checks availability immediately. The cue-test flake document was deleted.

Merge Risk: Minimal · previous review 5b1a7

This change starts sources before Engine::start returns, so callers no longer depend on program-thread scheduling. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: sources now start with the engine, which fixes the flaky cue test. It matches the changeset in engine.rs, where Engine::start now calls a new sync step so sources are …
Description check Passed The description states the root cause, the changes in Engine::start and the new private Engine::sync, the test update, validation runs, and the design decision. It matches the changeset closely.
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: sources now start with the engine, which fixes the flaky cue test. It matches the changeset in engine.rs, where Engine::start now calls a new sync step so sources are running when start returns.

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: 037a5828-be7d-4a63-813c-7c2ed79f44f7
Commits

Reviewing files that changed from the base of the PR and between 9291483 and 5b1a73c.

Files selected for processing: 2

  • quest/m0/cue-test-flake.md
  • rs/moq-studio/src/engine.rs
Files with no reviewable changes: 1

  • quest/m0/cue-test-flake.md

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

@pullfrog pullfrog 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.

✅ No new issues found.

Approach: sound. Moving the first source sync into Engine::start fixes the cause for every holder of a fresh engine, not just the test, and it keeps the existing order: recording line, then audio clock, then sources.

Reviewed changes: I reviewed the extraction of the stale-tick body into Engine::sync, its new call site in start, and the test that now asserts instead of polling.

  • Engine::sync: holds the program thread's former stale-tick body unchanged (sources.sync, recorder.set_sources, spawn drivers into running, pick_audio), with the same state → running lock order.
  • Engine::start: syncs once before spawning the program thread, and stale now starts false. If a later clocked spawn fails, Starting::drop → stop() → state.sources.stop() still ends the newly spawned source threads. The first tick's synced no longer being true is harmless, since air is None at start and going live sets each line's audio through started.
  • a_lost_picture_is_reported_once: now asserts that the red source runs as soon as start returns. This holds because Sources::sync inserts the feeds synchronously.
  • Quest file: quest/m0/cue-test-flake.md is deleted on completion, as the repo convention expects.

ℹ️ One neighbouring comment still says the program clock starts the sources

rs/moq-studio/src/engine.rs:1316-1318 still says the recording line is "opened before the program clock starts the sources". start now does that itself. The order still holds, so only the wording is stale. The PR already rewrote the audio-clock comment a few lines below for the same reason.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@kixelated
kixelated enabled auto-merge (squash) November 21, 2026 15:14
@kixelated
kixelated merged commit 8a667c0 into main Nov 21, 2026
4 checks passed
@kixelated
kixelated deleted the quest/m0/cue-test-flake branch November 21, 2026 15:38
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