Skip to content

test: Capture every tick a scene audio toggle may land in - #1852

Merged
zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:fix/scene-audio-test-flake-2
Oct 23, 2026
Merged

zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:fix/scene-audio-test-flake-2

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Refs #1834

What and why

test_scene_audio_actions (#1815) still failed now and then on a loaded machine after #1835: show_over_other_item once against hybrid libobs and hide_over_other_item once against libobs (C backend). Both times the change was on sample 0, and no tone had been left out of any tick the test captured. The case ran fine alone most of the time, but not every time.

  • The audio thread renders a tick one tick plus the audio buffering after that tick's time. When a source's audio comes late, libobs adds buffering (dynamic by default, up to 960 ms). After that, the ticks rendered right after obs_sceneitem_set_visible() can have times well before the call.
  • test: Retry a scene audio toggle when a tone's audio came late for a tick #1835's capture only took ticks with a time from four ticks before the call. So ticks rendered after the call with older times were never seen. If libobs left the scene's tones out of one of them, the scene had no audio there, and scene_audio_render() applied the queued action at once (process_all_audio_actions()). Every captured tick then read the new level from sample 0.
  • A local diagnostic (not committed) logged the tick times of each audio callback, every scene_audio_render() while an action was queued (the scene's time, each item's audio_pending and audio time, and whether the action was placed or applied at once), and each captured tick's flags. A switch in the test also made the tones' threads late by a set amount (fault injection). With the tones late long enough for libobs to add about 300 ms of buffering, and then late for 420 ms again, starting 250 ms before the call, master's test failed in 16 of 16 runs, always hide_over_other_item with "changed at sample 0 ... allowed none". The log shows the action applied at once in a tick whose time was 260 ms before the call, rendered after it, with both tones pending and the tick outside the capture.
  • There is a second way the capture can miss a tick: when libobs adds buffering, it renders the ticks it adds but doesn't deliver them (audio_callback() returns false), so the raw callback never sees them. An action applied at once in one of those would look the same.
  • The change: the capture takes every tick rendered after it starts, whatever its time. It also records whether the scene itself had no audio in a tick, and when the action had been applied. A toggle is undone and tried again when a tone was left out of any captured tick, or the scene was while it still had audio to play. After hide_only_item's hide, the scene has no audio because its only item is hidden, so that doesn't count.
  • The test also sets fixed audio buffering, about 200 ms (obs_reset_audio2()). libobs then adds all of it on the first tick, before any case runs, and never again, so no undelivered ticks happen during a case. The tones' threads can now be up to about 200 ms late before their audio is left out. Most of the earlier retries came from tones only a little late, and those are gone too.
  • Neither a libobs bug nor a libobs change: in each failure, the tick that applied the action at once had no audio from any visible item. No change landed on sample 0 in a tick that had all its audio. That apply-all path is characterized in libobs: Move the scene item visibility audio ramp into obs-scene-audio-actions.c #1815, not endorsed.

Test expectation change (maintainer sign-off): a toggle is now also tried again when the scene's own audio was pending (left out) in a captured tick before its action was applied, or in any captured tick when the scene should still have audio after the change. The capture also checks ticks rendered after the call whose times are before it (they used to be skipped). The test now runs libobs with fixed audio buffering of about 200 ms instead of the dynamic default. Every check is the same: each sample, contiguous ticks, the sample the call maps to, and the references. They run on a try where every tick rendered while the action waited had all its audio. The test can't pass without such a try: if every try until the existing deadline has one of these ticks, it fails and says so.

Headless: private Xvfb with -noreset, private D-Bus, fresh HOME. "Under load" means 8 runs at a time per library, with all three libraries running together, 16 busy loops pinned one per CPU, and a full parallel build (ninja -j16, no ccache) of a separate tree; load average 30 to 37. The second batch of 96 had the busy loops but no build. After the rebase, 8 runs per library, 4 at a time, as a check.

Build Library Under load Idle
master 72a5b5f + diagnostic all three 0 of 1,776 (busy loops or build load; 4 to 8% of toggles retried). One more run crashed in startup before any case (hybrid); see below
master 72a5b5f + diagnostic, tones made late before the call libobs 16 of 16 failed
This branch + the same injection (4 settings) libobs 0 of 64 (every first try retried)
This branch libobs, C backend 0 of 240, then 0 of 96 (and 8 of 8 passed after the rebase) 0 of 16
This branch hybrid libobs 0 of 240, then 0 of 96 (and 8 of 8 passed after the rebase) 0 of 16
This branch libobs-c-reference 0 of 240, then 0 of 96 (and 8 of 8 passed after the rebase) 0 of 16

With fixed buffering, no try needed a retry in those runs under load; the retry path ran in the injected runs. The one crash: a segfault in group_setup() (after the audio reset, before the first case) in 1 of 720 runs of the diagnostic build against hybrid libobs under load, no core kept. It is not in the code this PR touches and I haven't reproduced it.

Mutants: each one was built into libobs (C backend), and the test from master and this branch's test each ran against it 3 times:

RED → GREEN

  • RED commit: N/A, a focused flaky-test fix with RED and GREEN together. The failure under natural load is rare, so the RED is the local fault injection above: master's test failed 16 of 16 runs, with the libobs state of each failure from the diagnostic.
  • GREEN: c698be7. test_scene_audio_actions 4/4 in every run above, against all three libraries: 0 failures in 1,008 runs under load and 48 idle. uv run ci/local_gate.py --lane lint: ok.
  • Real app (UI, protocol output or logging changes): N/A, test-only change.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

test_scene_audio_actions still failed now and then on a loaded machine
after obs-rust#1835, with a change on sample 0 and no tone left out of any
captured tick.

The audio thread renders a tick one tick plus the audio buffering after
the tick's time. libobs adds buffering when a source's audio comes late,
so after a late tone the ticks rendered right after the call can have
times well before it. The capture only took ticks from four ticks before
the call, so it did not see them. If a tone was left out of one of them,
the scene had no audio and libobs applied the action at once there, and
every captured tick read the new level from sample 0.

The capture now takes every tick rendered after it starts, whatever its
time, and also records whether the scene itself had no audio in a tick:
a toggle is tried again when a tone was left out of any of them, or the
scene was while it still had audio to play. libobs also renders ticks it
adds as buffering without delivering them, which the raw callback can't
see, so the test sets fixed buffering (about 200 ms): libobs adds all of
it on the first tick, before any case, and never again.

Refs obs-rust#1834
@rdoupe
rdoupe requested a review from zackees as a code owner October 23, 2026 00:52
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
Merged via the queue into obs-rust:master with commit 4e430ae Oct 23, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants