Repository navigation
Conversation
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks @hardik4love-lang — this targets a real, well-reproduced defect (#20779) and the core direction is right: an empty or failed codec read must not silently become PCM8, and retrying a transient GATT failure before giving up is the correct shape.
What I verified in app/lib/services/devices/connectors/omi_connection.dart:
- The retry loop (3 attempts, 100ms x attempt backoff) and the removal of the
codecId = 1initialization fix exactly the failure mode the issue describes; pcm8 is now only returned when the characteristic explicitly yields 1. - The new
throw StateError(...)changes the contract ofperformGetAudioCodec()from never-throws to throws-after-retries. I traced every caller: most are safe — the capture coordinator's stage runner (capture_coordinator.dart_pump/ fail-closed path) absorbs the error and fails closed, and storage_sync.dart / ring_storage_sync.dart wrap theirgetAudioCodec()calls in try/catch.
Two call paths are not prepared for the new throw and I'd like them addressed before merge:
-
sdcard_wal_sync.dart —
_getMissingWals()(~line 178) calls_getAudioCodec(deviceId)with no try/catch, and it is reached fromsetDevice()(declaredvoid setDevice(...) async, i.e. async-void) and fromstart(). A StateError there becomes an unhandled async exception on device connect and leaves_walsunpopulated. Please catch it and degrade the same way storage_sync/ring_storage_sync do (skip listing rather than throw). -
capture_controller.dart —
setBackgroundModeEnabled()awaits_getAudioCodec(device.id)(~line 2509) unguarded, and it is called directly from the settings UI (settings_groups.dart_setBackgroundMode). It also sets_preferences.backgroundModeEnabled = truebefore that await, so a throw leaves the in-memory flag enabled while_saveNativeBleStreamConfignever runs. Please guard the read and handle/roll back the failure consistently.
Minor, non-blocking: for an unknown codec id the default: branch still returns pcm8, while the issue's expected behavior says PCM8 should only come from an actual 1. Keeping it is a defensible forward-compat choice, but consider BleAudioCodec.unknown or a more visible log so field reports are traceable.
A small unit test would also be welcome — e.g. a fake transport whose read throws twice then returns 20 (asserts opus), and one that always fails (asserts the StateError and that pcm8 is never returned). test/unit/omi_connection_serial_number_test.dart shows the harness pattern.
Fixing the two unguarded call sites is required; the rest are suggestions. Happy to re-review.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Hi @Git-on-my-level, Thank you for the detailed code review and tracing of all call sites! I have addressed all items:
Ready for re-review! Thank you. |
Dismissed: both blocking concerns from this review (unguarded _getAudioCodec in sdcard_wal_sync.dart _getMissingWals and in capture_controller.dart setBackgroundModeEnabled) and the requested unit tests are resolved on head 70aaa53.
|
Thanks @hardik4love-lang — everything from my earlier review is addressed on this head. Verified per file:
I've dismissed the earlier changes-requested review since both blocking call sites are fixed. One thing remains before merge: no CI checks have run on this head yet, so the new unit suite hasn't executed in CI — the merge decision should wait for a green run. Leaving this for maintainer merge review. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Hi @Git-on-my-level, The PR metadata preflight check is now PASS green (Run 38855454758) with the updated body declarations (- INV-CAP-1 and line-count exception for capture_controller.dart). The branch and test suite are ready for maintainer merge click! Thank you. |
kodjima33
left a comment
There was a problem hiding this comment.
hardik4love-lang (unflagged on this PR) adds retry+explicit failure for BLE codec reads, fixes real issue #20779 (filed by Itaxh1 but third-party pickup, not self-bounty). Scoped, test added, CI in-progress (acceptable). 4/5.
|
Thank you @kodjima33 and @Git-on-my-level for reviewing and merging! Glad to have this critical P1 audio codec stability defect resolved for all pendant users. Bounty Claim Details
|
|
Hi @kodjima33, @josancamon19, Following up on bounty settlement for merged PR #21524 (Issue #20779):
Whenever the batch disbursement runs, please confirm. Thank you! |
What changed and why
Fixes #20779 by introducing retry logic for audio codec reads in OmiDeviceConnection.performGetAudioCodec(), preventing silent fallback to BleAudioCodec.pcm8 on empty data or transient GATT errors, guarding call sites in capture_controller.dart and sdcard_wal_sync.dart, and adding hermetic unit test coverage.
Line-Count-Exception: app/lib/services/capture/capture_controller.dart | 4475 -> 4487 | guard and rollback background mode on audio codec read failure
Product invariants affected
How it was verified
Verified via hermetic Dart unit tests covering retry with exponential backoff on transient errors, decoding of codec IDs (PCM8 and OpusFS320), and StateError throwing on persistent failure/empty payload.
Tests
app/test/unit/omi_connection_audio_codec_test.dart
UI evidence
UI-Evidence: none -- Non-UI BLE protocol and codec retry logic verified via hermetic unit tests.
Failure class (fixes)
Failure-Class: none