Lesson 8: Sync & Accounts

Goal of this lesson

Explain guest vs. account use, the outbox pattern, how conflicts are detected, and exactly what syncs.

Guest vs. account

GuestSigned-in account
Identitylocal_guest_user on this phoneCloud account (backend, Neon)
Planner, alarms, reminder calls✅✅
Offline voice, local Ask USTP✅✅
Sync across phone and PC❌✅
Online AI, online voice, documents❌✅ (Online Mode, subject to account access and limits)

Upgrading: when a guest signs in or registers, their tasks, notes, schedule, and chats are carried over to the account once, without duplicates.

The outbox pattern

Student saves a change Manual edit or confirmed review card
ONE SQLite transaction ① update the record table ② add a sync_outbox entry
UI updates immediately No waiting for the server
Signed in AND connected?
no
Wait Outbox keeps the change
yes
Sync worker sends a batch Authenticated /v1/sync/batch
Server acknowledges + sends remote changes Cursor moves forward. Conflicts recorded
Incoming changes applied locally Validated, and not re-queued as new local changes

Why one transaction?

If the record were saved but the outbox entry wasn’t (for example, if the app crashed in between), that change would never sync. Writing both together means either both happen or neither does. This is called the transactional outbox pattern.

Versions and conflicts

Each synced record has a version. A local change remembers the base version it was edited from.

Local change sent with its base version
Does the server still have that version?
yes
Accepted New version returned
no, someone else changed it
Conflict recorded Both copies kept in sync_conflicts (local + server version)

Nothing is silently overwritten. The conflict stores the local payload, base version, server version, and server payload.

What syncs and what doesn’t

Syncs (7 entity types)Stays on the device
profileAlarm clocks
tasksFloating LAFINA settings and most local settings
eventsDownloaded models, recordings, attachments
time blocksDelivery jobs and history
remindersHandbook index
notes
custom categories

Chats sync separately through chat history sync, up to 20 chats per account.

Sync is not a full backup

Clearing app data or uninstalling removes device-only content such as alarms and recordings. Sign Out and Clear All Data remove local leftovers thoroughly.

Check yourself

  • What can a guest do, and what can’t they do?
  • Explain the transactional outbox in one sentence. What problem does it prevent?
  • How is a conflict detected, and what is stored when it happens?
  • Name the 7 sync entity types. Name 3 things that never sync.