Repository navigation
fix: the OCP assertions wait for the transition instead of sampling once - #219
openvoiceos-bot wants to merge 1 commit into
Conversation
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>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Checking the status... all automated tasks are done! ✅I've aggregated the results of the automated checks for this PR below. 📋 Repo HealthEnsuring the project's documentation is healthy. 📚 ✅ All required files present. Latest Version: ✅ 🔒 Security (pip-audit)I've checked for any hardcoded credentials. 🔑 ✅ No known vulnerabilities found (133 packages scanned). ⚖️ License CheckEverything 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 PreviewComing soon to a stable branch near you! 📽️ Current:
✅ PR title follows conventional commit format. 🚀 Release Channel Compatibility Predicted next version:
🔍 LintBeep boop! Standard processing sub-routine complete. 🦾 ❌ ruff: issues found in 74 file(s) — see job log 📊 CoveragePeeking behind the curtain of your test suite. 🎭 Files below 80% coverage (16 files)
Full report: download the 🔨 Build TestsTesting the integrity of the build artifacts. 🏺 ✅ All versions pass
Keeping the repository healthy and happy. 😊 |
What this changes
Root cause found and proposed by the plugins lane (T-5243). This lane holds
OpenVoiceOS/ovoscope, so the fix lands here.OCPPlayerHarnesstransport methods emit on the bus and return; the playertransitions 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 inmedia.pyshow the pattern is the harness's,not one careless line.
Measured
By plugins, in
ovos-media-plugin-chromecastatorigin/dev:test/directoryAlways the same test, always the first assert after
play(). The middle row iswhat isolates it to the missing wait: no plugin code, no test body, no ordering
changed.
The change
settle_timeout = 2.0andsettle_interval = 0.01are class attributes, so aslow box can raise them and
settle_timeout = 0restores the old single-readbehaviour. One
_eventually(read, ok, describe)helper returns as soon as thevalue 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_stoppedreadsis_playingandis_pausedtogether, as one tuple. A backend that stopsplaying 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 theassertions 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 itneeds no bus or player. 5 of the 7 rows fail on
dev.slow the suite;
value it read. A polling assertion that always passed would be worse than the
flake it replaces;
settle_timeout = 0reads exactly once;says which.
Consumer sweep
Every repository driving
OCPPlayerHarnesswas read:ovos-media,ovos-test-harness,ovos-media-plugin-mass,ovos-audio-plugin-mpvand thechromecast 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
devtoo, for named missing optionalpackages in this venv —
ovos-dinkum-listener(7),ovos_audio(2),ovos-nebulento-pipeline-plugin(3) — none of them code. A full differentialof the sorted failure lists shows none introduced.
ruffonmedia.py: 21 findings before, 21 after. (The first draft of thischange added a
RUF059; it is gone.)Why this matters beyond one test
CI runs
pytest testover the whole chromecast directory, where the flakemeasured 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
OCPPlayerHarnesshas the same exposure.Filed under T-5277, root cause T-5243.
🤖 Generated with Claude Code