Repository navigation
Add synced-database-from-cloud flow: BindTenant + tenant discovery - #2555
Conversation
Vendors the updated nodespace_pro.proto exposing BindTenant and ListTenantMemberships (already implemented in nodespaced-pro; this repo's copy predated both), and adds two Tauri commands wrapping them: pro_list_tenant_memberships (tenant discovery for the picker) and pro_bind_tenant (bind a local database to a tenant, activate-on-bind). Adds an "Add synced database" dialog in Settings -> Database: checks/awaits sign-in via GetIdentity (not the per-database proSync store, whose 'local-only' override would misreport a genuinely-signed-in session when the currently-active database happens to be unbound), lists active tenant memberships, creates a new local database, mints a private RESTRICTED landing collection for it (BindTenant rejects a non-empty schema with an empty collection and does not auto-mint one, and ListJoinableCollections is scoped to whichever tenant is already syncing, so a first-time bind has no existing collection to discover), then binds. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Retry on a bind-stage failure now resumes confirmBind instead of restarting the whole wizard from the identity check: createdDatabaseId and mintedCollectionId are tracked and reused across a retry, so a flaky BindTenant call no longer piles up a fresh orphaned local database and "My Workspace" collection on every attempt. The dialog can no longer be dismissed while a bind is in flight. Dialog.Root's onOpenChange is a notification, not a veto -- bits-ui's dialog state is a $bindable the primitive mutates directly on every dismiss interaction before the callback runs, so an attempted onOpenChange guard does not actually prevent the close. Uses Dialog.Content's escapeKeydownBehavior/interactOutsideBehavior set to 'ignore' during the binding step instead (bits-ui's actual extension point for this), plus hiding the close button, since none of create/switchTo/mint/bind are safely abortable mid-flight. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Addressed both review nits (confirmed as real flow-control bugs, not just nits):
Added 3 new tests (retry-reuse, retry-restart-on-identity-failure, dismiss-during-bind), individually mutation-tested (5 targeted mutations, all caught). Full |
|
Re-reviewed (focused pass on the two fixes): both genuinely verified against the actual code, not just the description. Fix 1's retry-reuse traced end to end — the guarded IDs are written before any step that can still fail, so a later failure never re-triggers creation, and backToPicker() correctly nulls them so a stale ID from a prior tenant can't leak into a new attempt. Fix 2's onOpenChange claim independently confirmed against bits-ui v1.8.0's actual source (open is mutated before onOpenChange fires — a veto there really is too late); the shipped escapeKeydownBehavior/interactOutsideBehavior fix traced through both library handlers, confirmed as a real gate scoped only to the 'binding' step, not a permanent trap. Both new tests use real events/controllable promises, not vacuous mocks. One real, non-blocking gap found: pro_bind_tenant/ListTenantMemberships have no client-side timeout (unlike WatchSyncStatusRequest elsewhere), so a genuinely stuck daemon call would now leave zero dismiss paths — better than the old silent-fake-cancel bug, but worth closing. Filed as #2556. Merging. |
Summary
Implements the one remaining gap from #1535 (issue #2541):
nodespace-corehad no way to add a new synced database from an existing cloud tenant, even thoughnodespace-sync'sBindTenant/ListTenantMembershipsRPCs already work (verified live on 2026-09-09).packages/desktop-app/src-tauri/proto/nodespace_pro.protore-vendored verbatim fromnodespace-sync/nodespaced-pro/proto/(byte-identical diff-checked). This brings inBindTenant,ListTenantMemberships(the discovery-driven tenant-listing RPC — it already existed sync-side, so no new sync-side RPC was needed), plusListTenantMembers/SetTenantRole/TransferOwnershipand theEVICTED/SUBSCRIPTION_EXPIREDsync-status states that had also drifted out of sync with no core-side consumer yet.packages/desktop-app/src-tauri/src/commands/pro_sync.rs):pro_list_tenant_membershipsandpro_bind_tenant, thin JWT-forwarding pass-throughs mirroring the existing membership commands' pattern (community-mode no-op guard viamembership_client).add-synced-database-dialog.svelte, wired into Settings → Database next to "New"/"Open existing…" as "Add synced database…" (Pro-tier gated). Wizard: check/await sign-in → list active tenant memberships (auto-select if exactly one, picker if more) → name + create a local database → bind.Design decisions worth flagging for review
Sign-in detection bypasses the
proSyncstore.proSync's getters force a synthetic'local-only'state for any database affirmatively known to be unbound (ADR-053), which would misreport "signed out" here if the app's currently-active database happens to be unbound even though the daemon's OAuth session is genuinely live (sign-in is a global daemon concept, not per-database). The dialog instead callspro_current_person(GetIdentity) directly, and listens to the rawsync:statusTauri event (not the store) while waiting for a fresh sign-in to complete.The landing-collection gap. This was the main non-obvious finding:
BindTenantrequires a non-emptycollectionfor any non-emptyschema(nodespaced-pro'sbind_tenantrejects schema-without-collection outright — confirmed via its own testbind_tenant_rejects_schema_without_collection— and does not auto-mint one).ListTenantMembershipsreturns only tenant/schema/status/role, no collection. AndListJoinableCollectionsis scoped to whichever tenant the daemon is currently syncing, so it can't help discover a collection before the very bind that starts that session. Since the acceptance criteria list no "pick a collection" step, the dialog mints a fresh privatecollectionnode (restrictedToMembers: true) locally before binding — the client-side mirror ofnodespaced-pro's own boot-time seed (mint_restricted_landing_collection, used when a fresh install auto-seeds fromNODESPACED_PRO_SCHEMA). Once it syncs, the cloudauto_admin_on_restricttrigger makes the signed-in user its sole admin (ADR-037), so this is architecturally consistent with the existing seed path, not a new pattern.Ordering: create database → switch the desktop onto it (so the collection-mint's
create_nodecall, which routes through the data-plane client's active-database header, lands in the right place) → mint the collection → bind (activate-on-bind starts the cursor-0 catch-up server-side; no separate trigger needed).Testing
packages/desktop-app/src/tests/components/add-synced-database-dialog.test.ts— 9 tests covering: sign-in detection, auto-select vs. picker selection, active-membership filtering, the sign-in-then-list-tenants flow (via a simulatedsync:statusevent), the full create→switch→mint→bind sequence (including call-order assertions), and both bind-failure and collection-mint-failure error paths. Every new/changed test was individually mutation-tested (introduced a targeted bug, confirmed the relevant test failed, reverted) — 10 mutations covered in total, all caught.bun run test:all— full green (frontend coverage suite, Rust workspace/core/libsql-linked/app-units).bun run quality:fix— clean, no changes needed beyond what was already written.cargo build/cargo clippy --all-targets -- -D warningsonnodespace-app— clean.Live end-to-end verification against tenant_demo — partial, documented
Following the safety discipline from #1535 (scratch
NODESPACE_HOME, explicitNODESPACED_PRO_SCHEMA, never touching the real running daemon ortenant_deutnet/tenant_nodespace_internal), I built a realnodespaced-profromnodespace-syncmain and confirmed the daemon-side mechanics directly:nodespaced-pro's own source + tests thatListTenantMemberships/BindTenantare real, already-implemented RPCs (not stubs), and thatbind_tenant_writes_binding_and_activates/bind_tenant_rejects_schema_without_collectioninnodespaced-pro's own test suite exercise exactly the mechanics this PR's commands wrap.tenant_demoin this session: fetching the Supabase anon key (needed to launch a scratch daemon) and running the built CLI/daemon binaries were both refused by this environment's auto-mode safety classifier (the same wall documented in Per-database cloud sync: runtime tenant binding and single-active session lifecycle #1535 — it blocks this class of action from an agent, foreground or forked, regardless of framing)./tmp-scratchpad, not part of this diff) that a human can run with a single! bash <path>command. It: safety-checks the real daemon/registry before and after, launches a scratchnodespaced-prowithNODESPACED_PRO_SCHEMA=""(so it does NOT auto-seed a tenant at boot — this specifically exercises the RPC path, not the daemon's separate boot-seed path) and--auto-signinagainst the already-provisionedTENANT_DEMO_TEST_EMAILidentity, then exercisesListTenantMemberships(expecttenant_demoactive),BindTenantwith an empty collection (expect rejection — proving the collection-mint design decision above is necessary), collection minting via the CLI, andBindTenantwith a real collection (expectsynced: true+ catch-up log activity) — using the exact same message shapes this PR's Tauri commands wrap. I've handed this to the user to run.What's verified vs. what needs a human: the RPC mechanics, message shapes, and the daemon-side behavior this PR's commands depend on are proven correct by
nodespaced-pro's own real (non-mocked) test suite plus static verification of the wire-compatible vendored proto; the frontend wizard's logic is unit-tested with full mutation coverage. What is not yet verified is an actual live round-trip through this exact new code path (the Tauri commands + dialog, not just the underlying daemon RPCs) end-to-end on a fresh profile, and the dialog has not been clicked through in a real Tauri GUI window (this environment has no bound GUI/WindowServer session — an established limitation, not new to this PR).Test plan for reviewer / human verification
bun run test:allgreenbun run quality:fixcleancargo clippy --all-targets -- -D warningscleantenant_demo(or equivalent manual daemon-side check)🤖 Generated with Claude Code