Skip to content

Stop driving Pro sync lifecycle from the app shell, database store and debug channel #3329

Closed as not planned

Description

@mstomar125

Summary

Core's shared code stops starting, re-targeting and inspecting Pro sync:

  • App shell: no longer calls proSync.start().
  • Database store:
    • no longer invokes pro_activate_database (proActivateChain, activateProSync());
    • no longer invalidates the Pro membership cache;
    • no longer hydrates the settings singleton on its own.
  • Debug channel: no longer dumps proSync.

The Pro frontend does this work through #3313's hooks (ADR-082 §2.5, proposed): lifecycle.start, lifecycle.onDatabaseActivated and debugDump.

databaseStore.refreshDatabaseSettings() stays, because it is the host-API method databases.refreshDatabaseSettings() (ADR-082 §2.6). Core stops calling it.

The Pro modules stay in core, unused, until #3331 and #3332 delete them.

Context

Line numbers are at main @ af8ddb6. #3317 and #3327 will have shifted them, so locate code by symbol.

packages/desktop-app/src/lib/components/layout/app-shell.svelte

Symbol Lines Notes
import { proSync } from '$lib/stores/pro-sync.svelte' 36
let cleanupProSync 248
The "Pro-tier sync listener" comment and the proSync.start().then(…).catch(…) chain 256-263 Runs on every launch, inside the __TAURI_INTERNALS__ check. In community it invokes pro_tier, pro_current_status and pro_subscribe_sync_status, which do nothing
cleanupProSync?.() 605 In the onMount cleanup

The same onMount also holds code that other issues add. This PR changes none of it:

packages/desktop-app/src/lib/stores/database.svelte.ts

Symbol Lines
import { membership } from '$lib/stores/membership.svelte' 12
DATABASE_SETTINGS_PIN_OWNER and its doc 94-104
this.refreshDatabaseSettings() in the browser-mode branch of load() 182
this.activateProSync(resolved) in load() 234
The else branch in load() that calls this.refreshDatabaseSettings() 243-247
proActivateChain and its doc 283-293
proSyncSettled(), already deleted by #3325 295-304
activateProSync() and its doc 306-327
The re-target comment and this.activateProSync(id) in switchTo() 451-455
The membership comment and membership.invalidateForDatabaseSwitch() in evictAndReloadActiveDatabase() 517-520
The re-hydrate comment and this.refreshDatabaseSettings() at the end of evictAndReloadActiveDatabase() 544-546
refreshDatabaseSettings() and its doc 549-593
The module-level onDaemonReconnect comment, which says a failed load leaves "the settings node unhydrated" 659-663

The docs say refreshDatabaseSettings() exists only to feed the Pro variant machine. No core UI reads the settings singleton.

packages/desktop-app/src/lib/services/debug-channel.ts

captureStoreDump() has two Pro parts:

  • a PII note naming proSync.userEmail (lines 120-122);
  • a dynamic import and dump of proSync (lines 156-161).

#3313 already added the debugDump loop over registered extensions.

Hook timing, from #3313

onDatabaseActivated fires after evictAndReloadActiveDatabase() in switchTo(), and after the if/else in load(). It therefore always fires after sharedNodeStore.clearAll().

That matters because clearAll() wipes every pin and bumps the database epoch. The Pro frontend uses this hook for three things:

  • the serialized pro_activate_database re-target, with its own copy of proActivateChain;
  • membership.invalidateForDatabaseSwitch();
  • databases.refreshDatabaseSettings(), whose pin survives because it runs after clearAll().

Scope

app-shell.svelte

