Skip to content

fix(firmware): bound audio notification chunk size to ATT MTU limit - #13342

Merged
Git-on-my-level merged 2 commits into
BasedHardware:mainfrom
gianluca-disanto:fix-cv1-mtu-notification-limit
Nov 8, 2026
Merged

Git-on-my-level merged 2 commits into
BasedHardware:mainfrom
gianluca-disanto:fix-cv1-mtu-notification-limit

Conversation

@gianluca-disanto

@gianluca-disanto gianluca-disanto commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor
  • Reserve ATT_NOTIFICATION_HEADER_SIZE (3 bytes: opcode 0x1B + 16-bit handle) when computing audio packet size in push_to_gatt().

  • Prevent bt_gatt_notify_cb from returning -EMSGSIZE and dropping packets when negotiated current_mtu is small.

  • Add check_cv1_mtu.py regression test script covering 15 MTU test cases with C-seam verification.

  • Update firmware README with ATT MTU notification constraints documentation.

    Fixes CV1 audio transport exceeds ATT notification limit at smaller negotiated MTUs #13265

    What changed and why

    Bounded audio notification chunk size in push_to_gatt() by subtracting ATT_NOTIFICATION_HEADER_SIZE (3 bytes) in addition to
    NET_BUFFER_HEADER_SIZE. Previously, chunks were sized up to current_mtu - 3, causing total ATT packet size (packet_size + 3 + 3) to exceed
    current_mtu at lower MTUs, which triggered -EMSGSIZE (-90) errors and dropped audio frames.

    Product invariants affected

    none

    How it was verified

    Verified via omi/firmware/scripts/check_cv1_mtu.py, which extracts push_to_gatt() from transport.c, compiles it against Zephyr stubs using cc -Wall -Wextra -Werror, and tests 15 MTU boundary cases (including minimum MTU 23 and 17/18-byte audio cases) with byte-exact payload reconstruction
    and semaphore accounting. All 15/15 cases pass.

    Tests

    omi/firmware/scripts/check_cv1_mtu.py (added in this PR and wired into build-cv1.sh).

    Failure class (fixes)

    Failure-Class: none

- Reserve ATT_NOTIFICATION_HEADER_SIZE (3 bytes: opcode 0x1B + 16-bit handle)
  when computing audio packet size in push_to_gatt().
- Prevent bt_gatt_notify_cb from returning -EMSGSIZE and dropping packets
  when negotiated current_mtu is small.
- Add check_cv1_mtu.py regression test script covering 12 MTU test cases.
- Update firmware README with ATT MTU notification constraints documentation.

Fixes BasedHardware#13265

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread omi/firmware/scripts/check_cv1_mtu.py Resolved
Comment thread omi/firmware/scripts/check_cv1_mtu.py Resolved
Comment thread omi/firmware/scripts/check_cv1_mtu.py Resolved
- Add BLE default/minimum ATT MTU 23 boundary cases (0, 17, and 18 audio bytes).
- Compare received payload directly with buffer in assertion (received == buffer)
  to ensure content integrity and ordering.
- Add C production seam execution via compiler if available, with explicit
  source-string static tripwire verification.
- Wire check_cv1_mtu.py into build-cv1.sh firmware CI lane.
- Update total test case count to 15 cases (all passing).
@gianluca-disanto

gianluca-disanto commented Sep 9, 2026 via email

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 9, 2026

Copy link
Copy Markdown

