Repository navigation
feat(sync): sync health watchdog and stall alerts (#15501) - #23884
Conversation
Re-implements community PR #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 (#22119) — and it is not a disconnect push (#3328): it fires only when nothing has flowed for 24 hours. Co-authored-by: TheRWX <[email protected]>
…nchanged capture rows) Co-authored-by: TheRWX <[email protected]>
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf706226c6
ℹ️ 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".
| final acute = acuteEpisode; | ||
| hasUnseenCaptureAttention.value = (storage != null && (seen == null || storage.engagedAt.isAfter(seen))) || | ||
| (upload != null && (seen == null || upload.since.isAfter(seen))) || | ||
| (sync != null && (seen == null || sync.since.isAfter(seen))) || |
There was a problem hiding this comment.
Include sync silence in Activity's seen snapshot
When sync silence is the only capture-attention condition, opening Activity never acknowledges it. ActivityPage.build computes builtThrough from storage, upload, and acute episodes only, so it never calls markCaptureAttentionSeen for this new row. Consequently, the bell's warning dot remains lit even after the user reads the stall. Include the sync-silence episode in that snapshot so viewing its row clears the unread indicator.
Useful? React with 👍 / 👎.
| final acute = acuteEpisode; | ||
| hasUnseenCaptureAttention.value = (storage != null && (seen == null || storage.engagedAt.isAfter(seen))) || | ||
| (upload != null && (seen == null || upload.since.isAfter(seen))) || | ||
| (sync != null && (seen == null || sync.since.isAfter(seen))) || |
There was a problem hiding this comment.
Track when a sync stall is declared for unread detection
If the user views another capture-attention row after the last sync activity but before the 24-hour stall threshold, _captureAttentionSeenAt is newer than sync.since. When the watchdog subsequently declares the sync stall, this comparison treats the newly added row as already read, so the bell never warns about it. Keep the last-activity timestamp for the duration text, but use a separate declaration timestamp for unread detection, as acute episodes already do.
Useful? React with 👍 / 👎.
| _lastRecordedActivityAt = now; | ||
| SharedPreferencesUtil().lastSyncTimestamp = now.millisecondsSinceEpoch; | ||
| Logger.debug('SyncHealthWatchdog: activity from $source'); |
There was a problem hiding this comment.
Publish recovery when sync activity resumes
After a stall has been declared, reconnecting the pendant, receiving BLE audio, or completing an upload only updates the persisted timestamp here; none of those activity paths publishes a healthy evaluation. With the default 30-minute watchdog interval, Activity can therefore continue claiming that no recordings have synced for over a day, and Device Settings can keep showing the stalled state, for nearly half an hour while recordings are actively flowing. Reevaluate or publish recovery on the first activity that ends a declared stall, without adding per-frame evaluations.
Useful? React with 👍 / 👎.
| SharedPreferencesUtil().lastSyncAlertTimestamp = currentTime.millisecondsSinceEpoch; | ||
| alertSent = true; |
There was a problem hiding this comment.
Start the alert cooldown only after notification acceptance
When notification permission is denied, NotificationService.createNotification explicitly returns false without displaying anything, but this code discards that result and persists a successful dispatch anyway. If the user subsequently enables notifications while the stall persists, the watchdog suppresses the alert for the remainder of the 24-hour cooldown despite never having notified them. Check the asynchronous result before advancing lastSyncAlertTimestamp and reporting alertDispatched, with an in-flight guard if needed to prevent duplicate sends.
Useful? React with 👍 / 👎.
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: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 fix(app): drain offline-sync history oldest-first and honor 5xx Retry-After #23679/fix(sync): quiet upload refusals and bound Catching up spans #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 fix(sync): quiet upload refusals and bound Catching up spans #23822 deliberately keeps refusals out of user attention./settings/device, the capture-recovery push precedent). The silence clock seeds on first run, so the app update itself cannot alarm.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):
CaptureWedgeMonitor.observeSyncSilence, so the bell's unseen-dot machinery is reused unchanged.The watchdog's periodic loop starts in app bootstrap (main.dart, after prefs init);
DeviceProviderwires each evaluation into the wedge monitor and exposesisSyncStalled/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:

Device Settings — the alert toggle with the stall subtitle:

Activity — the existing capture rows, unchanged by this PR:

Product invariants affected
INV-DATA-1 applies because
app/lib/main.dartis 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.dartonly to add a slow-burnCaptureSyncSilencerow (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 hermeticbash test.shCI 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).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 intest/services/capture/capture_wedge_monitor_test.dart(sync-silence row + bell) andtest/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-cuttingapp/libchange).flutter analyze: no new findings (pre-existing environment-only errors in flavor-generated files aside, whichtest.shbootstrap generates).python3 app/scripts/l10n.py check: ok, 49 locales; 6 new keys via the tool.check_mobile_ux_contract.pyon the two touched UI files: clean.tool/perf_shell.py --check: PASS (shell regenerated for the main.dart import).app/scripts/visual_audit.sh --head WORKTREE --only activity-sync-stall,device-sync-stall-alerts,activity-capture-attention.Not verified / limitations
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)