# feat(sync): add manual sync and repair sync controls in mobile settings

**URL:** <https://forum.rodydavis.dev/t/feat-sync-add-manual-sync-and-repair-sync-controls-in-mobile-settings/298>\
**Category:** Feature Requests\
**Tags:** enhancement, migrated\
**Created:** [November 15, 2026, 2:00am UTC](https://forum.rodydavis.dev/t/feat-sync-add-manual-sync-and-repair-sync-controls-in-mobile-settings/298 "2026-11-15T02:00:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.rodydavis.dev/images/discourse-logo-sketch-small.png) [@system](https://forum.rodydavis.dev/u/system)\
**Post date:** [November 15, 2026, 2:00am UTC](https://forum.rodydavis.dev/t/feat-sync-add-manual-sync-and-repair-sync-controls-in-mobile-settings/298/1 "2026-11-15T02:00:42Z")

</div>

> **Synced from GitHub:** [`hymns-for-worship/issues#242`](https://github.com/hymns-for-worship/issues/issues/242) opened by [**@headmasterditto**](https://github.com/headmasterditto) on `2026-11-15T01:45:12Z`

* * *

Hey all,

I noticed this evening that my song lists look to have stopped syncing – possibly a re-emergence of #240 – but in the process of trying to test things on my end I noticed that the manual sync/repair sync buttons that are available on the web profile don’t exist in the mobile app. Having that available would provide a quicker way of resetting the sync than the other available option of deleting and reinstalling the app.

---

<div class="post-metadata">

**Author:** ![rodydavis](https://forum.rodydavis.dev/user_avatar/forum.rodydavis.dev/rodydavis/32/8_2.png) [@rodydavis](https://forum.rodydavis.dev/u/rodydavis)\
**Post date:** [November 15, 2026, 11:06am UTC](https://forum.rodydavis.dev/t/feat-sync-add-manual-sync-and-repair-sync-controls-in-mobile-settings/298/2 "2026-11-15T11:06:05Z")

</div>

### Automated Issue Triage

**Metadata Updates:**

- Assigned label: `enhancement` (`58`)
- Formatted title: `feat(sync): add manual sync and repair sync controls in mobile settings`

**Codebase Analysis & Implementation Touchpoints:**

1. **Pigeon Native Bridge API Interface ([`hfw_native_api.dart`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/pigeons/hfw\_native\_api.dart#L628-L791))**:
  - In [`packages/hfw_flutter/pigeons/hfw_native_api.dart`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/pigeons/hfw\_native\_api.dart#L628-L791), declare `@async void triggerManualSync()` and `@async void repairSync()` on `HfwHeadlessFlutterApi`.
  - Expose sync status flags in `NativeAppStateDto` (such as `isSyncing: bool`, `isConnected: bool`, `isRepairingSync: bool`, `lastSyncRepairMessage: String?`) so native UI platforms can render real-time connection status badges mirroring the Jaspr web app.

2. **Headless Coordinator Self-Healing Sync Engine ([`hfw_headless_coordinator.dart`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/lib/src/native\_bridge/hfw\_headless\_coordinator.dart#L988-L1670))**:
  - In [`packages/hfw_flutter/lib/src/native_bridge/hfw_headless_coordinator.dart`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/lib/src/native\_bridge/hfw\_headless\_coordinator.dart#L988-L1670), implement `triggerManualSync()` to flush pending `ps_crud` operations, trigger a PowerSync sync cycle via `getIt<PowerSyncDatabase>()`, and push updated list/search states.
  - Implement `repairSync()` mirroring the web implementation in [`packages/hfw_jaspr/lib/services/web_app_store_web.dart`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_jaspr/lib/services/web\_app\_store\_web.dart#L1408-L1475):
    - Disconnect and reconnect the local `PowerSyncDatabase` connector.
    - Execute `_sanitizePsCrudQueue(preserveUserListsAndItems: true)` to purge poisonous/stuck non-list crud operations without dropping local user edits.
    - Re-trigger `_migrateGuestListsToUser(userId)` and `_reconcileLocalListsToServer(userId)`.
    - Refresh user authentication credentials via `_authService`.

3. **Native iOS Settings & Profile Views ([`HfwListsAndSettingsViews.swift`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/ios/Runner/HfwListsAndSettingsViews.swift#L3240-L3700) & [`HfwSearchViews.swift`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/ios/Runner/HfwSearchViews.swift#L2106-L2210))**:
  - In [`HfwAccountSettingsSheet`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/ios/Runner/HfwListsAndSettingsViews.swift#L3240-L3700), add a “Cloud Sync & Storage” card section displaying sync connection status, a “Sync Now” button, and a “Repair Sync & Clear Cache” option with explanatory subtitle (“Refreshes authentication, cleans stuck sync queues, and reconnects PowerSync without signing out”).
  - In [`HfwAuthSheet`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/ios/Runner/HfwSearchViews.swift#L2106-L2210), surface the quick sync trigger in `authenticatedProfileSections`.

4. **Native Android Compose Settings ([`HfwSettingsAndAuthComposeViews.kt`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/android/app/src/main/kotlin/com/appleeducate/hfw/HfwSettingsAndAuthComposeViews.kt))**:
  - In [`HfwSettingsAndAuthComposeViews.kt`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/android/app/src/main/kotlin/com/appleeducate/hfw/HfwSettingsAndAuthComposeViews.kt), add the equivalent “Cloud Sync” section in Compose settings with “Sync Now” and “Repair Sync” buttons hooked into `HfwStore`.

5. **Native Bridge Verification Tests ([`hfw_native_bridge_test.dart`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/test/native\_bridge/hfw\_native\_bridge\_test.dart))**:
  - Add unit tests in [`packages/hfw_flutter/test/native_bridge/hfw_native_bridge_test.dart`](file:///Users/rodydavis/dev/gitea-repos/rodydavis/hymns-for-worship/packages/hfw\_flutter/test/native\_bridge/hfw\_native\_bridge\_test.dart) validating that `triggerManualSync()` and `repairSync()` execute successfully and broadcast state changes.

---

<div class="post-metadata">

**Author:** ![rodydavis](https://forum.rodydavis.dev/user_avatar/forum.rodydavis.dev/rodydavis/32/8_2.png) [@rodydavis](https://forum.rodydavis.dev/u/rodydavis)\
**Post date:** [November 21, 2026, 6:34pm UTC](https://forum.rodydavis.dev/t/feat-sync-add-manual-sync-and-repair-sync-controls-in-mobile-settings/298/3 "2026-11-21T18:34:29Z")

</div>

### Implementation Plan & Research Summary

**Root-Cause Clue for Mobile Song-List Sync Stalls:**

- In `packages/hfw_flutter/lib/src/native_bridge/hfw_headless_coordinator.dart`, `_reconcileLocalListsToServer(userId)` (line 1611) is guarded by `_reconciledListUserIds.add(cleanUid)`, so it only runs **once** per app process.
- Additionally, `hfw_headless_coordinator.dart` does not subscribe to `PowerSyncDatabase.statusStream` or trigger `_database.connect()` on manual retry, leaving users with no way to recover a stalled PowerSync session short of reinstalling.

**Exact Pigeon Contract (`packages/hfw_flutter/pigeons/hfw_native_api.dart`):**

1. Add to `HfwHeadlessFlutterApi`:
  - `@async void triggerManualSync();`
  - `@async void repairSync();`

2. Add sync status fields to `NativeAppStateDto`:
  - `final bool isSyncing;`
  - `final bool isConnected;`
  - `final bool isRepairingSync;`
  - `final String? lastSyncRepairMessage;`  
_(Coordinate regeneration with #272’s Pigeon additions to avoid duplicate codegen.)_

**Mapping Web `syncNow()` / `repairSyncAndClearCache()` (`hfw_jaspr/.../web_app_store_web.dart:1402-1492`) to Mobile (`hfw_headless_coordinator.dart`):**

- Subscribe to `getIt<PowerSyncDatabase>().statusStream` in `_ensureInitialized()` to keep `isConnected` / `isSyncing` updated via `_pushAppState()`.
- **`triggerManualSync()`**:
  1. If authenticated, refresh auth/entitlements (`_refreshOfferingsAndEntitlements(refreshAuthSession: true)`), migrate guest lists (`_migrateGuestListsToUser(uid)`), clear `_reconciledListUserIds.remove(uid)`, and run `_reconcileLocalListsToServer(uid)`.
  2. Call `_database.connect()` (`packages/hfw_core/lib/src/services/powersync/database.dart:267-317`, which cleanly disconnects and reconnects `HttpPowerSyncConnector`).
  3. Push refreshed `_pushListsExplorerState()`, `_pushSearchState()`, and `_pushAppState()`.

- **`repairSync()`** (preserves local user lists/edits without signing out):
  1. Guard with `_isRepairingSync` flag and push state.
  2. Refresh auth token/session & entitlements; run `_migrateGuestListsToUser(uid)`.
  3. Clean transient guest history (`DELETE FROM user_hymn_history WHERE LOWER(COALESCE(user_id, '')) = 'local_guest'`) and run `_sanitizePsCrudQueue(preserveUserListsAndItems: _authService.isAuthenticated, targetUserId: uid)`.
  4. Clear `_reconciledListUserIds.clear()` and re-run `_reconcileLocalListsToServer(uid)`.
  5. Reconnect PowerSync via `_database.connect()` and refresh list/search/app state; set `lastSyncRepairMessage` and emit banner.

**Native UI & Tests:**

- **iOS** : Add a _Cloud Sync_ card in `HfwAccountSettingsSheet` (`HfwListsAndSettingsViews.swift`) with connection badge, **Sync Now** , and **Repair Sync & Clear Stale Cache** buttons (plus quick **Sync Now** in `HfwAuthSheet` in `HfwSearchViews.swift`).
- **Android** : Add matching _Cloud Sync_ controls in `HfwSettingsAndAuthComposeViews.kt` wired through `HfwStore`.
- **Tests** : Add unit tests in `packages/hfw_flutter/test/native_bridge/hfw_native_bridge_test.dart` covering `triggerManualSync()`, `repairSync()`, and preservation of `user_lists`/`user_list_items` in `ps_crud`.

---

<div class="post-metadata">

**Author:** ![rodydavis](https://forum.rodydavis.dev/user_avatar/forum.rodydavis.dev/rodydavis/32/8_2.png) [@rodydavis](https://forum.rodydavis.dev/u/rodydavis)\
**Post date:** [November 21, 2026, 7:55pm UTC](https://forum.rodydavis.dev/t/feat-sync-add-manual-sync-and-repair-sync-controls-in-mobile-settings/298/4 "2026-11-21T19:55:58Z")

</div>

Landed in commit `101b79e` on `main`: added `triggerManualSync()` and `repairSync()` Pigeon RPCs + live PowerSync `statusStream` fields (`isSyncing`, `isConnected`, `isRepairingSync`, `lastSyncRepairMessage`) in `hfw_headless_coordinator.dart` (with forced `_reconcileLocalListsToServer` and `hfw_jaspr` repair parity), and wired Cloud Sync controls (status badge, Sync Now, Repair Sync with confirmation, feedback message) in both iOS `HfwAccountSettingsSheet` and Android `HfwSettingsAndAuthComposeViews.kt`. Verified across Flutter tests (41/41), iOS `xcodebuild`, and Android Gradle tests.

---

<div class="post-metadata">

**Author:** ![rodydavis](https://forum.rodydavis.dev/user_avatar/forum.rodydavis.dev/rodydavis/32/8_2.png) [@rodydavis](https://forum.rodydavis.dev/u/rodydavis)\
**Post date:** [November 21, 2026, 8:00pm UTC](https://forum.rodydavis.dev/t/feat-sync-add-manual-sync-and-repair-sync-controls-in-mobile-settings/298/5 "2026-11-21T20:00:30Z")

</div>

> **[@rodydavis](https://github.com/rodydavis)** commented on [GitHub](https://github.com/hymns-for-worship/issues/issues/242#issuecomment-7068420305) at `2026-11-21T19:59:12Z`:

Thanks for the suggestion! We’ve added a **Cloud Sync** section in mobile Settings (iOS & Android) showing live sync status along with **Sync Now** and **Repair Sync** controls—matching the web app—plus a fix for song lists stalling on sync. This will be available in the next app update.

---

<div class="post-metadata">

**Author:** ![system](https://forum.rodydavis.dev/images/discourse-logo-sketch-small.png) [@system](https://forum.rodydavis.dev/u/system)\
**Post date:** [November 28, 2026, 12:59am UTC](https://forum.rodydavis.dev/t/feat-sync-add-manual-sync-and-repair-sync-controls-in-mobile-settings/298/6 "2026-11-28T00:59:05Z")

</div>

Closed on November 28, 2026, 12:59am UTC


