VoiceStudio is the open-source, fully-local ElevenLabs alternative — voice cloning, voice design, video dubbing, dictation, transcription & audiobook creation in 646 languages.
Cloud Settings Sync (S1) Implementation Plan
For agentic workers: executed inline (superpowers:executing-plans) by the same session that wrote it. Each task is test-first; the tests named per task are the contract.
Goal: Sync settings, shortcuts, and gallery favorites between a user's devices through VoiceStudio Cloud (/v1/sync), opt-in per device, and stopped at once by the S0 switches.
Architecture: A backend package backend/services/cloud_sync/ runs the engine: pull GET /changes, apply with a three-way merge against the last agreed version, then push the outbox with If-Match. It reads every token through services.cloud_account.access_token(), so main's switches stay the single gate. Local values come from three stores. prefs.json and the settings table are hooked in the backend. Renderer localStorage is mirrored into the backend by a renderer syncedStorage wrapper, and pulled values flow back to the renderer the same way. When sync is switched off, main tells the backend to stop at once.
Tech stack: Python 3 (httpx async, sqlite3, Alembic), FastAPI router, React renderer, Vitest and pytest.
Spec: account_login/desktop-app-guide.md §3–8 and §10, account_login/sync-api.md, and account_login/sync-collections.md. These are git-ignored copies; the canonical versions are in vssaas docs/specs/.
Builds on: docs/superpowers/plans/2026-10-16-account-sign-in-and-cloud-switches.md (S0).
Global constraints
- Off means off. Every Cloud request asks
cloud_account.access_token()first, andNonemeans make no call. Main'sPOST /api/cloud-sync/stopcancels the loop, the event stream and timers at once. Local data is never deleted when sync stops. - Never sync secrets (
secret.*,hf_token), absolute paths, hardware or engine choices (compute_device,*_backend, model IDs), the analyticsinstallation_id, or the device-local keys insync-collections.md. - IDs are 16 Base62 characters from
secrets.choice. Idempotency keys are made once per outbox row, reused on retry, and replaced after a409. - Applying a pulled change never re-queues it. The
from_synccontext suppresses the hooks. - Never run two rounds at once. The outbox holds one row per item.
- Values are compared as canonical JSON: sorted keys, no whitespace.
- Localization: every new string goes into all 21 locales. Parity rule: the same behaviour on all OSes.
- Commits carry no AI attribution (CLAUDE.md).
Rulings (made while planning)
- Table names. Tables are
cloud_sync_state,cloud_sync_items,cloud_sync_outboxandcloud_sync_local(the renderer mirror), not the guide'ssync_*. VoiceStudioPro already has async_statetable (migration 0019, folder sync) with another schema, and both apps share this code. Cost if wrong: renaming four tables. - Device and Organization. The token bridge answer also carries
organization_id(personal_organization_id) and thesync_apibase URL, so the backend needs no environment table of its own. - Renderer stores. Renderer keys reach the backend over the renderer's existing loopback HTTP channel (
apiJson), not through main. Renderer → backend is the path every other renderer setting already uses. Cost if wrong: none; the guide's "via main" was a suggestion. - Favorites.
voicestudio.gallery.favorites.v1is an ID array, so the mirror recordsadded_atthe first time it sees each ID. - Shortcuts.
shortcuts.globalmapsdictation.toggleto the renderer bridge'scaptureshortcut API, applied through the existing setter, so main's file stays the one writer. dictationgroup. This list is sent back tovssaas(S1-23):aecEnabled(localStorage), plus prefsdictation.mode,dictation.enabledanddictation.prompt. Excluded:dictation.model_idanddictation.silent_models(engine choices) and the input device.- Plan style. This plan gives interfaces and test contracts rather than full code. The same session executes it immediately, so writing the code twice would only duplicate it.
Tasks
- IDs and merge (
cloud_sync/ids.py,cloud_sync/merge.py). Providesnew_sync_id(),canonical(v), andmerge3(base, local, remote) -> Merge(values, conflicts). Item level:merge_item(base, local, remote)handles tombstones, where an edit beats a delete. Tests: the guide's six cases plus every row of the §7 table. - Allowlist (
cloud_sync/allowlist.py). It holds the item definitions forsettings(appearance, generation-defaults, review, transcription, dictation, history, llm),shortcuts.global,favorites.galleryanddevice-preferences. Providesread_values(collection, item_id)andwrite_values(collection, item_id, values), sourced from prefs, the settings table and the renderer mirror. Also providesitems_for(choices)andRENDERER_KEYS. Tests: every allowlisted key has a reader and a writer; denied keys are never read; projection keeps the excludedclone.settingsfields; llm reads no secret. - Local tables (alembic
0014_cloud_sync,_BASE_SCHEMA,cloud_sync/store.py). Covers state, items (the merge base), the outbox (unique per item) and the renderer mirror with a sequence number. Tests: upgrade from a pre-0014 snapshot; outbox upsert keeps one row and its key; the mirrorsincequery. - Change hooks (
core/change_hooks.py, plusprefs,settings_storeand the mirror router call it). Providesnotify(source, key),from_sync()context, andsubscribe(cb). Tests: each allowlisted key emits exactly one change; a write insidefrom_syncemits none; a non-allowlisted key emits none. - API client (
cloud_sync/client.py). An asynchttpxclient covering devices, collections, usage, changes,put/delete/batch, and errors mapped toSyncApiError(status, code, details, retry_after). Tests: request shapes and headers throughhttpx.MockTransport; error mapping includingRetry-After; theIf-Matchencoding. - Engine (
cloud_sync/engine.py). Providesrun_once,pull(with paging and the cursor saved alongside the applied items),apply_remote, andpush, which handles409merge-and-retry (3 rounds),413(pause and show "full"),403(not_entitled/collection_disabled/device_revoked/account_suspended),429and5xx. It also covers the first-sync merge with an empty base, full resync on410, batching when more than 10 rows wait, the mass-delete guard (>20 or >25% of a collection), conflict notes, and a single-round lock. Tests: the guide's §11 items 5–7 (merge, outbox, pull) against a fake server. - Event stream (
cloud_sync/events.py). An SSE parser plus a runner with a 60 s stall timeout, backoff of 1–60 s with ±20% jitter,bye/revokedhandling and a 60 s poll fallback. Tests: the parser handleshead, comments,byeandrevoked; stall triggers a reconnect; the backoff sequence. - Service and router (
cloud_sync/service.py,api/routers/cloud_sync.py,main.pywiring, the bridge answer extended). Routes under/api/cloud-sync:status,PUT choices(turn on, toggles, "also remove from the cloud"),run,stop,devices,devices/{id}/revoke,confirm-deletes,use-choices-of/{device_id}, andlocalGET/PUT for the renderer mirror. Tests: no Cloud call without a token;stopcancels the loop and the stream; turning sync back on does a full pull before any push; the router contract. - Main. On
syncEnabled→ off, main POSTs/api/cloud-sync/stopto the local backend; it never does this for a remote one. The bridge carriesorganization_idandsync_api. Tests: switch-off calls stop; remote mode makes no call; the bridge payload. - Renderer.
syncedStorage(wrapssetItem/removeItemforRENDERER_KEYS, posts to the mirror, applies pulled values with astorageevent), the shortcut bridge, and Settings → Account → Sync: "Choose what to sync" with Pro locks, paused rows, sizes and "Use the same choices as …", the Devices list with Remove, the guide §10 messages, the mass-delete confirm and the conflict notice. All strings in 21 locales. Tests: the wrapper posts once per change and never echoes a pulled value; the UI states. - Docs and verification.
HANDOFF.mdrecords the S1-23 dictation list;STRUCTURE.mdservice count; full suites.