@cubic-dev-ai All 3 review points have been addressed in
│ commit 612aa28:
│
│ 1. Added BLE default/minimum ATT MTU 23 boundary cases
(0,
...

@gianluca-disanto All three points look addressed in commit 612aa28, and the transport.c fix itself is consistent with them:

  • MTU 23 boundary: TEST_CASES now includes (23, 0), (23, 17), and (23, 18) with the payload budget at 23 - 6 = 17, and both the C seam and simulation carry a 15-case count.
  • Content integrity: the success assertion is now received == buffer (simulation) and a memcmp against tx_buffer + RING_BUFFER_HEADER_SIZE (C seam), which catches reordering/duplication/corruption, not just length.
  • Real C path + CI wiring: run_c_seam() extracts the actual push_to_gatt() from transport.c, compiles it with cc -Wall -Wextra -Werror, and the script is invoked from build-cv1.sh, with verify_source_tripwire() as the explicit static fallback.

Two small caveats to keep an eye on, neither blocking:

  1. The C seam drive pattern (source.index("static bool push_to_gatt...") → next #define OPUS_PREFIX_LENGTH) assumes the whole function is contiguous and defines nothing the function body references that the stub prefix lacks. If a future commit pulls a helper into the middle or the function calls into other transport.c symbols, the compile fails and the script silently falls back to run_behavioral_simulation() (via the -1 return path in main). That fallback still validates the contract via the tripwire + Python model, but it no longer guarantees line 1 of your commit message ("regression test" of real code). Consider making a failed C seam compile a hard error (or at least a printed warning that the production path was not exercised) so CI can't quietly downgrade.
  2. The README step says python scripts/check_cv1_mtu.py but the CI lane runs it with an explicit transport.c argument; the default path in the script is absolute-derived from __file__ so both work — just confirming the paths line up, which they appear to.

No remaining action needed from me on the three original issues.

Tip: get faster answers by chatting with cubic’s review copilot in the review UI

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified end to end — the diagnosis and the fix are correct, and the regression coverage is real. Nice first contribution, and thanks for picking up the earlier review feedback so precisely in 612aa28.

omi/firmware/omi/src/lib/core/transport.c — the fix is exactly right. push_to_gatt() submits .len = packet_size + NET_BUFFER_HEADER_SIZE (line 1101), so the old cap current_mtu - NET_BUFFER_HEADER_SIZE could emit a notification of the full current_mtu bytes while the ATT notification value limit is current_mtu - 3 (1-byte opcode 0x1B + 2-byte handle) — at the minimum supported MTU 100, any frame over 94 bytes was rejected with -EMSGSIZE and dropped after 3 retries. Reserving ATT_NOTIFICATION_HEADER_SIZE on top of the existing header lands the worst case exactly on the limit. Edges check out: both call sites gate on current_mtu >= MINIMAL_PACKET_SIZE (100, config.h), so the chunk budget never goes zero/negative, and pusher_temp_data[517] still fits the largest possible notification (514 bytes at MTU 517).

omi/firmware/scripts/check_cv1_mtu.py — genuine behavioral coverage, not a string tripwire. It extracts the production push_to_gatt(), compiles it with cc -Wall -Wextra -Werror against Zephyr stubs, and asserts byte-exact payload reconstruction, chunk counts, semaphore balance, sequence rollover, and the retry-exhaustion path across 15 cases including the MTU-23 boundaries (17/18 bytes). I ran it in an isolated container: 15/15 pass on this head; it exits 1 against the pre-fix source, and when I tampered the reserve to zero (which the regex tripwire alone would miss) it still fails 6/15 behaviorally — so the guard really would catch a regression.

omi/firmware/scripts/ci/build-cv1.sh — wiring is correct ($FW-relative paths resolve; set -euo pipefail aborts the build before west init if the check fails). One reach caveat for maintainers: firmware_release.yml is workflow_dispatch-only, so this check never runs on PRs — it only fires on a manually dispatched firmware build. That matches the repo's manual firmware-release posture, but it means the guard can't block a bad merge on its own.

omi/firmware/readme.md — accurate and appropriately narrow: the documented current_mtu - 6 budget matches the code, opcode 0x1B is correct, and it points at the verification script.

Non-blocking notes:

  • If the C-seam compile ever fails (e.g. a future refactor moves a helper between push_to_gatt and #define OPUS_PREFIX_LENGTH), run_c_seam() returns -1 and the script silently falls back to the Python simulation, which re-implements the chunking rather than exercising the production C — CI wouldn't notice the downgrade. Making a failed seam compile loud (or fatal) would keep the guard honest; leaving it is defensible since the tripwire still pins the source contract.
  • The devkit firmware still has the unfixed pattern (omi/firmware/devkit/src/transport.c line 571 caps at current_mtu - NET_BUFFER_HEADER_SIZE). Out of scope per CV1 audio transport exceeds ATT notification limit at smaller negotiated MTUs #13265, but a small follow-up issue would be cheap.
  • Two description nits: the PR body says "12 MTU test cases" but the suite now carries 15 after the feedback commit, and the template's Verification/Tests sections are unfilled — worth a quick fill-in since reviewers read those first.

Since no automated lane builds the CV1 firmware on PRs, this still needs a maintainer-dispatched NCS build (and ideally a quick on-device audio check at a small negotiated MTU) before merge.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution needs-maintainer-review Needs a human maintainer to sign off before merge firmware firmware work labels Sep 9, 2026
@gianluca-disanto

Copy link
Copy Markdown
Contributor Author

Thanks @Git-on-my-level for the thorough review and container verification!

I've updated the PR description with the filled Verification and Tests sections. Standing by for the maintainer build, and happy to open a follow-up for the devkit transport if that would be helpful.

@Git-on-my-level

Copy link
Copy Markdown
Member

Follow-up verification pass on the current head (612aa28), checked against today's main:

  • The fix is still missing on main: push_to_gatt() there computes packet_size = MIN(current_mtu - NET_BUFFER_HEADER_SIZE, ...) and then submits .len = packet_size + NET_BUFFER_HEADER_SIZE — i.e. up to the full ATT MTU — while the notification value limit is current_mtu - ATT_NOTIFICATION_HEADER_SIZE. Reserving the 3-byte ATT header (opcode 0x1B + 2-byte handle) lands the worst case exactly on the limit. Edge cases check out: both call sites gate on MINIMAL_PACKET_SIZE (100, config.h), so the new budget (current_mtu - 6, minimum 94) can never underflow, and pusher_temp_data[517] still covers the MTU-517 worst case (514-byte notification).
  • omi/firmware/scripts/check_cv1_mtu.py — inspected the full script: no network access and no environment/secret reads; it only shells out to the local C compiler on code extracted from transport.c. One small caveat worth a follow-up: if the C extraction seam ever fails to compile (e.g. push_to_gatt() grows a dependency on another transport.c symbol), run_c_seam() returns -1 and the script silently falls back to the Python behavioral simulation, which re-implements the chunk calculation instead of exercising the real C path. In CI (build-cv1.sh) that fallback should be loud — or absent — so a regressed extraction can't mask a real break.
  • omi/firmware/readme.md — the two added bullets match the code: the current_mtu - 6 total budget and the python scripts/check_cv1_mtu.py invocation both agree with the implementation and CI wiring.

Issue #13265 is still open and this is its fix. The remaining steps are procedural: the PR is still in draft, and no CI ran on this head — once it's marked ready-for-review, it needs a maintainer sign-off on the CV1 firmware build pipeline. Thanks again for the precise turnaround on the earlier review points.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level
Git-on-my-level merged commit 5f6956f into BasedHardware:main Nov 8, 2026
Git-on-my-level added a commit that referenced this pull request Nov 8, 2026
<!-- claude-projects-attribution: {"github_login":"Git-on-my-level"} -->
_Requested by **David**_

## Status 2026-11-08: verified, ready for release review

All the pre-release gates listed further down have passed. The one left
is David's go. After that, the rollout coordinator handles a staged OTA.

- **Field path proven:** 3.0.21 to 3.0.23 over BLE OTA, on the jig
running the factory 3.0.8 bootloader (the bootloader shipped units
have). Slot1 went to pending+permanent, and after reset slot0 ran the
new image, active and confirmed, with DIS reporting 3.0.23. An earlier
install from an RC start image also passed.
- **Safe mode:** the bench check and all four fault proofs (hard fault,
driver hang, settings hang, watchdog starvation) passed on 6a09d7c. Same
code hash as this head.
- **Host and CI:** firmware host suites, the OTA slot geometry check and
preflight pass. All required CI checks are green. The two red `Analyze`
jobs are CodeQL failing at the SARIF upload step with no alerts. They
aren't required checks and GitHub won't rerun them.
- **Why there is no separate 3.0.22:** safe mode was going to ship alone
as 3.0.22. Its OTA was never proven, because the jig's stock MCUboot
lacks the Omi SD init and erased slot1. Once the jig had the factory
bootloader, the full candidate was proven instead, so safe mode ships
inside 3.0.23.
- **Known telemetry gap:** the boot record decides the update outcome
from the DIS string plus the MCUboot header version, which is 0.0.0 on
every image. So a field unit's first 3.0.23 boot reports UNKNOWN, and a
same-version reinstall reports NOT_INSTALLED. The app's post-reset hash
check stays the authority. A follow-up will switch to image-hash
identity.
- **Still not measured on hardware:** current draw, charger behavior,
and storage after power loss.

Evidence:
`data/run-2026-11-07-cv1-rc/factory-bootloader-install-proof.md` in the
workspace repo. Bench tooling: #24813.

## Update 2026-11-07: safe-mode SD fix, boot telemetry, pinned flash
layout

Four commits on top of the 11-04 head:

- `7a7a6aaa9dd` Safe mode now brings up the SD card before anything
reads the NOR on the shared SPI3 bus. Without that, an uninitialized SD
card drives MISO and corrupts NOR reads. Also adds the persisted boot
record, the saved update outcome, and storage health counters (NOR
read-check failures, SD init failures). These are telemetry items 4-6.
Recovery characteristic `19B10042` moves to v2 (96 bytes, same 16-byte
prefix, version byte 2). `19B10041` is unchanged.
- `481bab7ead1` Docs: `docs/verification/2026-11-07-boot-telemetry.md`,
GATT map.
- `44180c0060a` Hang guard: if SD init hangs and the watchdog fires,
later SAFE boots skip SD init and count a failure instead of looping.
- `6a09d7cbbe5` Pins the app, littlefs, settings and EMPTY_0 partitions
in `boards/omi/pm_static.yml` to the fielded 3.0.21 map. The partition
manager orders the "before: end" partitions in a Python set, so without
the pin the layout depended on the hash seed.
`tests/check_ota_slot_geometry.py` now asserts the pinned map.

Bench evidence on the jig (6a09d7c): the bench check passed, and so did
all four fault proofs (hard fault, driver hang, settings hang, watchdog
starvation). ALL OK at 2026-11-06T22:18:12Z. The jig was restored to
3.0.21 afterwards.

Since proven (see Status above): the jig now runs the factory 3.0.8
bootloader, and a real 3.0.21 to 3.0.23 BLE install passed.

## 3.0.23: merged with safe mode (update 2026-11-04)

This head merges `origin/main` into the backlog candidate. Main now
carries CV1 safe mode (#24505) and its interrupted-update retry fix
(#24514). The version is bumped to **3.0.23**. The original plan was to
ship safe mode alone first, as 3.0.22. That was dropped, and safe mode
ships inside 3.0.23 (see Status above).

- `safe_mode.c`, the retained record layout, the app overlay and the
development-only fault guard match main exactly.
- The replacement SD host joins deferred initialization. The backlog
shutdown worker starts only in normal mode, so SAFE still skips all
application startup.
- **Diagnostics:** the service is registered once, after storage.
`19B10041` keeps the 25-byte telemetry the shipped app parses. Safe
mode's 16-byte recovery state moves to `19B10042`. SAFE exposes only
`42` and Zephyr's static recovery services. `gatt-map.md` matches the
code.
- The merge had seven conflicts: gatt-map, CMakeLists, Kconfig,
diagnostics.h, transport.c, main.c and settings.c. Both sides' behavior
is kept.
- Verified: the host firmware suite and backlog regressions pass, and
preflight passes all 37 checks. Native simulation was skipped because no
Docker daemon was available on the build host.
- **Before any release** (all done except David's go, 2026-11-08):
  - An independent review of the merge.
  - A build-only CI image of this exact head.
  - A normal-mode jig cycle.
  - All four safe-mode fault proofs, rerun on this image.
  - An app DFU to the jig in SAFE.
  - David's go.

## What changed and why

Release candidate for the next CV1 firmware. It combines separately
written PRs so they can be tested together, and fixes what only showed
up once they were combined.

| PR | Author | What it brings |
|---|---|---|
| #24381 (#24137, #19469) | @rgr4y, David | Compiler warning cleanup,
Opus size check, BLE device diagnostics |
| #20450 | David | Ring custody: audio is kept when connected but not
subscribed, and reclaimed only after the phone confirms it |
| #14293 | @apoorvdarshan | Mute survives disconnect and reboot |
| #22659 | @esixce | SD CMD12 reply fix |
| #19719 | David | Per-unit serial number over DIS |
| #13342 | @gianluca-disanto | Audio chunks bounded to ATT MTU |
| #20483 (battery part only) | David | Battery percent doesn't jump on
the charger, and reads correctly after unplugging |
| #23735 (adapted) | @ducanh3005 | BLE power control: resume, pause
capture, power off |
| #23743 (firmware part) | @ducanh3005 | A user-set device name that
persists and advertises |

Also adds `omi/firmware/docs/gatt-map.md`, which assigns each
characteristic UUID to one owner so open PRs stop colliding.

David chose #20450 as the retention fix, accepting that going back to
older firmware loses unsynced audio on the pendant. Release and OTA
publication still need David's go.

**Fixes made on top of the merges:**
- Queued audio could still reach the phone after a mute. A mute now
stops it before sending.
- An unreadable stored mute setting fell back to unmuted, which could
resume capture after a reboot. It now stays muted until an explicit
unmute rewrites the setting. The tradeoff is that a corrupted setting
pauses capture rather than risking recording a user who paused. The app
reads this state back.
- Failed batch media syncs now count as storage errors in diagnostics.
- `check_cv1_mtu.py` passed on its fallback simulation when its compile
failed. A compile failure now fails the check, and only a missing
compiler falls back.
- New `check_ota_slot_geometry.py` keeps OTA slots at the addresses in
every recorded baseline build. It fails on #13855's map.

**Changes from the original PRs:**
- #20483 keeps only the battery fix. Its new diagnostics characteristic
is out, because the existing 25-byte diagnostics packet already covers
this. Diagnostics now report the uncorrected ADC voltage, while critical
shutdown still uses the corrected one.
- #23735 moves from UUID `19B10014` to the allocated `19B10016`, and
from feature bit 9 to bit 11. Pause now uses the same persistent mute as
`19B10015`, so a disconnect or AAD wake can't clear it. Sampling may
continue while paused, with sending and storage both stopped, so this
pause doesn't promise a power saving. A write acknowledges that shutdown
was queued, not that it finished.

- #23743 keeps only the firmware. Its app changes don't apply on this
base, so no app can set a name yet. A name now loads only from a
complete NVS record, and Bluetooth RX can't change it during an
advertising update. A new name takes effect after disconnect, because
advertising is off while connected. The name also moves from the
advertising packet to the scan response, so a passive scanner won't see
it.

**Left out:** #13855, merged and then reverted here. It shrinks both OTA
slots from `0xf0000` to `0xe8000` and moves external network staging and
settings. MCUboot compiles its slot addresses in and OTA doesn't replace
it, while mcumgr uses the app's map. So from reading the design, an app
on that map would write later images and upgrade trailers where the
installed bootloader doesn't look, and OTAs would stop applying.
Settings would also move from `0xfc000`, losing bonds and mute on
update. This hasn't been reproduced on hardware. Generated baseline
builds already end the app at `0xf6000`, below littlefs and settings, so
#5400 needs a fix that keeps the slots where they are.

Also left out: #12102, because #20450 already keeps audio when the clock
is untrusted and its test doesn't link on this branch. Also #14156, held
because it keeps the mic on while connected and that battery cost hasn't
been measured, and #20838 (the retention alternative), #12943 and
#14240.

## Product invariants affected

- INV-CAP-1

This changes what happens to audio while connected but not subscribed,
which is the invariant's main case. Custody host harnesses pass, and the
RC ran on hardware through BLE install and safe-mode fault proofs.

## How it was verified

At `2810eaf`, this head, from a clean clone on the bench Mac, with no
device access:

- `quick-host` and `compile-only` against pinned NCS 2.9.0 pass.
- Host regressions and the OTA slot geometry check pass. The geometry
check also fails on #13855's map, as intended.
- The mute test passes, including new cases for an unreadable setting.
- Custody `make run` passes: `sd_card` and `storage` harnesses report 0
failures.
- The MTU check passes 15 of 15 on the production C seam.

An independent review covered how the merged PRs interact; its three
findings are fixed above. It was a static read and ran no tests.

At the merge of #20483, #23735 and #23743, on the bare CV1 board on the
jig: one app-only cycle passed. The exact image CI built at `07f3866`,
this head, also passed one (build-only run 41523746903, nothing
published). It flashed and verified this image, ran the 30-second boot
check, then restored and verified baseline 3.0.21. The generated slot
map matches the baseline. The same cycle also passed at `2810eaf`. It
proves the image boots and the board can be restored, and nothing about
BLE or audio. Host tests for all three additions pass, and their merge
compiles, links and signs for the real target.

**Not verified at that point (11-04):** anything on hardware beyond that
boot. BLE, GATT, OTA and safe-mode recovery have since been verified
(see Status above). Still open: the new power-off path, renaming,
charger behavior, storage after power loss, the v1 to v2 media upgrade,
and current draw. Going back to pre-#20450 firmware orphans unsynced
audio on the pendant.

## Tests

`omi/firmware/omi/tests/`: custody, `sd_card`, `storage`, capture mute,
OTA slot geometry and host regressions, plus
`omi/firmware/scripts/check_cv1_mtu.py`.

## Failure class

Carried from #14293, which brings these app changes:

Failure-Class: new
Failure-Class-ID: FC-device-mute-cleared-on-disconnect
Line-Count-Exception: app/lib/services/capture/capture_controller.dart |
4609 -> 4670 | Keep durable pendant mute confirmation in the existing
capture owner; unrelated ownership extraction is outside this privacy
fix.
Line-Count-Exception: app/lib/services/capture/capture_coordinator.dart
| 2964 -> 3017 | Confirm device mute before local policy and restore
winning hardware intent on supersession in the existing serialized
owner.

## UI evidence

UI-Evidence: none -- firmware only; the app changes come from #14293 and
aren't exercised in this PR's verification

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

firmware firmware work needs-maintainer-review Needs a human maintainer to sign off before merge positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CV1 audio transport exceeds ATT notification limit at smaller negotiated MTUs

2 participants