database.svelte.ts

  • Check: proSyncSettled is gone (Delete the Pro Account section, workspace-members card and tenant-admission calls #3325). If it is not, stop, because Delete the Pro Account section, workspace-members card and tenant-admission calls #3325 has not merged.

  • Pro re-target:

  • Membership: delete the import, and the comment and call in evictAndReloadActiveDatabase().

  • Automatic settings hydration: delete core's three calls to refreshDatabaseSettings(). In load(), the if (resolved !== null && resolved !== this.defaultDatabaseId) block keeps its eviction call and loses its else.

  • Keep refreshDatabaseSettings() and DATABASE_SETTINGS_PIN_OWNER unchanged in behaviour, and rewrite both docs neutrally. The new docs say that the method:

    • hydrates and pins the per-database settings singleton for extension code that reads it, and is the host-API method databases.refreshDatabaseSettings() (ADR-082 §2.6);
    • is never called by core itself;
    • pins the singleton because nothing in the structure tree reaches it, and never unpins it;
    • loses its pin to a database switch's clearAll(), so a caller re-runs it from onDatabaseActivated, which fires after the eviction.

    Remove every mention of these from the two docs: resolveProSyncVariant, activeDatabaseSettings, pro-sync-variant.svelte.ts, membership.svelte.ts, collaboration-locked.svelte, sync_enabled and auth_status.

  • onDaemonReconnect comment: drop "(and the settings node unhydrated)". This PR makes it false.

debug-channel.ts

Host API, only if needed

Check that src/lib/extension-api/index.ts (#3315) exports databases.refreshDatabaseSettings(). If it does not:

Tests

src/tests/stores/database.test.ts

Setup:

  • Reword the pinNodes mock comment (lines 26-28) neutrally: extension code reads the singleton outside any open tab.
  • Delete the $lib/stores/membership.svelte mock and membershipInvalidateForDatabaseSwitch (lines 79-84).
  • In settingsNode() (lines 146-158), set properties to {}.

describe('load'): two tests change.

  • The tests:
    • "reloads the database-scoped stores when the restored database is not the default" (line 347);
    • "does not reload the stores when the restored database is the default" (line 363).
  • In both, replace expect(mockGetNode).toHaveBeenCalledWith(DATABASE_SETTINGS_NODE_ID) with expect(mockGetNode).not.toHaveBeenCalledWith(DATABASE_SETTINGS_NODE_ID).

describe('switchTo'):

  • In "flushes, switches, clears caches, resets tabs, and reloads", drop three things:
    • the pro_activate_database note on the mock (line 467);
    • the re-target comment and vi.waitFor (lines 473-479);
    • the membership assertion and its comment (lines 521-524).
  • Delete "completes the switch even if the Pro sync re-target fails" (lines 537-555).
  • Delete "does not dispatch a later pro_activate_database call until an earlier one settles…" (lines 557-587). The serialization contract moves to the Pro frontend's tests.
  • Drop pro_activate_database from the inline comments at lines 633 and 710.

describe('refreshDatabaseSettings'):

  • Reword the comment in "pins DATABASE_SETTINGS_NODE_ID reachable…" (lines 772-778) neutrally.
  • Delete "load() hydrates the settings node through the same forced refetch" (lines 798-811).
  • Delete "switchTo re-pulls the new database settings after the caches are cleared" (lines 844-856). Add start, onDatabaseActivated and debugDump extension lifecycle hooks #3313's lifecycle describe covers the hook's order relative to clearAll().
  • Keep the other five tests.

describe('isActiveDatabaseEvent'): retitle "passes events with no database id (single-database / Pro daemon)" (line 898) to "passes events with no database id (not scoped to a database)". #3366 no longer lists this title.

Leave #3313's lifecycle-hooks describe unchanged.

src/tests/stores/daemon-reconnect-retry.test.ts

Ratchet

Run bun run scripts/check-pro-boundary.ts and paste the printed BASELINES.

Out of scope

Steps

  1. Startup, per core's CLAUDE.md:
    • On the primary checkout, run git status, then git fetch origin && git pull origin main.
    • Run EnterWorktree({name: "issue-<N>-pro-lifecycle-hooks"}).
    • Inside the worktree, run bun install, then bun run test for the baseline.
    • Run bun run gh:comment <N> "Frontend: X passed", bun run gh:assign <N> "@me" and bun run gh:status <N> "In Progress".
  2. Check the preconditions:
  3. Make the app-shell.svelte changes.
  4. Make the database.svelte.ts changes.
  5. Make the debug-channel.ts changes.
  6. Check the host API facade, and add refreshDatabaseSettings if it is missing.
  7. Update the tests.
  8. Run the searches under Acceptance criteria, then the ratchet.
  9. Run the free-app check under Tests and verification.
  10. Finish:
    • Run bun run test:changed.
    • Run bun run --cwd packages/desktop-app quality:fix, then commit.
    • Run git push origin HEAD:issue-<N>-pro-lifecycle-hooks.
    • Run gh pr create --repo NodeSpaceAI/nodespace-core --base main --head issue-<N>-pro-lifecycle-hooks, then bun run gh:status <N> "In Review".
    • Run /pragmatic-code-review, then /address-review.
    • Merge only after the user approves. Run bun run merge <PR#> in the background, then ExitWorktree.

Standards:

  • Use createLogger, never console.*.
  • Mock Tauri with mockTauriCore from src/tests/helpers/mock-tauri-core.
  • Run tests with bun run test, never bun test.
  • No any, and no lint suppression.
  • No GitHub issue numbers in code comments. Cite ADRs instead.

Acceptance criteria

  • rg -n 'proSync|pro-sync' packages/desktop-app/src/lib/components/layout/app-shell.svelte packages/desktop-app/src/lib/stores/database.svelte.ts packages/desktop-app/src/lib/services/debug-channel.ts finds nothing.
  • rg -n 'pro_activate_database|proSyncSettled|activateProSync|proActivateChain' packages/desktop-app/src finds nothing.
  • rg -n membership packages/desktop-app/src/lib/stores/database.svelte.ts finds nothing.
  • rg -n -F 'refreshDatabaseSettings(' packages/desktop-app/src/lib matches only these four places:
  • @nodespace/extension-api exports databases.refreshDatabaseSettings(), and its export snapshot passes.
  • Core's debug store dump has no proSync section, and Add start, onDatabaseActivated and debugDump extension lifecycle hooks #3313's debugDump tests in debug-channel.test.ts pass.
  • Add start, onDatabaseActivated and debugDump extension lifecycle hooks #3313's test that onDatabaseActivated fires after clearAll() still passes.
  • The free app is unchanged (see the free-app check under Tests and verification).
  • BASELINES in scripts/check-pro-boundary.ts is lowered to the printed counts, and bun run scripts/check-pro-boundary.ts exits 0.
  • bun run test:changed and bun run --cwd packages/desktop-app quality:fix pass.

Tests and verification

Unit tests

  • bun run --cwd packages/desktop-app test src/tests/stores/database.test.ts src/tests/stores/daemon-reconnect-retry.test.ts src/tests/services/debug-channel.test.ts src/tests/services/shared-node-store-pin-guard.test.ts
  • bun run test:changed

The pin-guard's second test still finds pinNodes(DATABASE_SETTINGS_PIN_OWNER, [DATABASE_SETTINGS_NODE_ID]) in database.svelte.ts, because the method stays.

Free-app check

Run bun run tauri:dev with an isolated NODESPACE_HOME, never the live ~/.nodespace.

  • Stop the daemon, then cold-start the app. The sidebar's collections and the schema-backed types load without a manual reload.
  • Switch databases A → B → A. The sidebar, schemas, saved queries and AI chats reload for each database, and the console shows no errors.
  • No pro_* command is invoked. The acceptance searches check this statically: after this PR, the only callers are in Pro modules that core no longer registers (Stop importing the Pro extension in core; register it only through the build entry #3316) or starts.

Pro check, in nodespace-sync's pin-bump PR

When sync moves its pin past this commit, with SYNC counterpart (b) from the parent, build with scripts/build-pro-dmg.sh and check:

  • the sync status arrives after launch;
  • switching databases re-targets sync to the new database;
  • a rapid A → B → A switch ends on A;
  • after a switch, the settings singleton rehydrates, so the consent modal appears for a signed-in database that is not yet enabled;
  • the Collaboration tab's roster shows the new database's members.

Before merging, you may also build the Pro app from a sync branch pinned to this PR's head.

Dependencies

Risks and rollback

  • Pro build at a pin past this commit, without counterpart (b): sync never starts, and the relogin modal never shows. The pin gate keeps this out of Pro releases until sync's pin-bump PR carries (b).
  • Two lifecycles at once:
    • Suppose sync pins to a revision between Stop importing the Pro extension in core; register it only through the build entry #3316 and this PR while its Pro frontend already implements start and onDatabaseActivated.
    • Core's proSync.start() and activateProSync then run next to the Pro frontend's copies.
    • Their two pro_activate_database chains are not serialized with each other, so they can race.
    • To avoid this, sync turns its hooks on in the pin bump that crosses this PR.
  • Rollback: revert the PR.
    • The Pro build is unaffected until sync pins to a revision that contains the revert.
    • Do not let sync pin to that revision while its Pro frontend drives the lifecycle, for the reason above.

Plan key: C6.2 (pro-boundary DAG).

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

Labels

pro-boundary

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions