Skip to content

feat(sync): add sync health watchdog and stall alerts (#15501) - #17825

Open
TheRWX wants to merge 1 commit into
BasedHardware:mainfrom
TheRWX:feat/sync-health-watchdog-15501
Open

TheRWX wants to merge 1 commit into
BasedHardware:mainfrom
TheRWX:feat/sync-health-watchdog-15501

Conversation

@TheRWX

@TheRWX TheRWX commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Implements an automated device synchronization health watchdog (SyncHealthWatchdog) and user notification alert system to prevent silent multi-day recording loss on Android (#15501).

Problem

Users on Android running Omi with paired hardware devices reported discovering multi-day gaps in recordings with no warning that sync had stopped working or disconnected silently. When the background connection or audio transport stalled, the app gave no indication or notification, leading to permanent loss of unretrieved audio recordings.

Solution

  1. SyncHealthWatchdog singleton service (app/lib/services/sync_health_watchdog.dart):
    • Monitors elapsed time since last sync, BLE audio ingestion, or batch recording finalization.
    • Evaluates device sync health against a 4-hour stall threshold.
    • Dispatches a local notification (Omi Not Syncing: No recordings have synced from your Omi in over X hours...) with deep-link navigation to /home.
    • Protects users with a 6-hour notification cooldown and quiet night-hours suppression (22:00 to 08:00).
    • Throttles in-memory timestamps to avoid disk I/O thrashing during continuous audio capture.
  2. Activity Recording Hooks:
    • DeviceProvider: Starts/stops watchdog lifecycle, updates sync timestamp on device connection, and checks health on disconnection.
    • CaptureController: Records activity on incoming BLE audio packets and finalized batch recordings.
    • LocalRecordingsProvider: Records activity when local recordings are successfully uploaded.
  3. UI Integration:
    • DeviceSettings: Exposes a user toggle (Sync Health Alerts) with an active stalled badge and warning text when stalled.
    • HomePage: Sync indicator button switches to an amber disconnected cloud icon (Icons.cloud_off_rounded) when sync has stalled.
  4. Unit Tests:
    • Comprehensive unit test suite in app/test/unit/sync_health_watchdog_test.dart verifying all 9 gate, cooldown, quiet-hours, preference toggle, and throttle conditions.

Line-Count-Exception: app/lib/services/capture/capture_controller.dart | 3124 -> 3127 | record ble audio sync watchdog activity

Closes #15501
Failure-Class: none
PayPal: [email protected]

Review in cubic

@TheRWX
TheRWX requested a review from mdmohsin7 as a code owner September 23, 2026 18:53
@TheRWX
TheRWX force-pushed the feat/sync-health-watchdog-15501 branch from 8a2716c to 0543f44 Compare September 23, 2026 19:26
@TheRWX
TheRWX force-pushed the feat/sync-health-watchdog-15501 branch from 0543f44 to 7156188 Compare September 23, 2026 20:27
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @TheRWX — this addresses #15501, a severity:high community signal (10 reporters), and the implementation is solid: injectable clock and notification callback, sensible gate ordering, and a real unit suite (9 cases including cooldown, quiet hours, throttle, lifecycle). File-by-file notes below.

What looks good

  • app/lib/services/sync_health_watchdog.dart — clean singleton; evaluateSyncHealth orders its gates readably (noDevice → first-run seed → threshold → alerts-enabled → quiet hours → cooldown), and recordSyncActivity's 1-minute in-memory throttle avoids SharedPreferences churn per BLE packet.
  • app/test/unit/sync_health_watchdog_test.dart — covers the branches that matter: first-run seeding, 6h cooldown, 22:00–08:00 suppression, disabled toggle, throttle windows, timer lifecycle.
  • app/lib/providers/device_provider.dart — watchdog start/stop tied to provider construct/dispose; recording activity on connect and evaluating on disconnect are the right hooks.
  • app/lib/providers/local_recordings_provider.dart and app/lib/services/capture/capture_controller.dart — activity hooks are narrow one-liners in the right places (upload accepted, BLE audio, batch finalize).
  • app/lib/backend/preferences.dart — three new prefs via the existing get/save helpers, nothing exotic.
  • Widget-test stubs in app/test/widgets/device_settings_double_tap_test.dart and app/test/widgets/semantics_baseline_test.dart — honest isSyncStalled => false overrides keep the existing suites meaningful.

Design questions for a maintainer

  1. Stall semantics / false alarms. evaluateSyncHealth() only checks that a device is paired — there is no connectivity or expected-activity gate — while the activity signal comes from capture events (ble_audio, batch_recording_finalized). So "stalled" effectively means "paired but no capture for 4h", which is also the normal state of a pendant on a charger or in a drawer. Those users would get "Omi Not Syncing … Open Omi to check device connection" every 6 daytime hours, with the toggle defaulting to ON. Routine false alarms are the fastest way to get users to disable exactly this alert. Worth deciding whether stall should require recent connection/session evidence, or whether the copy should be softened.
  2. Coverage when the app is killed. The watchdog is a 30-minute Timer.periodic started from DeviceProvider's constructor, so it ticks only while the isolate is alive. If the OS suspends or kills the app (the "discovered gaps days later" case in the issue), nothing fires client-side. That may be an accepted scope for a first cut — just worth making it a conscious call.

Minor

  • app/lib/pages/home/page.dart: 'Sync stalled' is hardcoded English while the neighboring label uses context.l10n.sync — and this is the semantics/a11y label. Same for the Sync Health Alerts title/subtitle strings in app/lib/pages/settings/device_settings.dart.
  • DeviceProvider.syncHealth runs a full evaluation (including a first-run preference write) inside a getter that UI rebuilds hit; each call also JSON-decodes the stored device via SharedPreferencesUtil().btDevice.id. Caching the evaluation and notifying listeners would keep build-time cost flat.
  • The default NotificationService.instance.createNotification path has no test coverage (only the injected callback) — understandable given platform channels, just noting it.

Left for human maintainer review: this ships a default-on user-facing notification, and when "stalled" should fire (paired-but-idle vs. actual sync failure) is a product decision.


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 needs-maintainer-review Needs a human maintainer to sign off before merge flutter flutter work labels Sep 23, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (sync health watchdog + stall alerts) — approve only per policy; DIRTY, needs-maintainer-review.

@Git-on-my-level

Copy link
Copy Markdown
Member

Follow-up verification pass on the sync health watchdog work (head 7156188).

I went through all 10 changed files at the current head:

  • app/lib/services/sync_health_watchdog.dart - the watchdog core holds up well: paired-device gate returns noDevice, first-run seeding of lastSyncTimestamp avoids false alarms right after pairing, 4h stall threshold with a 6h alert cooldown, quiet-hours suppression (22:00-08:00), notification id 15501 with a navigate_to:/home payload, injectable onTriggerNotification for testing, and recordSyncActivity throttled to one SharedPreferences write per minute.
  • app/lib/backend/preferences.dart - three cleanly namespaced keys (syncAlertsEnabled default-on, lastSyncTimestamp, lastSyncAlertTimestamp); default-on is the right call for the data-loss scenario in [community-signal] sync-backup: silent multi-day recording loss on Android, no 'not syncing' alert #15501.
  • app/lib/providers/device_provider.dart - lifecycle wiring is correct: startWatchdog in the constructor, stopWatchdog in dispose, activity recorded on connect, health evaluated on disconnect, plus the syncHealth/isSyncStalled getters. The dropped flutter/foundation.dart import is covered by the material import.
  • app/lib/providers/local_recordings_provider.dart and app/lib/services/capture/capture_controller.dart - single-line activity hooks; ble_audio fires per BLE packet, which is fine given the in-memory throttle.
  • app/lib/pages/home/page.dart and app/lib/pages/settings/device_settings.dart - amber cloud_off state, live stalled chip/subtitle, and a keyed toggle; widget-test stubs updated accordingly.
  • app/test/unit/sync_health_watchdog_test.dart - good coverage of the gates, threshold boundary, cooldown, and quiet hours.

Three non-blocking observations for the record:

  1. evaluateSyncHealth only runs while the app process is alive (the watchdog timer lives in DeviceProvider). A stall while Omi is backgrounded or killed will not alert until the app is opened again - worth confirming that covers the [community-signal] sync-backup: silent multi-day recording loss on Android, no 'not syncing' alert #15501 scenario, since silent multi-day gaps often involve the app not being foreground.
  2. The new user-facing strings ('Sync stalled', 'Sync Health Alerts', 'Alert if Omi has not synced recordings for over 4 hours', the notification body) are hardcoded English while neighboring entries use context.l10n - a follow-up to route them through l10n would keep the app consistent.
  3. isSyncStalled is evaluated on read (evaluateSyncHealth(triggerNotification:false)) rather than being driven by notifyListeners, so the amber home-screen icon only refreshes when something else triggers a rebuild. Fine in practice, just noting the coupling.

@kodjima33's approval is on this exact head. With the above answered (mainly point 1), this looks good to land.


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

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (sync health watchdog + stall alerts) — approve-only per policy. Not merging.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (sync health watchdog + stall alerts) — approve-only per policy. mergeStateStatus DIRTY, not merging.

@TheRWX

TheRWX commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the approval. This branch now conflicts with main. Happy to rebase it onto current main to clear the conflicts (no behavior changes, tests re-run) — want me to go ahead?

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feature (sync health watchdog + stall alerts) — approve-only per policy; DIRTY so not mergeable regardless.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

feat(sync): health watchdog — feature with tests, mobile; approve-only

@Git-on-my-level

Copy link
Copy Markdown
Member

Thank you for this contribution @TheRWX — the watchdog design (persisted last-sync clock, cooldown, quiet hours, settings toggle) carried through to main in #23884, with your Co-authored-by trailer on the commits.

The re-implementation adapts it to the rulings that landed since this PR was opened: the stall now surfaces in Activity's Needs attention section and lights the bell dot rather than Home (#22119), the threshold moved from 4h to 24h so a pendant charging overnight never triggers a false alert, and the alert is scoped to pendant device types. Your unit test suite was ported and extended alongside.

Anyone wanting the final shape: #23884

Git-on-my-level added a commit that referenced this pull request Oct 28, 2026
### What does this PR do?

Re-implementation of community PR #17825 by @TheRWX (approved, but
conflicted and unmoved since 2026-10-05) on today's sync code and the
rulings that landed since. Fixes #15501: Android users silently lost
days of pendant recordings with no "device not syncing" warning; others
only sync when they open the app.

A new `SyncHealthWatchdog` (app/lib/services/sync_health_watchdog.dart)
watches the paired pendant's pipeline:

- **Activity signals.** BLE audio bytes arriving, a WAL accepted by the
server (`onWalSynced` — every upload path, manual and drain), a batch
recording finalized, and the pendant (re)connecting. Any of them proves
recordings are moving — audio is then safe on the phone or on the
server, and the #23679/#23822 drains (oldest-first, Retry-After, quiet
refusals) own recovery. Only silence across **every** signal is a stall
the user must hear about. Refusal-only stretches stay quiet by design: a
refusal with live ingestion is not data loss, and #23822 deliberately
keeps refusals out of user attention.
- **Stall threshold: 24 hours.** Longer than the longest normal daily
gap — a pendant taken off and charged overnight (~8–12h silent) — and
far inside the reported 4-day silent losses, with #23679's 30-day server
backfill window still far away. (The original 4h threshold would alert
every morning when quiet hours end.)
- **Alert cadence.** At most one reminder per day (24h cooldown), never
22:00–08:00 local (quiet hours do not spend the cooldown), notification
id 15501, tap lands on Device settings (`/settings/device`, the
capture-recovery push precedent). The silence clock seeds on first run,
so the app update itself cannot alarm.
- **Not a disconnect push (#3328).** No per-event notification; onboard
storage keeps recording across BLE drops. This alert fires only after a
full day of zero flow — the state where users actually lost data. Acute
stalls stay the wedge monitor's job in-app (connected-no-bytes within
minutes, upload silence at 2h with a backlog); this is the out-of-app
last resort.
- **Scope.** Paired pendant types only (`omi`, `friendPendant`); watches
and glasses sync on their own cadence. Ships on by default with a kill
switch ("Sync Health Alerts", Device Settings).

**Surfacing, per #22119** (capture/sync problems speak on the live
capture page and the Activity bell, never Home):

- Activity → Needs attention: "Omi isn't syncing · No recordings synced
for over N hours" (cloud-off row, opens Offline Sync; ordered after the
upload row as the broadest, slowest condition). Fed through
`CaptureWedgeMonitor.observeSyncSilence`, so the bell's unseen-dot
machinery is reused unchanged.
- Device Settings: the "Sync Health Alerts" toggle sits under the device
group; its subtitle switches to the live stall duration while stalled.
- The original PR's Home indicator is deliberately **not**
re-implemented.

The watchdog's periodic loop starts in app bootstrap (main.dart, after
prefs init); `DeviceProvider` wires each evaluation into the wedge
monitor and exposes `isSyncStalled`/`syncHealth`. Timer ownership stays
out of the provider so provider tests never hold a pending timer.

### Renders (headless visual-audit captures, synthetic state)

Activity — the new sync stall row:
![Activity sync stall
row](https://raw.githubusercontent.com/BasedHardware/omi/bf706226c6f7/.agent-artifacts/ui-evidence/cs-syncalerts/001-mobile-ios-activity-sync-stall.png)

Device Settings — the alert toggle with the stall subtitle:
![Device Settings stall
toggle](https://raw.githubusercontent.com/BasedHardware/omi/bf706226c6f7/.agent-artifacts/ui-evidence/cs-syncalerts/002-mobile-ios-device-stall-toggle.png)

Activity — the existing capture rows, unchanged by this PR:
![Activity capture rows
unchanged](https://raw.githubusercontent.com/BasedHardware/omi/bf706226c6f7/.agent-artifacts/ui-evidence/cs-syncalerts/003-mobile-ios-activity-capture-attention.png)

## Product invariants affected

- INV-DATA-1
- INV-CAP-1

INV-DATA-1 applies because `app/lib/main.dart` is a protected data-plane
routing authority; this PR only starts the watchdog's periodic timer
there after prefs init — no routing, endpoint, build define, or bundled
env value changes.

INV-CAP-1: touches `app/lib/services/capture/capture_wedge_monitor.dart`
only to add a slow-burn `CaptureSyncSilence` row (declared and ended
solely by the watchdog's evaluation) to Needs attention and the bell's
unseen logic. Ingress, retention and admission behavior are unchanged;
the new row makes no saved-audio claim.

## How it was verified

- `flutter test` (full hermetic `bash test.sh` CI suite): 7921 passed /
9 skipped; the single failure during the run was this PR's own new
visual-audit scenario before a fixture fix, green on re-run (`flutter
test test/visual_audit/visual_audit_smoke_test.dart`: 158 passed).
- New suites: `test/unit/sync_health_watchdog_test.dart` (device gating,
24h threshold arithmetic, daily cooldown, quiet hours, toggle, seeding,
throttle incl. no clock rewind, timer lifecycle) and new groups in
`test/services/capture/capture_wedge_monitor_test.dart` (sync-silence
row + bell) and `test/widgets/needs_attention_capture_test.dart` (row
render, absence, Offline Sync tap, ordering behind the upload row).
- `make mobile-verify ARGS="fast --all"`: 31/31 journeys passed
(full-suite fallback selected — cross-cutting `app/lib` change).
- `flutter analyze`: no new findings (pre-existing environment-only
errors in flavor-generated files aside, which `test.sh` bootstrap
generates).
- `python3 app/scripts/l10n.py check`: ok, 49 locales; 6 new keys via
the tool.
- `check_mobile_ux_contract.py` on the two touched UI files: clean.
- `tool/perf_shell.py --check`: PASS (shell regenerated for the
main.dart import).
- Renders above: `app/scripts/visual_audit.sh --head WORKTREE --only
activity-sync-stall,device-sync-stall-alerts,activity-capture-attention`.

## Not verified / limitations

- The watchdog evaluates only while the app process runs (the capture
foreground service keeps it alive on Android). If the OS kills the
process, no alert can fire until it runs again — the same boundary the
original PR had.
- The Activity row's hour count refreshes on watchdog ticks (30 min),
not per minute.
- No on-device run: all verification is hermetic (widget tests,
journeys, headless renders).

Line-Count-Exception: app/lib/backend/preferences.dart | 1612 -> 1630 |
three persisted sync-health keys: alert toggle, last activity timestamp,
last alert timestamp
Line-Count-Exception: app/lib/providers/device_provider.dart | 1624 ->
1663 | watchdog wiring, stall getters, connect/disconnect hooks
Line-Count-Exception: app/lib/services/capture/capture_controller.dart |
4602 -> 4609 | record sync-activity on BLE audio and batch finalization

Failure-Class: none

Closes #15501
Re-implements #17825 (original by @TheRWX, co-authored there)


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/23884?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/BasedHardware/omi/23884?returnTo=https%3A%2F%2Fgithub.com%2FBasedHardware%2Fomi%2Fpull%2F23884&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
YinkaAdepoju pushed a commit to YinkaAdepoju/omi that referenced this pull request Oct 28, 2026
Re-implements community PR BasedHardware#17825 (by @TheRWX) on today's sync code: a
full day of silence across every sync signal (BLE audio, WAL accepted by
the server, batch finalized, pendant connect) raises one local
notification, at most once a day, never at night, on by default with a
kill switch in Device Settings. The stall surfaces in Activity's Needs
attention section and lights the bell — never on Home (BasedHardware#22119) — and it
is not a disconnect push (BasedHardware#3328): it fires only when nothing has flowed
for 24 hours.

Co-authored-by: TheRWX <[email protected]>

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

flutter flutter work needs-maintainer-review Needs a human maintainer to sign off before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[community-signal] sync-backup: silent multi-day recording loss on Android, no 'not syncing' alert

3 participants