Repository navigation
fix(firmware): bound DevKit audio notification chunk size to ATT MTU limit - #13388
gianluca-disanto wants to merge 3 commits into
Conversation
…limit - Define ATT_NOTIFICATION_HEADER_SIZE (3 bytes: opcode 0x1B + 16-bit handle) in devkit transport.c. - Reserve ATT_NOTIFICATION_HEADER_SIZE when calculating packet_size in push_to_gatt(). - Add check_devkit_mtu.py regression test covering 15 boundary MTU test cases with C-seam verification.
There was a problem hiding this comment.
2 issues found across 2 files
Confidence score: 3/5
- In
omi/firmware/scripts/check_devkit_mtu.py, the fallback can validate duplicated Python logic when the C seam is unavailable or fails to compile, allowing a brokenpush_to_gatt()implementation to pass; make seam unavailability a test failure or otherwise fail closed. - The regression script in
omi/firmware/scripts/check_devkit_mtu.pyis not run by CI or repository checks, so future DevKit MTU regressions may ship with all checks green; register it in the firmware check lane and run it locally and in CI.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="omi/firmware/scripts/check_devkit_mtu.py">
<violation number="1" location="omi/firmware/scripts/check_devkit_mtu.py:1">
P2: This regression script is not invoked by any CI or repository check, so future DevKit MTU regressions can ship with all checks green. Register it in the firmware check lane with local and CI execution.</violation>
<violation number="2" location="omi/firmware/scripts/check_devkit_mtu.py:287">
P2: When the C seam is unavailable or fails to compile, this fallback can pass a broken `push_to_gatt()` because it tests duplicated Python logic rather than production code. Make seam unavailability a test failure, or make the fallback validate the extracted production function instead of reimplementing it.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| if c_res >= 0: | ||
| return c_res | ||
|
|
||
| sim_failures = run_behavioral_simulation() |
There was a problem hiding this comment.
P2: When the C seam is unavailable or fails to compile, this fallback can pass a broken push_to_gatt() because it tests duplicated Python logic rather than production code. Make seam unavailability a test failure, or make the fallback validate the extracted production function instead of reimplementing it.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At omi/firmware/scripts/check_devkit_mtu.py, line 287:
<comment>When the C seam is unavailable or fails to compile, this fallback can pass a broken `push_to_gatt()` because it tests duplicated Python logic rather than production code. Make seam unavailability a test failure, or make the fallback validate the extracted production function instead of reimplementing it.</comment>
<file context>
@@ -0,0 +1,291 @@
+ if c_res >= 0:
+ return c_res
+
+ sim_failures = run_behavioral_simulation()
+ return 0 if sim_failures == 0 else 1
+
</file context>
| @@ -0,0 +1,291 @@ | |||
| #!/usr/bin/env python3 | |||
There was a problem hiding this comment.
P2: This regression script is not invoked by any CI or repository check, so future DevKit MTU regressions can ship with all checks green. Register it in the firmware check lane with local and CI execution.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At omi/firmware/scripts/check_devkit_mtu.py, line 1:
<comment>This regression script is not invoked by any CI or repository check, so future DevKit MTU regressions can ship with all checks green. Register it in the firmware check lane with local and CI execution.</comment>
<file context>
@@ -0,0 +1,291 @@
+#!/usr/bin/env python3
+"""Regression test for DevKit BLE audio notification MTU boundary limits.
+
</file context>
…header - Use bt_gatt_get_mtu(conn) in push_to_gatt() to ensure bounds reflect the true negotiated ATT MTU rather than link-layer DLE. - Dynamically generate C seam test cases and assertion counts from authoritative TEST_CASES list in check_devkit_mtu.py. - Prevent silent downgrades on seam compile failures and provide clear fallback diagnostics. - Wire check_devkit_mtu.py into build-cv1.sh CI build script.
|
@cubic-dev-ai All 4 review points addressed in commit a952ae3:
|
@gianluca-disanto All four look genuinely addressed — I don't see a spot left over.
Two minor nits, neither blocking: the tripwire regex is a bit brittle if someone reformats the Tip: get faster answers by chatting with cubic’s review copilot in the review UI |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Thanks @gianluca-disanto — the production fix here is correct, and it's the right diagnosis.
What's right (verified):
current_mtuwas set frominfo.le.data_len->tx_max_len(transport.c:418, :476) — that's the LE Data Length Extension PDU length, not the negotiated ATT MTU. Using it to budget ATT notifications under-reserved the 3-byte ATT header, so constrained-MTU links could hit-EMSGSIZEfrombt_gatt_notify. Bounding chunks bybt_gatt_get_mtu(conn) - ATT_NOTIFICATION_HEADER_SIZE - NET_BUFFER_HEADER_SIZE(transport.c:572-573) is the correct fix, and the API is available in the DevKit toolchain (NCS v2.7.0 → Zephyr v3.6.99;bt_gatt_get_mtusince Zephyr 3.3,gatt.halready included).- The static tripwire correctly fails against pre-fix source and passes on this head.
Blocking: the new CI check breaks the CV1 release build.
I ran check_devkit_mtu.py on this head inside the exact CI image the firmware lane pins (ghcr.io/zephyrproject-rtos/ci:v0.26.13): it exits 1 because the generated C seam never compiles when a C compiler is present:
generate_c_main()buildsprintf("\n%d of ...")from a non-raw f-string, so\nbecomes a literal newline inside the C string literal — guaranteedmissing terminating "error.-Werrorsign-compare fires on the extractedMIN(int, uint32_t)expression.struct bt_conn conn = {0};against the memberless mock struct is an excess-initializer error.
run_c_seam() correctly returns failure on compile errors, so the script exits 1 whenever cc exists — and build-cv1.sh runs it under set -euo pipefail before west build. The next manual CV1 release dispatch would abort at the "Verify DevKit MTU notification limit contract" step. The "15/15 pass on head" in the PR description only holds on the no-compiler fallback path.
Suggested fixes: make the f-string raw (or emit \\n), cast the MIN operands to a common type in the mock prefix, use an uninitialized struct bt_conn conn; or a non-empty mock struct, and add a one-line smoke assertion that the compiled seam binary actually ran (defensive against silently regressing to the fallback path).
Non-blocking notes:
- The DevKit check is wired only into the manual-dispatch CV1 release script; it has no PR-visible audience, and the CV1 build compiles
omi/, notdevkit/. Consider a PR-visible lane (e.g. the checks manifest) so the contract is enforced before a release attempt. - Sibling #13342 adds
check_cv1_mtu.pyto the samebuild-cv1.sh— expect a conflict; sequencing the two PRs would help. - The
current_mtu < MINIMAL_PACKET_SIZEgate at transport.c:723 still uses DLE length; unchanged here, but worth a look in a follow-up since it's the same class of confusion this PR fixes.
Requesting changes only for the CI-gate compile failure — the transport.c change itself looks good. Once the seam compiles and passes on a real toolchain, this needs a maintainer familiar with DevKit BLE behavior to sanity-check on hardware before merge.
Feedback by Omi's AI maintainer assistant on behalf of David — flag disagreements, it learns.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
…mtu.py
- Cast operands in MIN macro to uint32_t to prevent -Werror=sign-compare
- Add member to struct bt_conn mock to allow {0} initialization under C11
- Cast printf arguments to (int) in check_case to satisfy format specifiers
- Escape newline as \n in generate_c_main() to prevent multiline C literal syntax error
- Add smoke assertion that compiled seam binary executes with exit code 0
|
@Git-on-my-level Thanks for the thorough review and for catching the C compiler seam issues in the CI image! I've addressed all blocking points in commit
I tested the seam compilation directly with GCC using |
Dismissed: the blocking concern (C seam compile failures under -Werror in the pinned firmware CI image, which would abort the CV1 release build) is resolved on 9f9f686 — verified by running check_devkit_mtu.py from this head inside ghcr.io/zephyrproject-rtos/ci:v0.26.13: the seam compiles clean and passes 15/15, exit 0.
|
Verified — 9f9f686 resolves everything blocking from my earlier review, and I confirmed it by execution rather than inspection:
Thanks @gianluca-disanto — responsive and precise fix series; the extracted-C-seam pattern is a genuinely useful way to unit-test firmware I/O logic. Left for a maintainer before merge (non-blocking):
The follow-up note from my earlier review also stands, outside this PR's scope: the Feedback by Omi's AI maintainer assistant on behalf of David — flag disagreements, it learns. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Reviewed all three changed files on head
Also confirmed this isn't a duplicate of #13342: that sibling PR (same author) carries the identical fix pattern for the CV1 transport; this PR covers DevKit. The two 300-line check scripts are near-copies — fine for now, but a shared parameterized harness could serve both down the road. The PR is still draft; from a technical standpoint it looks merge-ready once a maintainer signs off on the CI placement question above. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
Reserve ATT_NOTIFICATION_HEADER_SIZE (3 bytes: opcode 0x1B + 16-bit handle) in
omi/firmware/devkit/src/transport.cwhen computing audio packetsize in
push_to_gatt().omi/firmware/scripts/check_devkit_mtu.pyregression test covering 15 boundary MTU cases with C-seam verification.What changed and why
In
omi/firmware/devkit/src/transport.c, line 571 capped packet chunks atcurrent_mtu - NET_BUFFER_HEADER_SIZE. Becausebt_gatt_notifyadds the3-byte ATT notification header, total packet size exceeded
current_mtuunder constrained MTUs, leading to-EMSGSIZEdrops. ReservingATT_NOTIFICATION_HEADER_SIZEensures chunks strictly honor the negotiated MTU budget.Product invariants affected
none
How it was verified
Verified with
omi/firmware/scripts/check_devkit_mtu.py, asserting byte-for-byte buffer reconstruction across 15 boundary cases (including MTU 23and 17/18-byte payloads). 15/15 pass on head; exits 1 against pre-fix source.
Tests
omi/firmware/scripts/check_devkit_mtu.pyFailure class (fixes)
Failure-Class: none