fix(python-sdk): BLE listeners hang instead of erroring on device disconnect - #14229
Merged
Merged
Conversation
…connect omi.ble.listen() and omi.bluetooth.listen_to_omi() waited on a fixed sleep (3600s / 99999s) with no Bleak disconnected_callback registered. A caller awaiting the listener got no terminal signal when the peripheral disconnected — it just hung until the sleep timed out. Wire disconnected_callback to an asyncio.Event and poll it every 1s instead of sleeping for the full interval, then raise ConnectionError once the device disconnects so callers can detect and react to it. fixes #13290
Guard artifact for the BLE listener disconnect fix: sdks/python's listen() and listen_to_omi() previously blocked on a fixed sleep with no Bleak disconnected_callback wired, so a real disconnect produced no terminal signal for the caller.
Git-on-my-level
approved these changes
Sep 17, 2026
Git-on-my-level
left a comment
Collaborator
There was a problem hiding this comment.
Obvious bugfix with tests; CI green on this head. Approving for admin squash.
Git-on-my-level
deleted the
issues-improver/13290-ble-disconnect-hang
branch
September 17, 2026 05:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / why
omi.ble.listen()andomi.bluetooth.listen_to_omi()waited on a fixedsleep (
asyncio.sleep(3600)/asyncio.sleep(99999)) with no Bleakdisconnected_callbackregistered. If the peripheral disconnected, acaller awaiting the listener got no terminal signal — the high-level
listener hung indefinitely (next wake at the top of the hour) and the
legacy listener hung until its ~27.7-hour sleep elapsed.
Fix: register Bleak's
disconnected_callbackon anasyncio.Event,poll it every 1s instead of sleeping for the full interval, and raise
ConnectionErroronce the device disconnects so callers can detectand react to it (e.g. reconnect).
Evidence
Issue #13290 reproduced this offline against the real SDK functions
with a simulated Bleak client (two disconnect timeouts before the fix).
I independently re-verified against current source rather than trusting
the issue's pasted patch, and wrote my own fix + tests.
What I tested
pytest sdks/python/tests/— 43 passed, 1 pre-existing failure(
test_decoder_short_packet_if_opuslib_available, a native Opuslibrary linking issue in the test venv, reproduces identically on
unmodified
main, unrelated to this change).sdks/python/tests/test_ble_disconnect.py: both listeners nowraise
ConnectionErrorpromptly when the disconnect callback fires,and
listen()is still cleanly cancellable while connected.black --checkpasses on every line this PR touches (two pre-existingover-length lines in
ble.pyare untouched debt, not from this diff).sdks/python(the device SDK) has no CI workflow wired up today—
python-cli-ci.ymlonly coverssdks/python-cli. Out of scope forthis fix; verified locally only.
BLE — not merged
This touches BLE/GATT connection lifecycle, so per this repo's contribution
norms I'm not merging it myself. @TuEmb @mdmohsin7 — could one of you review
and merge?
Failure-Class: new
Product invariants: none
fixes #13290
Auto-generated from issue feedback by the mini issues-improver — tested and NOT auto-merged (BLE exception, needs BLE-owner review).