Skip to content

feat(firmware): add idle sleep and BLE device controls - #10604

Draft
undivisible wants to merge 20 commits into
mainfrom
codex/firmware-idle-auto-sleep
Draft

undivisible wants to merge 20 commits into
mainfrom
codex/firmware-idle-auto-sleep

Conversation

@undivisible

@undivisible undivisible commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • add BLE-controlled sleep and persistent device naming, both behind an encrypted link
  • ship idle auto-sleep and the capture / low-battery LED patterns as opt-in Kconfig, disabled in omi.conf
  • ref-count current_connection behind get_current_connection() across all call sites
  • expose validated sleep and device-name controls to the mobile transport layer

Review round: changes requested

  • BLE sleep (19B10014), capture-state (19B10015), and device-name (19B10016) now use BT_GATT_PERM_*_ENCRYPT; an unpaired central can no longer power off or rename the pendant.
  • Idle auto-sleep no longer decides from charging || audio_subscribed alone. The policy moved to omi/firmware/omi/src/lib/core/idle_sleep.h: a storage sync transfer is activity, and any build that can capture offline never auto-sleeps, because the firmware cannot distinguish an idle pendant from one recording to SD. OMI_ENABLE_IDLE_SLEEP now depends on !OMI_ENABLE_OFFLINE_STORAGE.
  • Idle auto-sleep and both new LED patterns are disabled in omi.conf, so the shipping build's LED language and power behavior are unchanged; the LED language is documented next to set_led_state().
  • Capture flag is cleared on disconnect (no link means no audio subscription).
  • The device name is back in the primary advertisement (shortened when it does not fit the 31-byte payload) with the complete name in scan response, so passive scanners still see a name.

Status update — 2026-09-26 (revive)

What this does, in plain terms: three opt-in firmware features — auto-sleep when the pendant is idle, a BLE "sleep now" command, and renaming the pendant from the app — plus two optional LED indicators (capture state, low battery). Everything ships disabled: omi.conf keeps the current behavior byte-for-byte until maintainers flip a Kconfig flag in a release. For users this means multi-day battery life becomes possible and lost/renamed pendants become manageable, with zero behavior change until product opts in.

  • Dependency void: fix(firmware): make CV1 capture durable and 3.2× faster on iPhone #10572 was closed unmerged on Aug 21 ("experimental CV1/storage-first branch"; the surviving firmware reliability work is fix(firmware): keep CV1 capture reliable across silence and SD faults #11578, also closed). Verified there is no compile-time coupling: OMI_ENABLE_OFFLINE_STORAGE exists in main's Kconfig, OMI_ENABLE_IDLE_SLEEP depends on !OMI_ENABLE_OFFLINE_STORAGE holds against it, and the idle-sleep host tests pass on the merged tree.
  • Up to date with main: merged main into the branch (merge commit b68d860a84). Upstream drift on transport.c, main.c, settings.c and the app connector since this branch diverged: zero files, so the review rounds of Aug 4–19 remain valid for the code as-is. Single textual conflict was .github/checks-manifest.yaml (both sides added test entries at the same spot; both kept).
  • Re-verified on the merged head: bash omi/firmware/omi/tests/run_idle_sleep_test.sh → passed; clang-format --dry-run -Werror clean on all touched C files; checks-manifest parses with no duplicate ids.
  • Still required before merge (unchanged from prior rounds): maintainer re-review of the current head (the Aug 9 CHANGES_REQUESTED predates the Aug 18 fixes that Git-on-my-level confirmed on 11aa7b5687), NCS 2.9.0 compile, and hands-on hardware QA. CI runs the app tests and the firmware host tests on this push.

Validation

  • bash omi/firmware/omi/tests/run_idle_sleep_test.sh -> idle-sleep policy tests passed; mutation-verified (dropping the offline-capture guard fails 2 assertions).
  • Registered as firmware-idle-sleep-tests in .github/checks-manifest.yaml (local + ci lanes).
  • make preflight run locally on this head.
  • Earlier rounds: mobile analyzer/tests and Android compile smoke, NCS 2.9.0 signed dual-image CV1 build, BabbleSim run 30183037698, real CV1 HW5 OTA/rename/capture/reset checks.

