Skip to content

fix: the OCP assertions wait for the transition instead of sampling once - #219

Closed
openvoiceos-bot wants to merge 1 commit into
devfrom
fix/t5277-the-asserts-wait-for-the-transition
Closed

openvoiceos-bot wants to merge 1 commit into
devfrom
fix/t5277-the-asserts-wait-for-the-transition

Conversation

@openvoiceos-bot

Copy link
Copy Markdown
Contributor

What this changes

Root cause found and proposed by the plugins lane (T-5243). This lane holds
OpenVoiceOS/ovoscope, so the fix lands here.

OCPPlayerHarness transport methods emit on the bus and return; the player
transitions on another thread. Every state assertion read once, so a read
taken straight afterwards could land before the transition and report the state
the player had not left yet. "Not yet" and "wrong" are different answers, and
one read cannot tell them apart.

Twelve time.sleep(0.05) calls in media.py show the pattern is the harness's,
not one careless line.

Measured

By plugins, in ovos-media-plugin-chromecast at origin/dev:

failures in 12 runs
unmodified 4
assertion polls, nothing else changed 0
the real fix installed, no local conftest 0
the real fix, whole test/ directory 0

Always the same test, always the first assert after play(). The middle row is
what isolates it to the missing wait: no plugin code, no test body, no ordering
changed.

The change

settle_timeout = 2.0 and settle_interval = 0.01 are class attributes, so a
slow box can raise them and settle_timeout = 0 restores the old single-read
behaviour. One _eventually(read, ok, describe) helper returns as soon as the
value matches — a passing assertion costs one read and the suite does not get
slower — and on timeout raises the message it raised before with the deadline
appended, so a real failure still names the state it actually saw.

Six assertions route through it: assert_player_state, assert_media_state,
assert_backend_playing, assert_backend_paused, assert_backend_stopped,
assert_now_playing_uri.

One thing the proposal did not specify: assert_backend_stopped reads
is_playing and is_paused together, as one tuple. A backend that stops
playing and pauses in the same transition must never look stopped in between,
and two sequential single-condition waits could see exactly that.

The time.sleep(0.05) calls in the transport methods are left alone. With the
assertions polling they are redundant, but removing them is a wider change to a
shared harness and buys 50 ms.

Controls

test/unittests/test_the_asserts_wait.py, driving the helper directly so it
needs no bus or player. 5 of the 7 rows fail on dev.

  • a value already right returns in under 50 ms — a passing assertion must not
    slow the suite;
  • a value that arrives late is re-read, not sampled once;
  • a value that never arrives still fails, after the deadline, naming the
    value it read. A polling assertion that always passed would be worse than the
    flake it replaces;
  • settle_timeout = 0 reads exactly once;
  • a paused backend and a playing backend are each not stopped, and the message
    says which.

Consumer sweep

Every repository driving OCPPlayerHarness was read: ovos-media,
ovos-test-harness, ovos-media-plugin-mass, ovos-audio-plugin-mpv and the
chromecast plugin. None subclasses the harness, and none asserts that an
assertion raises
, so no consumer's behaviour inverts — only a genuinely
failing assertion becomes slower. No signature changed, so no floor pin moves.

Suite

648 passed, 12 failed. All 12 fail on dev too, for named missing optional
packages in this venv — ovos-dinkum-listener (7), ovos_audio (2),
ovos-nebulento-pipeline-plugin (3) — none of them code. A full differential
of the sorted failure lists shows none introduced.

ruff on media.py: 21 findings before, 21 after. (The first draft of this
change added a RUF059; it is gone.)

Why this matters beyond one test

CI runs pytest test over the whole chromecast directory, where the flake
measured 4 in 12 — roughly a third of that repository's PR builds were failing
for reasons unconnected to their diff, and a green build there was partly luck.
Every repository whose tests drive OCPPlayerHarness has the same exposure.

Filed under T-5277, root cause T-5243.

🤖 Generated with Claude Code

Root cause found and proposed by the plugins lane (T-5243). This lane
holds OpenVoiceOS/ovoscope, so the fix lands here.

OCPPlayerHarness transport methods emit on the bus and return; the
player transitions on ANOTHER thread. Every state assertion read once,
so a read taken straight afterwards could land before the transition and
report the state the player had not left yet. "Not yet" and "wrong" are
different answers and one read cannot tell them apart. Twelve
time.sleep(0.05) calls in media.py show the pattern is the harness's,
not one careless line.

Measured by plugins in ovos-media-plugin-chromecast at origin/dev:
4 failures in 12 runs of pytest test/test_backends.py test/test_e2e.py,
always test_play_pause_resume_stop_through_ocp, always the first assert
after play(). Replacing only the assertion through a throwaway conftest
took it to 0 in 12, with no plugin code and no test body changed, which
isolates it to the missing wait. With the real fix installed: 0 in 12 on
that pair and 0 in 12 on the whole directory.

settle_timeout = 2.0 and settle_interval = 0.01 are class attributes, so
a slow box can raise them and settle_timeout = 0 restores the old
single-read behaviour. One _eventually(read, ok, describe) helper returns
as soon as the value matches, so a passing assertion costs one read and
the suite does not get slower; on timeout it raises the message it raised
before with the deadline appended, so a real failure still names the
state it actually saw.

