Seedworks Labs Wiki The engineering referenceStudio website ↗
Coconut

Cloud sync & hosted web

Outbox, pull application, repair sync and account-bound browser caches.

Engineering documentation • Reviewed 2026-11-29

Sync is an optional transport, with a hosted exception#

Local/native Coconut can work from SQLite without cloud sync. Official builds default to SeedWorks Cloud; self-hosters can configure their own Supabase URL and public key. sync/supabase.ts creates the client and manages native/password authentication, while hosted web uses a dedicated OAuth-backed client.

The hosted build requires an account and binds the browser cache to that verified account. It is not simply the local web export uploaded unchanged.

Engine entry points#

engine.ts exports:

Function Work performed
syncPersonalChanges Incremental personal outbox push and watermark-based pull
syncSharedChanges Lightweight shared outbox push/pull, mirror reconciliation and selected identity settings
syncNow Full repair/reseed path for shared and personal datasets
isSyncRunning, isSharedSyncRunning State probes for the corresponding pending operations

All phases are placed on one internal promise queue. Each public operation also reuses its pending promise to avoid duplicate overlapping invocations. A failed task does not permanently poison the queue.

Before remote work, the engine checks enablement, session and dataset identity. ensureSyncIdentity prevents an already-bound local dataset being casually uploaded under another account.

Incremental personal flow#

load sync configuration and verified user
ensure identity binding
capture startedAt before network work
mark status syncing
reconcile shared mirrors
push local changes
pull remote changes since overlapping prior watermark
reconcile mirrors again
save startedAt as last successful watermark
schedule usage reporting

time.ts owns timestamp helpers and overlap calculation (pullSince). Capturing the watermark before network calls avoids advancing past a concurrent write that happened during the sync.

This is timestamp-oriented row synchronization, not a CRDT or a globally serializable transaction spanning SQLite and PostgreSQL. Inspect comparison and retry rules when analyzing simultaneous-device edits.

Push: domain rows become remote payloads#

push.ts reads queued row keys, loads local rows, builds UUID maps and invokes table adapters from serialize.ts. Parent integers become remote UUID references; user ownership is applied to the remote record.

Tombstones communicate deletion independently from upserted rows. Selected settings have their own push path. A full sync can backfill identities and enumerate existing rows so data predating installed change-capture triggers is not silently omitted.

Do not equate “outbox is empty” with “the cloud contains every historical row.” That assumption is exactly why the repair path exists.

Pull: remote payloads become local relationships#

pull.ts and pull.web.ts fetch remote rows/tombstones, resolve UUID references and apply records under guarded local writes.

Important helpers include:

  • loadFkMaps / pullFkResolver: map remote parent identities to local IDs.
  • findNaturalMatch: reconcile records with domain/natural uniqueness.
  • findSharedMirrorByOrigin: recognize a mirror by shared-source identity.
  • captureInsertedParent: extend maps as parents arrive.
  • hasUnresolvedFk, fetchMissingParents, repairNullableFks: detect and repair missing relationships rather than treating a missing parent as valid unrelated data.
  • pullSettings / applySettings: handle settings separately from ordinary row adapters.

Children must not receive a remote numeric parent ID. The local ID can differ across every device. Pull application also suppresses change-capture feedback and uses platform-specific database coordination.

Shared and full sync ordering#

syncSharedChanges keeps shared_last_sync_at separately in sync_meta. It pushes only changed shared rows, pulls changes, reconciles mirrors, and synchronizes username/language settings. An identity used by Shared Spaces should not require waiting for a full personal sync.

The full syncNow order is:

  1. Full shared push.
  2. Shared pull.
  3. Reconcile personal mirrors.
  4. Full personal push.
  5. Personal pull from the epoch, deliberately rereading historical rows.
  6. Reconcile mirrors again.
  7. Save both successful watermarks and report usage.

That second reconciliation is not redundant: pulling a personal mirror can otherwise restore an old month assignment after shared data was already processed.

Scheduling and change notifications#

scheduler.ts, cloud-change-sync.tsx and the provider connect application activity/local edits to sync requests. change-notifications.ts handles cloud-change subscriptions. Notifications trigger reconciliation; they are not a replacement for pulling durable state.

The local backend tree includes a newer coconut_sync_notifications migration. It was untracked at this review, so the wiki does not claim it is installed in production. See backend migration status.

Hosted bootstrap and browser lifecycle#

hosted-web-gate.web.tsx controls access to the account-required application. hosted-account-client.web.ts owns the single hosted SDK client and OAuth refresh adapter.

openHostedAccountCache connects verified identity with the correct local cache. hosted-web-sync.web.tsx coordinates hosted sync lifecycle. These boundaries matter on reload, sign-out and account switching: a previous user's SQLite cache is not a new user's dataset.

The OAuth chapter describes code exchange and token verification. The storage chapter describes Web Locks and tab ownership.

Failures and recovery#

Engine failures update sync status/error and propagate SyncError; an authentication-specific failure can return without treating it as an ordinary data-sync error. Offline financial editing remains local on supported local/native paths.

For a missing row, trace local UUID → outbox/identity → serialized payload → remote authorization → pull watermark → FK resolution → provider refresh. For an authentication failure, trace the session/client before retrying writes.

A full sync is a repair mechanism, not a backup restore and not a blanket conflict-resolution promise. Never delete local data as the first troubleshooting action.

Hosted deployment is separate#

Coconut's Pages workflow consumes the release web ZIP and verifies its checksum. The main website does not host a copy under /apps/coconut/web/. Old-origin browser data does not automatically move to the subdomain.

The detailed operational contract is docs/hosted-web.md. That file and the workflow had local modifications at review time; inspect the actual release artifact and deployed revision before relying on a particular rollout step.