Not verified on this head: no NCS toolchain or CV1 hardware was available for this review round, so the firmware was not compiled or flashed here. Physical system-off/wake, encrypted-link pairing behavior for the new characteristics, charger readings, and LED electrical output need hands-on maintainer QA.

Failure-Class: none

@undivisible
undivisible force-pushed the codex/firmware-idle-auto-sleep branch 2 times, most recently from 11505a9 to 9a9cfd0 Compare July 26, 2026 01:56
@Git-on-my-level Git-on-my-level added security-review Touches auth, provider routing, secrets, or security-sensitive surfaces needs-maintainer-review Needs a human maintainer to sign off before merge labels Jul 26, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for pushing this forward. The battery/power-control direction is useful, and the PR already includes good validation notes plus mobile coverage for the new transport methods.

I do see one blocker before this should move out of draft / toward merge:

  • The new BLE control characteristics use plain BT_GATT_PERM_WRITE / BT_GATT_PERM_READ | BT_GATT_PERM_WRITE for sleep, capture state, and persisted device name. With the current permissions, a nearby BLE client that can connect can issue a system-off command or persistently rename the device without an encrypted/authenticated link. For sleep in particular, that is a denial-of-service / UX risk because waking requires physical button access. Please require an appropriate protected link for these control writes (for example encrypted/authenticated GATT permissions consistent with the rest of Omi's pairing model, or another maintainer-approved authorization gate) before enabling these controls by default.

A couple of non-blocking notes for the maintainer pass:

  • This also touches .github/scripts/check-release-process-guards.py; the narrow guard update looks aligned with the isolated tag checkout described in the PR, and the new focused guard test passes locally.
  • Because this is a draft firmware behavior change depending on #10572, and physical system-off/wake / charger / LED behavior still needs hands-on validation, it should stay under human maintainer review before merge.

Local validation I ran:

  • python -m pytest .github/scripts/test_check_release_process_guards.py::test_desktop_qualification_runner_accepts_run_isolated_tag_checkout -q passed.
  • The full release-guard pytest file has pre-existing parent-fixture failures in this shallow review checkout, so I did not treat that as a PR regression.
  • Flutter/Dart tooling was not installed in this review environment, so I could not rerun the new app test locally.

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

@undivisible
undivisible force-pushed the codex/firmware-idle-auto-sleep branch from 101dac2 to 7d99732 Compare July 29, 2026 04:49

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the update. I re-reviewed the current head and the main blocker from the earlier review is still present:

  • The new BLE sleep, capture-state, and persisted device-name characteristics are still registered with plain BT_GATT_PERM_WRITE / BT_GATT_PERM_READ | BT_GATT_PERM_WRITE. Because these controls are enabled by default, a connected nearby BLE client could still issue system-off or persistently rename the device without a protected link or other maintainer-approved authorization gate. Sleep is especially sensitive because recovery requires physical button access.

Please require an appropriate protected/encrypted/authenticated link or another explicit authorization gate for these control writes before this moves toward merge.

Keeping this as a requested change on the current head. Separate from that blocker, this should remain under human maintainer/security review because it is still a draft firmware power/control behavior change, depends on #10572, touches workflow-adjacent release-guard coverage, and the physical system-off/wake, charger, and LED behavior still need hands-on validation.


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

@undivisible
undivisible marked this pull request as ready for review July 29, 2026 18:34
@cursor

cursor Bot commented Jul 29, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the follow-up update. I re-reviewed the current head and the earlier blocking BLE-permissions issue looks addressed: the sleep, capture-state, and persisted device-name characteristics are now registered with encrypted read/write permissions where applicable.

I’m not approving this automatically because this is still a firmware power/control behavior change that depends on #10572, the PR notes that physical system-off/wake, idle-timeout duration, charger readings, and LED electrical output still need hands-on observation, and the Desktop Swift CI checks are currently failing. This should stay under human maintainer/security review before merge, but from the automation pass the prior BLE authorization blocker no longer appears to be blocking on this head.


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 dismissed stale reviews from themself July 29, 2026 22:26

Resolved on head 91689c8: the BLE sleep/capture/name characteristics now require encrypted GATT access; preserving human-review requirements separately.

@undivisible
undivisible force-pushed the codex/firmware-idle-auto-sleep branch from 91689c8 to a384e60 Compare July 31, 2026 03:02
Comment thread omi/firmware/omi/src/main.c Resolved

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for continuing to tighten this up. The earlier BLE control-permission blocker appears addressed on the current head: the sleep, capture-state, and device-name controls now use encrypted GATT permissions where applicable.

I found a new blocking issue before this can move forward:

  • omi/firmware/omi/src/lib/core/transport.c still registers audio_ccc_config_changed_handler in the audio service CCC entries, but on this head the function is only declared and no longer defined. The base branch has the definition; this head has only the prototype/usages. With CONFIG_OMI_ENABLE_CAPTURE_LED=y also enabled, transport.c additionally declares/calls update_advertising_name() from the device-name work handler, but that helper is not defined either. These missing definitions should fail the firmware build/link path for the enabled configuration, so please restore/implement them before merge.

Separate from that blocker, this should remain under human maintainer/security review because it changes firmware power/control behavior, depends on #10572, and the PR still notes hands-on validation gaps for physical system-off/wake, idle timeout, charger readings, and LED output.


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

Comment thread omi/firmware/omi/src/lib/core/button.c Resolved
Comment thread omi/firmware/omi/src/main.c Resolved
@undivisible
undivisible force-pushed the codex/firmware-idle-auto-sleep branch from 1955e5b to e65713c Compare July 31, 2026 06:08
@undivisible undivisible added enhancement New feature or request hardware firmware firmware work labels Jul 31, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for continuing to iterate on this.

I re-reviewed the current head. The prior automation blocker about missing audio_ccc_config_changed_handler / update_advertising_name() definitions appears resolved on this head: both helpers are now present in omi/firmware/omi/src/lib/core/transport.c, and the BLE sleep / capture-state / device-name controls are registered with encrypted permissions where applicable.

I’m not approving this automatically because this remains a firmware power/control change with security-sensitive BLE controls, it still depends on #10572 being merged first, and the PR’s validation notes still leave physical system-off/wake, idle-timeout duration, charger readings, and LED electrical output for hands-on maintainer validation. Please keep this under human maintainer/security review 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 dismissed their stale review July 31, 2026 08:55

Current head restores the missing transport.c helper definitions; the prior automation build/link blocker no longer applies.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for continuing to iterate here.

I found one current-head blocker that should be fixed before this moves forward:

  • update_idle_sleep() treats the device as active only when it is charging, connected with audio notifications subscribed, or in a connected storage transfer. With offline storage enabled in omi.conf, a disconnected pendant that is actively capturing/writing to SD still has is_connected == false and will accumulate idle time. After the timeout, the main loop can call turnoff_all() and stop a long offline recording session unexpectedly. Please either gate auto-sleep on an explicit “not recording / no offline capture active” state, or keep the feature disabled until firmware can distinguish real idle from disconnected offline recording.

The earlier BLE permission and missing-helper blockers look addressed on this head, but this remains firmware power/control behavior with security-sensitive BLE controls, an open dependency on #10572, and hands-on validation gaps for physical system-off/wake, idle timeout, charger readings, and LED output, so it still needs human maintainer/security review 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.

Comment thread omi/firmware/omi/src/lib/core/button.c Resolved
Comment thread omi/firmware/omi/src/main.c Resolved
Comment thread omi/firmware/omi/src/main.c Resolved

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Done

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit e54302b. Configure here.

Comment thread omi/firmware/omi/src/main.c Resolved

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the follow-up changes here.

The previous automation blocker around idle sleep interrupting disconnected offline recording looks resolved on this head: update_idle_sleep() now also holds the device awake when offline storage is enabled and the SD/mic path indicates active capture, in addition to connected storage transfer and subscribed audio.

I’m not approving because this is still firmware power/control behavior with encrypted BLE device controls, an open dependency on #10572, and remaining hands-on validation items for physical system-off/wake, idle timeout, charger readings, and LED output. Human maintainer/security review should still sign off 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 dismissed their stale review July 31, 2026 23:19

Resolved on current head: idle auto-sleep now treats offline SD/mic capture as active, so the stale automation change request no longer applies.

@undivisible
undivisible force-pushed the codex/firmware-idle-auto-sleep branch from 3c72837 to bb7c073 Compare August 4, 2026 19:25
@undivisible
undivisible requested a review from mdmohsin7 as a code owner August 4, 2026 19:25
Shipping omi.conf enabled idle auto-sleep and two new LED patterns in the
same change. Auto-sleep with no user-visible warning can end a session
the user believes is still recording, and the capture/low-battery
patterns change the LED language users already learned. Ship the BLE
sleep and rename controls, leave the behaviour changes opt-in per build,
and document the LED language next to set_led_state().

Failure-Class: none
main's desktop_qualify_beta.yml carries the full run-isolated checkout
line again, and test_desktop_release_flow_contract asserts the guard
pins that exact fragment, so the relaxed constant fails the contract.
Restore main's guard text and keep the focused acceptance test.

Failure-Class: none
@undivisible
undivisible force-pushed the codex/firmware-idle-auto-sleep branch from 6de5334 to 3eb5da8 Compare August 10, 2026 23:11
@Git-on-my-level Git-on-my-level removed the flutter flutter work label Aug 11, 2026
@Git-on-my-level
Git-on-my-level dismissed their stale review August 11, 2026 17:51

Resolved on current head: encrypted GATT permissions restored for sensitive controls, and idle sleep is disabled/gated for offline-capture-capable builds.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for the latest update — I re-reviewed the current head and the automation blockers I raised on the previous head look addressed.

Specific notes from this pass:

  • omi/firmware/omi/src/lib/core/transport.c: the sleep command (19B10014), capture-state (19B10015), and device-name (19B10016) characteristics are now registered with encrypted GATT permissions where enabled, and the write handlers validate offset/prepared writes/lengths before acting. The connection refactor also uses get_current_connection() to return a ref-counted handle and unreferences it at the updated call sites I sampled.
  • omi/firmware/omi/src/lib/core/idle_sleep.h and omi/firmware/omi/src/main.c: the idle policy now treats charging, storage transfer, connected audio subscription, and offline-capture-capable builds as busy; update_idle_sleep() wires that policy in only behind CONFIG_OMI_ENABLE_IDLE_SLEEP.
  • omi/firmware/omi/Kconfig and omi/firmware/omi/omi.conf: idle auto-sleep depends on !OMI_ENABLE_OFFLINE_STORAGE, and the shipping config keeps idle sleep plus the new capture/low-battery LED patterns disabled while enabling only the encrypted app-driven sleep/name controls.
  • omi/firmware/omi/src/settings.c / settings.h: persisted device naming is bounded by CONFIG_BT_DEVICE_NAME_MAX, rejects empty values when loading/saving, null-terminates the in-memory cache, and is re-applied during transport startup.
  • app/lib/services/devices/connectors/omi_connection.dart and app/test/services/omi_device_controls_test.dart: the mobile side writes the expected sleep/name characteristic UUIDs and rejects blank, over-25-byte, or NUL-containing names before sending them.
  • .github/checks-manifest.yaml and omi/firmware/omi/tests/run_idle_sleep_test.sh / test_idle_sleep.c: the host-verifiable idle-sleep policy test is registered in the manifest and covers the offline-capture guard that was previously blocking.
  • .github/scripts/test_check_release_process_guards.py: this diff only adds coverage for the desktop qualification runner’s isolated tag checkout behavior; it still keeps this PR in workflow-review territory because it touches release/check guard coverage.

I’m not approving this automatically because this is still firmware power-off / BLE identity-control behavior, has workflow/check-manifest changes, carries a rebase/blocking state, and needs maintainer/product sign-off on the final shipped UX for sleep/LED behavior. Leaving this for human maintainer review for firmware power-control and workflow sign-off 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.

@undivisible

Copy link
Copy Markdown
Collaborator Author

Thanks for the firmware review. Both concerns are addressed on the current head:

LED patterns — the capture and low-battery LED patterns are now opt-in Kconfig, disabled in omi.conf, so shipping LED behavior is identical to before this PR. The review-fix commit 3f44b12836 ("keep idle auto-sleep and new LED patterns off by default") made this explicit.

Idle auto-sleep data loss — two guards:

  • Auto-sleep is disabled by default (omi.conf) and only reachable through an explicit BLE command behind an encrypted link (f8b7a43da4 — the sleep, capture-state, and device-name characteristics now require BT_GATT_PERM_WRITE_ENCRYPT / BT_GATT_PERM_READ_ENCRYPT).
  • update_idle_sleep() never powers off while offline_capture_possible is true (SD capture without a BLE link), nor during storage transfer or subscribed audio (4d4c7ee2d1), with regression coverage in test_idle_sleep.c.

Also merged main on this head (the branch was 330 commits behind). CI is re-running.

The DIS/BAS/device-name/device-appearance assignments are already
configured below (omi.conf lines 86-108); the commented duplicates above
were stale documentation that contradicted the effective config.
@undivisible

Copy link
Copy Markdown
Collaborator Author

Addressed the four review points (all already resolved or fixed on the current head):

  1. Remove commented BT config lines — done in 7989e42. The commented CONFIG_BT_DIS/BAS/DEVICE_NAME/APPEARANCE stubs above the real config block are now removed; the effective assignments (omi.conf:86-108) are unchanged.

  2. Keep the device powered during a storage sync while connected but not streaming audio — the idle policy (omi_idle_is_busy) already treats storage_transfer_active as busy, so a file sync holds the device awake. Verified at omi/firmware/omi/src/lib/core/idle_sleep.h and update_idle_sleep in main.c.

  3. Blinking red reused for low battery conflicts with the time-sync blink — resolved by 3f44b12: CONFIG_OMI_ENABLE_CAPTURE_LED and the low-battery LED branch are now off by default, so the shipped build keeps the existing LED behavior (time-sync blink red, red = not connected). The new patterns only activate when a board opts in.

  4. Red overlapping with 'disconnected + offline recording' — same off-by-default resolution: with CONFIG_OMI_ENABLE_CAPTURE_LED unset, the capture-state LED never runs. Additionally, offline-storage builds never auto-sleep (4d4c7ee) since the firmware can't tell idle from mid-recording.

I have not run this on hardware; the LED config changes are config-gated so the default firmware path is unchanged.

@undivisible
undivisible removed the request for review from TuEmb August 14, 2026 09:41
@Git-on-my-level Git-on-my-level removed the needs-rebase PR has merge conflicts / is behind main and needs rebasing label Aug 18, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for the latest round on this head — re-reviewed 11aa7b5687 and the new commits look right on everything I can verify without hardware:

  • omi/firmware/omi/src/main.c + omi/firmware/omi/Kconfig (f81b8765a3): the low-battery warning is now a distinct double-blink (low_battery_phase < 2, cycling mod 3 and resetting once the battery is back above threshold), so it no longer collides with the time-sync / disconnected red blink. That addresses the LED-confusion half of the earlier firmware review; the Kconfig help text matches the new pattern.
  • .github/scripts/test_check_release_process_guards.py (11aa7b5687): dropping test_desktop_qualification_runner_accepts_run_isolated_tag_checkout is consistent with current main, where ci: collapse desktop beta to signed-smoke plus hourly freshness #11588/fix(ci): land leftover desktop-beta review fixes from #11588 #11605 removed check_desktop_qualification_runner() from the guard script. The net diff of the release-guard files against this PR's base is empty, so this reads as cleanup rather than a guard weakening. I ran the suite on this head: 94 passed.
  • omi/firmware/omi/omi.conf (7989e42c7d): removing the commented CONFIG_BT_DIS/BAS/DEVICE_NAME/APPEARANCE stubs is safe — the effective block (omi.conf:100-109) is unchanged.
  • Re-ran the host policy test on this head: bash omi/firmware/omi/tests/run_idle_sleep_test.sh → idle-sleep policy tests passed. The encrypted permissions on 19B10014/19B10015/19B10016 with strict write validation and NVS-rollback on rename, the ref-counted get_current_connection()/transport_off() ownership transfer, the disconnect-time is_capturing clear, and the persisted-name restore during transport init all still check out. The new OMI_FEATURE_SLEEP_COMMAND/OMI_FEATURE_DEVICE_NAME bits (1<<9, 1<<10) match OmiFeatures in app/lib/services/devices.dart.
  • GitHub now reports the PR mergeable with no conflicts, so I removed the stale needs-rebase label.

Leaving the merge decision with a human maintainer as before: this is power/identity firmware behavior on an encrypted link, the stacked dependency #10572 is still open, the shipped UX for app-driven sleep and the opt-in LED language still needs product sign-off before idle sleep is enabled in a shipping config, and on-device QA (pairing on the three encrypted characteristics, rename visibility in advertisement/scan response, physical system-off/wake) hasn't been run. The two Desktop Swift checks are also still queued.


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

Copy link
Copy Markdown
Member

Re-reviewed the current head. Thanks @undivisible — this round cleanly addresses the earlier human review feedback:

  • Storage sync stays awake: omi_idle_is_busy() in omi/firmware/omi/src/lib/core/idle_sleep.h treats an active storage transfer as busy, and the host test (tests/test_idle_sleep.c) asserts the never-sleeps-mid-sync case. I ran bash omi/firmware/omi/tests/run_idle_sleep_test.sh on this head — passing.
  • LED-pattern overlap: both new patterns remain opt-in Kconfig and are off in omi.conf; the low-battery warning is now a distinct double-blink (low_battery_phase in src/main.c), so it no longer collides with the solid-red disconnected state or the time-sync blink.
  • omi.conf cleanup: the dead CONFIG_BT_DIS/BAS=n lines are removed rather than commented out (the =y settings later in the file already win).
  • Idle-sleep data-loss risk: OMI_ENABLE_IDLE_SLEEP is default-n, depends on !OMI_ENABLE_OFFLINE_STORAGE, and explicitly unset in the shipping config — a build that can record to SD can never auto-power-off.

Also verified on this head: the encrypted GATT permissions for sleep (19B10014), capture-state (19B10015), and device-name (19B10016) are in place; the current_connection ref-counting is balanced at every call site I traced (button.c notifies, storage_write in both branches, the battery work handler, MTU recheck, both pusher paths, and transport_off's ownership transfer under the spinlock); the device-name write validates length and embedded NUL and rolls back bt_set_name() if the NVS save fails; and the Dart side (omi_connection.dart) mirrors the same limits with new tests in app/test/services/omi_device_controls_test.dart.

What remains before merge, for a human maintainer:

  • On-device validation of the power-off and rename flows (the earlier review noted this hadn't yet been tested on hardware).
  • Dependency ordering: this should still land after fix(firmware): make CV1 capture durable and 3.2× faster on iPhone #10572.
  • Product sign-off on the eventual enablement plan (idle sleep and the new LED patterns surfacing in-app) before any of the opt-in flags are turned on in a shipping config.

Leaving for human maintainer 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.

Merge origin/main into codex/firmware-idle-auto-sleep. Single conflict in .github/checks-manifest.yaml (both sides added test entries at the same location); kept both the PR's firmware-idle-sleep-tests entry and main's new iOS test entries.
@omiagent

omiagent Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Reviving this PR after the community-call ask (a user asked for exactly this "disable/put to sleep" capability on the Sep 25 call).

@undivisible — status: the changes requested on Aug 9 were addressed in your Aug 18 commits (distinct double-blink low-battery LED, storage-sync stays awake, config cleanup) and Git-on-my-level's Aug 19 review confirmed them on 11aa7b5687.

Updates today:

  1. Dependency fix(firmware): make CV1 capture durable and 3.2× faster on iPhone #10572 was closed unmerged — verified no compile-time coupling, this PR stands alone.
  2. Merged current main into the branch (merge commit b68d860a84): zero upstream drift on the firmware files this PR touches; one checks-manifest conflict, both sides kept.
  3. Re-verified on the merged head: idle-sleep policy host tests pass, clang-format clean on all touched C files, checks-manifest valid.

Remaining before merge: a fresh maintainer review of the current head (the Aug 9 CHANGES_REQUESTED predates the fixes), an NCS 2.9.0 compile, and hardware QA. Requesting re-review from @TuEmb and @Git-on-my-level.

@omiagent
omiagent Bot requested review from Git-on-my-level and TuEmb September 26, 2026 05:29
…ntrols

The mobile-changelog-entry hygiene gate (added to main after this PR opened) requires an app/changelog/unreleased fragment for any app/ change. The PR adds service-layer transports only and ships no user-facing UI, and the firmware features behind them are opt-in Kconfig disabled in omi.conf, so the fragment is {"kind": "none"}.
@omiagent

omiagent Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

CI green on the current head 0258c72047 (branch updated 2026-09-26: merged current main, resolved the checks-manifest conflict, added the {"kind": "none"} mobile changelog fragment now required by the Hygiene gate).

  • 36 check-runs: 26 success, 10 skipped (path-gated), 0 failures. Including: Hygiene ✅, Dart Analyze & Tests ✅, Dart Tests (Pacific/Kiritimati) ✅, Android Compile Smoke ✅, Android JVM Unit Tests ✅, iOS Compile Check ✅, Desktop Swift Build & Tests ✅, CodeQL ✅, Formatting ✅.
  • Host-side re-verification from the revive round: omi/firmware/omi/tests/run_idle_sleep_test.sh passes, clang-format clean on all touched C files, checks-manifest valid.
  • Probe: GET /commits/0258c72047/check-runs — every check completed with success/skipped.

What remains before merge, unchanged in kind from earlier rounds:

  1. A fresh maintainer review of the current head so the Aug 9 CHANGES_REQUESTED is superseded (the concerns in it were addressed by the Aug 18 commits; @Git-on-my-level's Aug 19 review confirms them on this code).
  2. NCS 2.9.0 signed build (CI does not compile firmware) — needed once before release, per the PR's own validation notes.
  3. Hands-on hardware QA of system-off/wake, encrypted-link pairing on the new characteristics, and LED output.

@Git-on-my-level

Copy link
Copy Markdown
Member

Since my last review: addressed — idle-sleep policy moved into a Zephyr-free omi/firmware/omi/src/lib/core/idle_sleep.h with a host test (tests/test_idle_sleep.c + run_idle_sleep_test.sh, wired into CI as firmware-idle-sleep-tests; I ran it on this head and it passes), offline-recording protection is now structural (OMI_ENABLE_IDLE_SLEEP depends on !OMI_ENABLE_OFFLINE_STORAGE), the app side gained the sleep/rename controls with matching validation plus app/test/services/omi_device_controls_test.dart, and a changelog fragment was added · still open — maintainer sign-off for the firmware power/identity surface (why the review labels stay) · newly introduced — nothing blocking; two notes below.

Verdict: solid and safely gated on this head — what remains is a maintainer decision, not contributor rework.

  • transport.c: the three new characteristics (19B10014 sleep, 19B10015 capture-state, 19B10016 device-name) all require an encrypted link — stricter than the existing dim-ratio/mic-gain chars, which still use plain BT_GATT_PERM_READ|WRITE. Name writes validate 1–25 bytes, reject embedded NULs, and roll back bt_set_name() if the NVS persist fails; advertising is rebuilt with the runtime name (shortened in the ad, complete in the scan response).
  • Refcounting: get_current_connection() now returns a ref'd pointer under a spinlock and every call site unrefs (button.c notify helpers, the storage.c write loop, battery broadcast, MTU recheck, pushers, transport_off). Dropping the bt_conn_unref(conn) in _transport_connected's bt_conn_get_info error path is correct — that callback never owned a ref. This closes real leak paths.
  • idle_sleep.h / main.c: busy inputs are charging, storage sync, subscribed audio, and any offline-capable build; the counter saturates rather than wraps. omi.conf ships idle sleep, capture LED, and low-battery LED off, so device behavior at merge is unchanged.
  • omi_connection.dart + devices.dart: sleepDevice() / setDeviceName() mirror the firmware validation (trim, 25-byte cap, NUL check); feature bits 1<<9/1<<10 match features.h. Dart tests are green in CI.

Security: no plaintext control surface — sleep and rename both require pairing/encryption, and capture-state clears on disconnect so it cannot stay latched. Blast radius: a slept pendant needs a physical button press (BLE cannot wake it), which is exactly the product behavior a maintainer should sign off on.

Two notes before this leaves draft:

  • omi.conf drops CONFIG_BT_DIS=n / CONFIG_BT_BAS=n. That is config-neutral only while the Kconfig defaults for those stay n, and firmware has no CI build — please confirm with a west build for the shipping board.
  • When idle sleep is later enabled for a real build: the tests intentionally treat "connected but not subscribed" as idle, so a pendant linked to a quiet app still powers off. The Kconfig help promises to surface that in-app first — keep that promise when the flag flips.

USER IMPACT: none at merge — every new behavior ships behind Kconfig flags that are off in the shipping build; once enabled, users get app-driven sleep/rename and, later, auto-sleep after idle.

What I'd still want: a firmware west build confirmation for the shipping config, and a maintainer decision on the encrypted power-off/rename surface (security-review stays; workflow-review covers the checks-manifest.yaml addition, whose triggers match its command).


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

Copy link
Copy Markdown
Member

Since my last review: addressed (low-battery warning is now an explicit double-blink phase machine in main.c with a bogus-0%-read guard and a reset when battery recovers; the contradictory CONFIG_BT_BAS/DIS=n lines were removed from omi.conf — the =y lines later in the file were already winning, so no behavior change; the idle policy is now host-testable and wired into the checks manifest; a Dart unit test covers the new sleep/rename writes; branch re-merged on current main) · still open (nothing from my prior review — the encrypted-permission, helper-definition, and offline-capture blockers all remain fixed on this head; the #10572 dependency is moot since that PR was closed unmerged and this branch carries its own storage/idle handling) · newly introduced (a firmware-idle-sleep-tests entry in .github/checks-manifest.yaml — I ran bash omi/firmware/omi/tests/run_idle_sleep_test.sh locally and it passes).

The production changes here are correct and nicely scoped; nothing blocking from automation, but this one stays with the human maintainers (firmware power/identity surface, draft PR).

What I verified on this head:

  • transport.c — sleep (19B10014), capture-state (19B10015), and device-name (19B10016) characteristics all registered with BT_GATT_PERM_*_ENCRYPT; validate_single_write() rejects offset and prepared writes; the power-off runs via k_work on the system workqueue (sleep_cmd_work → turnoff_all) instead of inside the ATT callback; capture state is cleared on disconnect so it cannot stay latched.
  • Device-name path — write caps at 25 bytes, rejects embedded NULs, rolls back bt_set_name() if the NVS persist fails, and re-applies the stored name on boot (transport_start → app_settings_get_device_name). The Dart side in omi_connection.dart mirrors the exact same rules (UTF-8, trim, 1–25 bytes, no NUL).
  • Advertising — start_advertising() now builds payloads from bt_get_name(): shortened name in the advertisement when it exceeds the 8-byte budget (31 − 3 flags − 18 UUID − 2 header) with the complete name in scan response. The default "Omi" still fits, so today's payload is effectively unchanged.
  • Refcounting — current_connection is static, guarded by a spinlock, and acquired via get_current_connection(); every caller unrefs on all paths (button.c notify_*, storage.c storage_write both branches, battery work, mtu_recheck, pusher/test_pusher). register_accel_service(NULL) is behavior-identical since the parameter is unused in accel.c.
  • idle_sleep.h — Zephyr-free policy with overflow-safe accumulation; offline-capable builds are unconditionally busy and Kconfig separately forbids OMI_ENABLE_IDLE_SLEEP with OMI_ENABLE_OFFLINE_STORAGE — belt and suspenders, both directions correct. omi.conf ships idle auto-sleep and both LED patterns disabled; the BLE sleep command and rename controls do ship enabled (both encrypted).

Security: WRITE_ENCRYPT requires an encrypted link but not an authenticated (MITM-protected) one — Just Works pairing leaves a narrow proximity-based rename/power-off surface. I think that's acceptable for this threat model, but it's exactly what the security-review label should sign off on.

Performance: the idle poll calls transport_is_audio_subscribed() once a second (one conn ref + CCC query) — negligible.

USER IMPACT: none yet — this adds encrypted firmware controls and opt-in flags with no shipped app UI, so users see no behavior change until the app wires up sleep/rename actions.

What I'd still want as a reviewer: on-hardware validation of the button system-off wake path and idle-sleep current draw (the PR notes this is untested), maintainer sign-off on the encrypted-write model before merge, and a product decision on when idle auto-sleep and the LED patterns get enabled in a release.


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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app enhancement New feature or request firmware firmware work hardware human Human-authored pull request mobile needs-maintainer-review Needs a human maintainer to sign off before merge security-review Touches auth, provider routing, secrets, or security-sensitive surfaces workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants