Skip to content

Re-target Pro cloud-sync when switching the active database (ADR-053) - #1714

Merged
mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:worktree-issue-1711-switch-activate-sync
Jul 23, 2026
Merged

mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:worktree-issue-1711-switch-activate-sync

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #1711. Part of the per-database cloud-sync epic (#1535). The daemon-side single-active sync + ActivateDatabase RPC are done in nodespace-sync (#350–#358, merged).

⚠️ HOLD — do not merge yet. Per the author's request this stays open for on-device validation first (the switch → sync-retarget → pill behavior needs the running Tauri app). The change is unit-tested + reviewed; only the interactive end-to-end check remains.

What

databaseStore.switchTo(id) re-points the routed gRPC clients via set_active_database (the data plane) but never told the Pro daemon to move its cloud-sync session — so switching database in the app changed which database is read/written while the daemon kept syncing the boot tenant. This wires the switch to the daemon's single-active ActivateDatabase RPC.

  • Mirror the ActivateDatabase RPC + messages into the desktop's pro proto copy.
  • Add pro_activate_database(database_id) Tauri command → CloudSyncService.ActivateDatabase; no-ops in community mode (no ProClient), matching the other pro_* commands, so the community DB switcher is unaffected.
  • switchTo calls it after set_active_database, best-effort: a re-target failure is logged and does not abort the already-committed routing switch.

Desktop-only.

Test plan

  • bun run test — the database-store tests assert the switch re-targets sync (pro_activate_database invoked with { databaseId }) and still completes when the re-target fails. nodespace-app compiles (proto regenerates). Pre-push gate (test:all + cargo build + test:e2e) green.
  • On-device (pending, the reason this is held): with a Pro daemon + ≥2 bound databases, switching database in the app re-targets sync to the new tenant (Realtime/pill follows). The backend RPC is already headless-validated in nodespace-sync.

Review

Independently reviewed (adversarial): proto parity byte-for-byte vs the daemon; command no-ops in community; switchTo wiring is genuinely best-effort; snake/camel arg convention correct; frontend tests cover both paths. No defects found.

Scope

The tenant/database picker UI + per-DB sync pill (builds on #1536/#1537) are separate — this is only the switch→sync wiring.

…#1711)

`databaseStore.switchTo(id)` re-points the routed gRPC clients via
`set_active_database` (the data plane) but never told the Pro daemon to move its
cloud-sync session, so switching database in the app changed which database is
read/written while the daemon kept syncing the boot tenant. Wire the switch to
the daemon's single-active `ActivateDatabase` RPC (shipped in nodespace-sync).

- Mirror the `ActivateDatabase` RPC + messages into the desktop's pro proto copy.
- Add a `pro_activate_database(database_id)` Tauri command that forwards to
  `CloudSyncService.ActivateDatabase`; no-ops in community mode (no `ProClient`),
  matching the other `pro_*` commands' side-effect-free contract, so the
  community database switcher is unaffected.
- `switchTo` calls it after `set_active_database`, best-effort: a re-target
  failure is logged and does not abort the already-committed routing switch.

Desktop-only. Frontend tests assert the switch re-targets sync and still
completes when the re-target fails. The tenant/database picker UI + per-DB sync
pill (builds on the tray DB menu / registry-driven Pro UI) are separate.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE

Independent adversarial review — all 5 verification points pass, nothing merge-blocking:

  • Community-mode safe (try_state::<ProClient>() None → Ok(()), no panic/error).
  • Best-effort in switchTo: try/catch after the supersede guard and activeDatabaseId = id, so a superseded switch never re-targets and a failure doesn't abort the committed routing switch.
  • Proto is byte-for-byte wire-compatible with the daemon proto (field numbers/names match); empty database_id = deactivate documented both sides.
  • Command registered in the Tauri handler list.
  • Test arg-name { databaseId: 'b' } matches Tauri v2 camelCase→snake_case (established convention).

One low-severity, non-blocking note: the new await invoke('pro_activate_database') adds a suspension point to a previously-synchronous switch tail with no seq !== switchSeq re-check after it — two rapid switches could interleave their activate RPCs briefly. Self-heals on the next switch (daemon ActivateDatabase is single-active + idempotent); worth a one-line re-check if tightened later. Device-validated both directions.

@mstomar125
mstomar125 merged commit 103b4e1 into NodeSpaceAI:main Jul 23, 2026
mstomar125 added a commit that referenced this pull request Jul 23, 2026
…d-persist (closes #1722) (#1725)

- Settings entry below Favorites in the sidebar (layout nav item + navigation-sidebar
  handler → shared open-settings.ts).
- The top-left database switcher becomes a read-only indicator that opens
  Settings → Database (no inline tenant switching); the Database settings section
  explains a database is a local store syncing to one cloud tenant, shows per row
  "Syncs to tenant · X" / "Local only", and switches via an explicit Open button.
- Per-row bound tenant is full-stack: DatabaseInfo.bound_tenant_schema (proto),
  populated by the daemon's database_service.rs, surfaced through the Tauri
  commands/database.rs DTO and the database.svelte.ts store, rendered per row — so
  a database and its tenant are never confused.
- Reload-persist: the active database is remembered in localStorage and restored on
  load, so a refresh no longer snaps back to the default database.

Builds on Slice C (#1714). Follow-ups: #1720 (multi-DB-per-tenant design), #1721
(invitations popup gating).

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ADR-053] Wire in-app database switch to re-target Pro cloud-sync (ActivateDatabase)

1 participant