Skip to content

fix(python-sdk): BLE listeners hang instead of erroring on device disconnect - #14229

Merged
Git-on-my-level merged 2 commits into
mainfrom
issues-improver/13290-ble-disconnect-hang
Sep 17, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
issues-improver/13290-ble-disconnect-hang

Conversation

@kodjima33

@kodjima33 kodjima33 commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

What / why

omi.ble.listen() and omi.bluetooth.listen_to_omi() waited on a fixed
sleep (asyncio.sleep(3600) / asyncio.sleep(99999)) with no Bleak
disconnected_callback registered. If the peripheral disconnected, a
caller 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_callback on an asyncio.Event,
poll it every 1s instead of sleeping for the full interval, and raise
ConnectionError once the device disconnects so callers can detect
and 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 Opus
    library linking issue in the test venv, reproduces identically on
    unmodified main, unrelated to this change).
  • Added sdks/python/tests/test_ble_disconnect.py: both listeners now
    raise ConnectionError promptly when the disconnect callback fires,
    and listen() is still cleanly cancellable while connected.
  • black --check passes on every line this PR touches (two pre-existing
    over-length lines in ble.py are untouched debt, not from this diff).
  • Note: sdks/python (the device SDK) has no CI workflow wired up today
    python-cli-ci.yml only covers sdks/python-cli. Out of scope for
    this 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).

Review in cubic

…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 Git-on-my-level left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obvious bugfix with tests; CI green on this head. Approving for admin squash.

@Git-on-my-level
Git-on-my-level merged commit d723d7b into main Sep 17, 2026
39 checks passed
@Git-on-my-level
Git-on-my-level deleted the issues-improver/13290-ble-disconnect-hang branch September 17, 2026 05:06
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.

Python BLE listeners remain pending after device disconnection

2 participants