Account and cloud synchronization
VoiceStudio's account and cloud synchronization system lets a desktop user sign in, choose which cloud features to use, and carry approved settings and voice data between desktop clients. Electron main owns account trust and credentials, while the local backend owns the sync round and the renderer shows the account and sync state. See Backend API platform, Electron desktop, Electron workspaces, and Quality and contract testing for the neighboring system views.
Account boundary
The account boundary keeps cloud identity and credentials inside Electron main. It exposes only safe account state to the renderer and gives the local backend a short-lived capability only when cloud sync is allowed.
Account sign-in
The account flow connects the desktop app to VoiceStudio Cloud through an OpenID Connect sign-in. The user signs in in an external browser, then the app receives the result through a temporary loopback callback. The flow uses PKCE and drops a result that arrives after sign-out, cancellation, or account disablement.
The account service also reads the user's profile, personal Organization, plan, storage use, and feature entitlements. Cloud sync uses the personal Organization rather than an arbitrary organization selected by the renderer.
References: electron/…/account-session.ts• L82-123 electron/…/account-api.ts• L7-29 electron/…/account-ipc.ts• L42-46
Token and session handling
Electron main is the credential boundary. It keeps the refresh token out of the renderer and stores it only in protected desktop storage when encryption is available. Short-lived access tokens stay in memory and refresh before expiry. An invalid refresh grant ends the session, while a temporary auth failure marks the account offline without deleting the refresh token.
The local backend receives an access token only through a loopback bridge when sync is enabled and the selected backend is local. The bridge requires its private capability token, rejects browser-origin requests, and returns no token when the account or sync switch does not permit a cloud call. The backend asks the bridge for a token before each cloud request, so a switch-off takes effect even if the backend missed a stop notice.
References: electron/…/token-store.ts• L11-51 electron/…/account-session.ts• L137-191 electron/…/account-token-bridge.ts• L6-52 backend/…/cloud_account.py• L1-8 backend/…/client.py• L1-6
Cloud feature switches
Cloud account features are off by default. The account switch controls sign-in and all account calls. The sync switch is valid only when the account switch is on, so sync cannot remain active after account features are disabled.
The packaged application can keep cloud accounts dark until the product build enables them. When both switches and a valid session are active, Electron tells the local backend to start sync. The renderer runtime starts only when the account state and the backend sync status both permit it. It stops when either condition becomes false. Turning a switch off also stops active cloud requests and timers and clears the local account session when the account switch is disabled.
References: electron/…/cloud-switches.ts• L4-19 electron/…/cloud-config.ts• L36-60 electron/…/cloud-activity.ts• L31-45 electron/…/index.ts• L86-125 electron/…/cloud-sync-runtime.ts• L111-139
Synchronization boundary
The synchronization boundary joins the renderer's approved local values, the backend's durable sync state, and the VoiceStudio Cloud record service. It keeps collection choice and merge policy in the backend instead of treating the desktop database as a cloud database.
Sync scope
Synchronization is an explicit allowlist, not a mirror of the desktop database. Each approved item maps to selected local sources such as renderer storage, user preferences, or settings rows. Values outside that map remain device-local, including secrets, paths, hardware choices, engine choices, analytics identifiers, and local work-in-progress fields.
The current settings groups cover appearance, generation defaults, review, transcription, dictation, history, language-model routing, the global dictation shortcut, and gallery favorites. The user chooses the settings, shortcuts, and favorites collections independently. Collection choices are published per device so another device can inspect or reuse them.
References: backend/…/allowlist.py• L1-14 backend/…/allowlist.py• L296-343 backend/…/engine.py• L40-43 backend/…/engine.py• L145-159
Desktop-to-backend mirror
When account and sync are active and the backend reports sync as enabled, the renderer starts a runtime for the window. It asks the backend for the allowlisted local keys to mirror. It applies pulled values before it sends the current local snapshot. A sequence number on each write prevents a stale window from overwriting a value that the backend has already pulled from another device.
The local mirror distinguishes whole values from partly synced objects. A partial update changes only the approved fields and keeps device-local fields such as a clone draft or selected voice. Pulled values are marked as sync-originated, so applying them does not create an echo back to the backend. The runtime pulls again while the window is visible and asks the backend to run a round when the window gains focus. It also mirrors the dictation shortcut through the desktop capture bridge without treating an operating-system refusal as a new local edit.
This diagram shows how an approved renderer value moves through the local backend and the cloud sync engine.
flowchart LR
R[Renderer setting] -->|allowlisted write| L[Local backend mirror]
L --> E[Sync engine]
E -->|pull or push| C[VoiceStudio Cloud]
C -->|new sequence| E
E --> L
L -->|apply without echo| R
References: electron/…/cloud-sync-runtime.ts• L29-55 electron/…/cloud-sync-runtime.ts• L58-108 electron/…/cloud-sync-runtime.ts• L111-139 electron/…/synced-storage.ts• L17-24 backend/…/cloud_sync.py• L125-159
Sync rounds
The backend runs one serialized sync round at a time. A round first pulls changes for the chosen collections, applies them locally, then pushes queued local changes. Local edits trigger a short debounce. The visible renderer runtime also pulls on a short interval and asks the backend to run on window focus. Manual sync requests and server events can wake the round.
The engine keeps a cursor and a merge base for each cloud item. It uses conditional writes and idempotency keys so a retry does not create a second logical write. If the server cursor expires, the engine performs a full resync instead of assuming that its old cursor is still valid.
References: backend/…/service.py• L99-128 backend/…/service.py• L167-220 backend/…/engine.py• L160-185 backend/…/store.py• L103-178 electron/…/cloud-sync-runtime.ts• L93-102
Merge and conflict behavior
Sync uses a three-way merge between the last shared base, the current local value, and the remote value. If only one side changed a field, that change wins. If both sides changed the same field differently, the local value wins and the engine reports the field as a conflict. An edit beats a delete when the other side changed the item after the shared base.
Settings groups are singleton items. A remote tombstone or a missing singleton does not erase the user's local settings; it only removes the old merge base. Large delete sets also pause for user confirmation before they reach the cloud.
References: backend/…/merge.py• L25-70 backend/…/engine.py• L305-344 backend/…/engine.py• L367-381 backend/…/engine.py• L527-537
Voice data scope
Voice synchronization uses a stable sync ID so a voice record keeps the same cloud identity across desktop clients. Sync content includes user-facing voice metadata and consent evidence, but it excludes local database IDs, file paths, and hardware choices.
The voice record path emits content only when the record has an explicit attestation that the voice belongs to the user or that the speaker gave permission. Replacing reference audio clears the old consent, which prevents a prior approval from silently applying to a new speaker. Voice collection support is off by default, and voice files are a separate blob concern from the attested record metadata.
References: backend/…/record_ids.py• L1-26 backend/…/voices.py• L1-59 backend/…/engine.py• L40-43 tests/…/test_cloud_sync_voices.py• L57-98
Device and entitlement controls
Turning sync on registers the desktop as a cloud device and performs a pull before it pushes local data. Turning sync off stops the active engine but keeps the device identity and local merge state so the next start can continue. A user can revoke a listed device or choose another device's collection choices.
The cloud API can pause a collection when the account lacks its entitlement, stop a device that was revoked or lost membership, and report offline or storage-full state without discarding queued work. The sync client accepts only known VoiceStudio sync endpoints and retries one rejected access token through the account session.
References: backend/…/service.py• L244-283 backend/…/service.py• L320-365 backend/…/engine.py• L467-537 backend/…/client.py• L52-115
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the account switch, token bridge permission, backend start/stop notices, and renderer runtime condition aligned. A mismatch can leave the UI on while no sync call is allowed.
- Keep the backend allowlist, renderer storage mirror, partial-field rules, and local key format in sync. A new key can otherwise be silently ignored or overwrite device-local data.
- Keep collection schema support, merge-base handling, and unknown-field preservation aligned when changing synced record shapes.
- Keep stable record IDs and consent checks aligned before enabling voice records in a collection choice.
- Keep the known cloud endpoint list aligned with the desktop environment map. The client must not accept an arbitrary bridge-provided sync URL.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Account or sync is switched off during a request | Active cloud work is aborted and later backend calls send no token | CloudActivity.stopAll, the token bridge gate, and per-request token lookup |
| A refresh token is rejected | The desktop signs out and the renderer loses account and sync state | InvalidGrantError ends the session and clears stored credentials |
| Another device changes the same field | The local value remains and the field appears in the conflict status | Three-way merge with local-wins conflict reporting |
| A remote item uses a newer schema | The current app does not overwrite it or push its older shape | Per-collection supported versions and needs_update state |
| A sync cursor expires | Incremental history cannot be trusted | Full resync from cursor zero with local singleton values retained |
| A large delete request is created | The delete is held instead of removing many cloud records at once | Mass-delete threshold and explicit confirmation |
| A voice has no current consent attestation | Its record is not emitted to cloud sync | Consent-gated voice content generation |
Key files
| File | Why to read it |
|---|---|
| electron/…/account-session.ts | Account sign-in, refresh, expiry, cancellation, and sign-out state |
| electron/…/account-token-bridge.ts | The narrow boundary that gives the local backend short-lived access tokens |
| electron/…/cloud-switches.ts | Account and sync switch rules and persistence |
| electron/…/index.ts | Wiring between account state, cloud activity, the local backend, and the bridge |
| backend/…/cloud_sync.py | Desktop-only sync control and renderer mirror API |
| backend/…/allowlist.py | Approved settings and voice-adjacent local data scope |
| backend/…/service.py | Sync lifecycle, device setup, collection choices, and status |
| backend/…/engine.py | Pull, merge, push, retry, and failure behavior |
| backend/…/merge.py | Field-level conflict rules |
| backend/…/voices.py | Consent-gated voice record content |
| electron/…/cloud-sync-runtime.ts | Renderer activation, pull-before-mirror order, visible polling, focus triggers, and shortcut sync |
| electron/…/synced-storage.ts | Local storage interception and partial-value application |