Six assertions route through it: assert_player_state, assert_media_state,
assert_backend_playing, assert_backend_paused, assert_backend_stopped and
assert_now_playing_uri.

assert_backend_stopped reads is_playing and is_paused TOGETHER, as one
tuple, which the proposal did not specify. A backend that stops playing
and pauses in the same transition must never look stopped in between, and
two sequential single-condition waits could see exactly that.

The time.sleep(0.05) calls in the transport methods are left alone. With
the assertions polling they are redundant, but removing them is a wider
change to a shared harness and buys 50 ms.

Controls, in test/unittests/test_the_asserts_wait.py: a value already
right returns in under 50 ms; a value that arrives late is re-read; a
value that NEVER arrives still fails, after the deadline, naming the
value it read — a polling assertion that always passed would be worse
than the flake; settle_timeout = 0 reads exactly once; and a paused or
playing backend is not stopped. 5 of the 7 rows fail on dev.

Consumer sweep before the change: every repository driving
OCPPlayerHarness was read. None subclasses it, and none asserts that an
assertion raises, so no consumer's behaviour inverts — only a genuinely
failing assertion becomes slower. No signature changed, so no floor pin
moves.

Suite: 648 passed, 12 failed, and all 12 fail on dev too, for named
missing optional packages in this venv (ovos-dinkum-listener 7,
ovos_audio 2, ovos-nebulento-pipeline-plugin 3), none of them code.
ruff on media.py: 21 findings before, 21 after.

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

coderabbitai Bot commented Sep 26, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

@github-actions github-actions Bot added the fix label Sep 26, 2026
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Checking the status... all automated tasks are done! ✅

I've aggregated the results of the automated checks for this PR below.

📋 Repo Health

Ensuring the project's documentation is healthy. 📚

✅ All required files present.

Latest Version: 1.11.0a1

✅ ovoscope/version.py — Version file
✅ README.md — README
✅ LICENSE — License file
✅ pyproject.toml — pyproject.toml
⚠️ setup.py — setup.py
✅ CHANGELOG.md — Changelog
✅ ovoscope/version.py has valid version block markers

🔒 Security (pip-audit)

I've checked for any hardcoded credentials. 🔑

✅ No known vulnerabilities found (133 packages scanned).

⚖️ License Check

Everything looks good on the legal front. ✅

✅ No license violations found.

Policy: Apache 2.0 (universal donor). StrongCopyleft / NetworkCopyleft / WeakCopyleft / Other / Error categories fail. MPL allowed.

🏷️ Release Preview

Coming soon to a stable branch near you! 📽️

Current: 1.11.0a1 → Next: 1.11.1a1

Signal Value
Label (none)
PR title fix: the OCP assertions wait for the transition instead of sampling once
Bump build

✅ PR title follows conventional commit format.


🚀 Release Channel Compatibility

Predicted next version: 1.11.1a1

Channel Status Note Current Constraint
Stable ⚪ Not in channel -
Testing ❌ Too new (must be <1.0.0) ovoscope>=0.7.2,<1.0.0
Alpha ✅ Compatible ovoscope>=1.6.15a1

🔍 Lint

Beep boop! Standard processing sub-routine complete. 🦾

❌ ruff: issues found in 74 file(s) — see job log
✅ actionlint: 12 workflow file(s), no finding

📊 Coverage

Peeking behind the curtain of your test suite. 🎭

⚠️ 65.0% total coverage

Files below 80% coverage (16 files)
File Coverage Missing lines
ovoscope/golden_worker.py 0.0% 30
ovoscope/simple_listener.py 0.0% 63
ovoscope/version.py 0.0% 5
ovoscope/classic_listener.py 18.2% 117
ovoscope/intent_cases.py 22.3% 153
ovoscope/pytest_plugin.py 47.0% 210
ovoscope/ocp.py 47.9% 61
ovoscope/cli.py 48.3% 140
ovoscope/tts_intelligibility.py 49.0% 102
ovoscope/e2e.py 57.1% 73
ovoscope/listener.py 57.1% 127
ovoscope/media.py 58.8% 101
ovoscope/voice_loop.py 59.0% 119
ovoscope/audio.py 64.4% 126
ovoscope/__init__.py 66.9% 401
ovoscope/media_provider.py 67.6% 23

Full report: download the coverage-report artifact.

🔨 Build Tests

Testing the integrity of the build artifacts. 🏺

✅ All versions pass

Python Build Install Tests pytest
3.10 ✅ ✅ ✅ 759 passed, 25 skipped, 85 warnings in 245.30s (0:04:05)
3.11 ✅ ✅ ✅ 759 passed, 25 skipped, 85 warnings in 250.30s (0:04:10)
3.12 ✅ ✅ ✅ 759 passed, 25 skipped, 85 warnings in 262.49s (0:04:22)
3.13 ✅ ✅ ✅ 759 passed, 25 skipped, 122 warnings in 256.82s (0:04:16)
3.14 ✅ ✅ ✅ 759 passed, 25 skipped, 122 warnings in 258.14s (0:04:18)

Keeping the repository healthy and happy. 😊

@JarbasAl JarbasAl closed this Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants