Repository navigation
fix(app): measure battery cliffs without charging diagnostics - #20490
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
All reported issues were addressed across 11 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 03aeb1d644
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
03aeb1d to
73278b9
Compare
|
Addressed all 7 unresolved review threads in 73278b9 (rebased onto current main first):
All 7 threads resolved as addressed. Verification: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73278b9e9e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
73278b9 to
43b6350
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 43b6350cd7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b5b987e08
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Count in-day battery cliffs and unknown-charging drain in the existing daily aggregate. Backfill charging after throttled best-effort native diagnostics reads and accept the append-only diagnostics tail. Failure-Class: none
…, rollup completeness - Retain the last-known charging flag across a reconnect while the 15-minute diagnostics cadence gate is still warm (iOS and Android), so battery points keep their tag instead of silently reverting to unknown and counting as drain. - Bound the post-diagnostics charging backfill to points at most 15 minutes old (both platforms) so the state observed now cannot relabel hours-old samples. - Drain windows exclude intervals with an explicitly charging endpoint on either side; unknown flags on both endpoints still count as drain. - Retain enough firmware-diagnostics reads (672 = 4/hour over the 7-day retention) so the previous day's samples survive until the daily rollup emits. - Emit last_off_charger_mv min/max aggregates alongside the other optional diagnostics-tail fields. - Tests: exact cliff_count/max_step_drop bounds; parser omits (not nulls) unknown tail fields; stale-point backfill stays unknown on both platforms; charging-endpoint drain exclusion; off-charger voltage aggregates. Failure-Class: none Verification: - flutter test test/unit/device_health_telemetry_test.dart: 7 passed. - ruby app/ios/test/omi_ble_energy_policy_test.rb: 3 runs, 0 failures. - xcrun swiftc -parse OmiBleManager.swift OmiBleEnergyPolicy.swift: clean. - Kotlin: no local SDK; CI runs Android unit tests (previously green on this PR).
…llup Address review: the priorTs >= start guard added for cliff detection also excluded drain intervals whose previous sample belongs to the prior day, so a window straddling midnight (e.g. 80% at 23:55 to 78% at 00:05) was dropped from both daily events. Restore the pre-PR boundary-sample anchor for drain windows; cliffs keep the same-day consecutive-point rule. Add a regression test asserting the window is counted exactly once, by the later day.
…ing for the catch-up window Address review: - The retained last-known charging flag cannot survive a disconnect: the state may have changed while disconnected (e.g. unplugged), the backfill only stamps points whose flag is missing, so a stale charging=true would exclude real drain intervals from drain_percent_per_hour forever. Clear the flag on reconnect (iOS and Android) so new battery points stay unknown — the rollup's conservative default — until the next successful diagnostics read re-stamps the actual state. Removes the now-unused isDiagnosticsReadThrottled helpers on both platforms. - Size the firmware-diagnostics ring for the worst-case catch-up window: maybeEmit can roll up yesterday - 6, whose start is nearly eight days old late in the current day, while 672 15-minute samples cover only seven rolling days including today. 4/hour * 24 * 8 = 768 (iOS and Android). Verification: swiftc -parse of OmiBleManager.swift clean; Kotlin verified by review + CI Android Compile Smoke (no local Android toolchain).
Address review: appendJsonRing prunes entries older than the passed retention before applying the entry cap, so the firmware ring was still losing the earliest catch-up day's samples to the seven-day disconnect retention even after the cap was raised to 768. Give the firmware ring its own worst-case window (8 days, matching the cap rationale); the disconnect history keeps the plain seven-day retention. iOS has no time-based eviction on its firmware ring, so no iOS change.
6b5b987 to
084a555
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Monitor run — review feedback addressed (context 14c0c533a5). All four unresolved Codex threads on this PR have been fixed in code and resolved; CI is green on the final head
Verification: |
…ice-health event (#26418) ## Summary When an Omi user stops capturing, telemetry can't tell a pendant that failed or became unusable (dead or uncharged battery, broken BLE, broken mic) from one that was put down. A churn study (heavy users who stop) found no failure events before the stop, but the known gaps meant it couldn't rule hardware out: - `charge_events` is 0 for everyone. The rollup is correct, but the charging bit comes only from the firmware Diagnostics characteristic, which ships from 3.0.24. The fleet is on 3.0.21: 14,212 of 26,135 daily events in the last 7 days, against 29 on 3.0.24, and 16 of those 29 do show `charge_events > 0`. `charge_pin_edges_max` and `soc_frozen_samples` never appear. - `lost_audio_seconds` is by design "time without a link", so it can't hold "connected, no audio". - Battery % is readable on only 10–20% of battery-indicator taps, which mostly happen while the pendant is disconnected. - The session end reason is `connection_timeout` for nearly every loss (602,881 of 650,590 iOS disconnects). Firmware power-off (`turnoff_all` → `sys_poweroff`) and the battery-critical shutdown cut power without terminating the link, so the phone sees a supervision timeout, the same as walking out of range. This PR adds drop-off fields to the existing **`Mobile Device Health Daily`** event (`schema_version` 2 → 3). They're computed in Dart from the native diagnostics snapshot the rollup already reads (`disconnect_history_v2`, `battery_history_v2`, `ble_log`, `audio_packet_days`). There's **no new event, native call, pigeon change, scan or BLE traffic**, and no firmware change. A **gap** is a disconnect whose next connection starts ≥ 30 minutes later, or hasn't started yet. Each day's event describes the most recent gap that started before the day's end, so a fully disconnected day still carries the cause of the stop. | Question | Fields | |---|---| | Out of range, powered off, or battery flat? | `gap_cause` (`battery_flat`, `out_of_range`, `power_off`, `manual`, `pairing_lost`, `phone_side`, `unknown`), `gap_last_rssi`, `gap_rssi_age_s`, `gap_rssi_trend` | | Last battery level and charging state before the disconnect, and how long before | `gap_battery_level`, `gap_battery_age_min`, `gap_battery_charging` | | Reconnect attempts failed, or none made? | `gap_fail_to_connect`; iOS, open gap only: `gap_saved_reconnect_enabled`, `gap_reconnect_suppressed` | | Seen advertising but never connected? | iOS: `gap_scan_covered`, `gap_scan_windows`, `gap_advert_sightings` (counts omitted when the 24 h native log doesn't reach the gap start; absent on Android, which logs no scan results) | | Mic or audio stopped while BLE stayed connected? | `connected_no_audio_seconds`, `connected_no_audio_sessions`, `audio_packets_per_connected_minute` | | Daily rollup: not connected vs connected with no audio | `connected_seconds`, `disconnected_seconds`, `connected_no_audio_seconds`, `long_gaps`, `long_gaps_by_cause` | | Charging without firmware support | `charge_inferred_events`, `battery_min_level`, `battery_max_level` | | Support-reported symptoms: disconnects seconds after connecting, stuck at 1%, won't charge, erratic reading | `short_sessions`, `gap_short_sessions_24h` (link dropped within 30 s), `battery_low_seconds` (time at ≤ 5%), `battery_erratic_steps` (≥ 20-point step within 10 min) | Field reference, cause rules and the analyst query: `app/docs/device-dropoff-telemetry.md`. Why the symptom fields exist: of 25 cancellers who reported a hardware problem to support in the 90 days before cancelling and had telemetry, 18 had no failure or reset event in the 14 days before. Their connected fraction and failure-event rate looked like cancellers who never contacted support. The schema 2 fields could not see these faults. Firmware resets (`device_resets_by_reason`, about 0.1% of daily rows, mostly `RESET_LOW_POWER_WAKE`) are rare but real, so the query counts them as hardware evidence. ## Cost Measured through the read-only PostHog bridge, aggregate HogQL, 7 days to 2026-11-26: `Mobile Device Health Daily` had 26,131 events from 4,991 users, about **0.75 per active pendant user per day**. It is keep-listed at 100%, so new fields are not sampled. - **Added events per active user per day: 0.** - Added properties: up to 30 keys per daily event (25 on Android), about 22 property values per active user per day, about +0.6 KB per user-day. PostHog bills per event, so there is no added event cost. - Phone: one extra pass over data already loaded, once a day. ## Kill switch PostHog flag `device_dropoff_telemetry_off` (registered in `config/feature-flags.yaml`, `posthog.row: absent`, role `kill`). If it's true, the event drops every new field and goes back to `schema_version` 2. If it's absent, false or unreadable, the fields stay on. On for everyone; no PostHog row is needed until someone uses it. The flag read adds no events, since `sendFeatureFlagEvents` is false. ## Query that separates hardware drop-off from put-down drop-off (after release) It is in `app/docs/device-dropoff-telemetry.md`. A stop is the first day with `connected_seconds = 0` after at least 5 connected days in the previous 14, with the next 2 days also at zero. All 3 days must have an event. The query works per Omi pendant model, so a second paired device such as a watch can't mask the stop. Each stop is classified as: - `hardware`: flat battery, the pendant seen advertising, mostly silent connected time, short-session churn, an hour or more stuck at ≤ 5%, an erratic or cliff battery step, or a firmware reset in the 14 days before the stop. Failed reconnect attempts are reported in their own column, because Android's direct connect also fails when the pendant is simply absent; - `put_down`: a clean loss (out of range, powered off or manual) with more than 20% battery left; - `unclassified`: anything else. The query buckets on `properties.day`, because emission can be up to 7 days late. Days the app never ran emit nothing, so a missing day is not a zero day. `put_down` also requires a battery sample at most 3 hours old. The query runs on PostHog today. It returns no rows until schema 3 ships. Run with `connected_time_fraction` standing in on schema-2 data, it found 1,626 Omi pendant stops and classified 89 of them as hardware (cliffs and resets). Once schema 3 has a month of data, check its recall against the support-reported hardware group before trusting a `put_down` share. ## Firmware follow-up (written up, not implemented) 1. Roll the 3.0.24+ Diagnostics characteristic out to the fleet. That makes `charge_events`, the charging bit, reset causes and `charge_pin_edges_max` real. 2. In `turnoff_all()`, terminate the link before `sys_poweroff()`, with distinct HCI reasons for the button and battery-critical paths. 3. Persist the last shutdown cause and expose it in the Diagnostics characteristic. 4. Record a watchdog or hang marker, plus the LED state, that survives a cable reset. Then a 3.0.21 freeze with a solid blue LED reports itself on the next connection. ## Verification - `flutter test test/unit/device_dropoff_signals_test.dart test/unit/device_health_telemetry_test.dart`: 59 passed (via `omi-heavy`). - `flutter analyze` on the changed Dart files: no issues. - `python3 scripts/check_feature_flag_registry.py`: OK. Registry doc re-rendered. - The analyst HogQL ran against PostHog (aggregate only). Layer measured: unit tests and static analysis. The production readback comes after release: run the query above, plus a coverage check of `schema_version = 3` and `gap_cause` presence on the daily event. ## Scope panel `scope-20261126t154826-3a9e` triage The scope panel (luna, deepseek, glm-flash) returns a dossier without triageable finding IDs (`omi-panel triage` accepts review findings only), so its 27 risks are triaged here in panel order (R1–R27). | # | Risk | Call | |---|---|---| | R1 | New fields conflict with the frozen typed registry row | Reject. Untyped rollup fields are the established path for this event (#20490 added `soc_frozen_samples` and others). `events.json` and the ring-read row are untouched. | | R2 | Labels are heuristics; a stale battery sample can fake a put-down | Accept. `unknown` stays explicit, and `put_down` needs a battery sample at most 3 h old. | | R3 | RSSI 0 or age −1 misclassified | Already guarded. Tests added for RSSI 0, age −1 and age 30001. | | R4 | Reconnect proof ignores `lostAudioResolvedAt` | Accept. Audio resuming now closes the gap, with a test. | | R5 | Days the app never runs emit nothing | Accept. Stated in the query header and the PR. | | R6 | Zero-audio time is confounded by capture being off | Accept. Documented as zero-packet time, not proof of a broken mic. | | R7 | Typed-registry route would fail CI | Accept. Legacy fields only. | | R8 | 7-day and 24 h retention bound coverage | Accept. Documented. | | R9 | Battery samples only exist while connected | Accept. Covered by the freshness rule in R2. | | R10 | Payload grows by about 0.5 KB per user-day | Reject. Billing is per event, and the size is stated. | | R11 | No dedup across installs | Reject. Existing behavior, out of scope. | | R12 | 8-day replay vs 7-day rings | Reject. Pruning drops the oldest rows first, so the latest retained gap is the true latest. The existing `connection_history_incomplete` flag marks partial days. | | R13 | Android fallback snapshot has no `connected_at` | Reject. It inherits `connected_time_fraction`'s existing behavior. | | R14 | Mixed row types could corrupt gaps | Already filtered to `disconnect` rows, and tested. | | R15 | Map properties may not be queryable | Reject. `JSONExtractKeysAndValues` on `disconnects_by_reason` ran in PostHog during design. | | R16 | Kill-switch path and name rules | Already compliant. The registry check passes. | | R17 | Bucket on `properties.day`, not timestamp | Already does. Now stated in the query header. | | R18 | `out_of_range` may rarely fire | Accept. The post-release readback measures the `unknown` share. | | R19 | Restarted counters fake zero-audio sessions | Accept. A packet `last_at` inside the session vetoes it, with a test. | | R20 | `phone_side` is Android-only | Accept. Documented. | | R21 | Stop day lost if the app is not opened within 7 days | Accept. Documented. | | R22 | Schema 3 with missing keys is ambiguous | Reject. A killed event emits schema 2. | | R23 | `disconnected_seconds` must use the corrected value | Already does. | | R24 | Existing fields must stay unchanged | Accept. A test asserts every legacy key's value is equal with the fields on or off. | | R25 | Storage growth | Reject. Duplicate of R10. | | R26 | Flag read cost | Reject. Read once per emission. | | R27 | Malformed rows | Accept. Malformed-row test added. | ## Review panel `review-20261126t160746-ed30` triage | # | Finding | Call | |---|---|---| | F1 | Missing days pass the stop's zero-connection check | Accept. Each of the 3 stop days needs an event at zero. | | F2 | Android `connected_at` is stamped before GATT succeeds | Accept. The open link counts only once a packet arrives on it, with a test. | | F3 | An unknown charging bit can fake `battery_flat` | Accept, modified. A level rising into the loss now vetoes `battery_flat`. Requiring `charging == false` would disable the cause on the whole 3.0.21 fleet, which has no bit. | | F4 | A gap maturing after its start day was emitted misses that day's `long_gaps` | Reject. It needs a gap starting within 30 min before an after-midnight emission, and the next day's gap fields still describe it. | | F5 | Person-day rows mix devices | Accept. The query works per pendant model, restricted to Omi pendants. | | F6 | Cause coverage differs by platform | Accept the documentation part: per-platform coverage is now in the doc. Native changes (Android manual rows, status 137 mapping) are out of scope for this Dart-only PR. | | F7 | `gap_fail_to_connect` overstated | Accept. Reworded, and taken out of the hardware rule into its own column. | | F8 | Null scan counts never reach PostHog | Accept. Added `gap_scan_covered`; uncovered counts are omitted. | | F9 | Full-log branch untested | Accept. A 500-row boundary test was added. | | F10 | Kill switch reads `isFeatureEnabled` | Reject. It matches the sibling `upload_end_marker_off` pattern, and the flag has no arms. | ## UI evidence Telemetry only: no screen, widget or string changes. UI-Evidence: none ## Product invariants affected none ## Failure class (fixes) The follow-up `fix:` commit corrects code that is new in this PR. It is not a released defect. Failure-Class: none 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Summary
App-only measurement for the 100% to ~40% battery cliff. No firmware release is required, and this does not depend on the draft firmware PR.
Mobile Device Health Dailystill uses the same event. Points with a missingchargingflag now count toward drain instead of being dropped. A drop of 30 points or more within 10 minutes incrementscliff_count.max_step_dropandmax_step_drop_secondskeep the largest such pair. No device id is added.chargingonto the latest battery-history point when that point has no flag yet. Reads are best-effort and throttled to 15 minutes per device, including failed attempts, so a missing characteristic cannot storm reconnects or start pairing recovery.last_off_charger_mv,charge_pin_edges, andsoc_frozen. Those aggregates are emitted only when a read actually contains them.The matching firmware change is draft PR #20483. This PR is useful on current firmware 3.0.21, which does not emit the characteristic.
Product invariants affected
none
Failure class
Failure-Class: none
This is a measurement fix, not a closed incident class.
Verification
flutter test test/unit/device_health_telemetry_test.dart: 6 passed, including the existing drain and charge-event expectations.ios-ble-energy-policyRuby tests: 3 runs, 0 failures.