Skip to content

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

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/cs-syncalerts
Oct 28, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/cs-syncalerts

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

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 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.
  • 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 fix(app): drain offline-sync history oldest-first and honor 5xx Retry-After #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 (Reduce unnecessary notifications for device disconnection #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

Device Settings — the alert toggle with the stall subtitle:
Device Settings stall toggle

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

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)

View guided diff Turn on auto-fix

Git-on-my-level and others added 2 commits October 28, 2026 18:10
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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T11:45:50.011985Z bf70622 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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))) ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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))) ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +97 to +99
_lastRecordedActivityAt = now;
SharedPreferencesUtil().lastSyncTimestamp = now.millisecondsSinceEpoch;
Logger.debug('SyncHealthWatchdog: activity from $source');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +165 to +166
SharedPreferencesUtil().lastSyncAlertTimestamp = currentTime.millisecondsSinceEpoch;
alertSent = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit d8fa0db into main Oct 28, 2026
50 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/cs-syncalerts branch October 28, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

1 participant