You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PR #899 implemented the AppServices container for hot-swappable database connections (Issue #894). The backend correctly switches databases at runtime — services are atomically replaced, MCP server and domain event forwarder are restarted with the new NodeService.
However, the frontend database-changed event handler only logs the event. It does not reset cached state from the old database, causing stale data to persist in the UI after a switch.
Problem
When the user switches databases, these frontend caches still hold data from the old database:
Store
Stale Data
Risk
SharedNodeStore
Cached node objects
Medium — user sees old node content
ReactiveStructureTree
Parent→child hierarchy
High — wrong children displayed
collectionsData
Collections list + member caches
High — sidebar shows old collections
Tab state
Open tabs reference old node IDs
Medium — tabs point to non-existent nodes
Status bar
In-flight messages ("Embedding 3/10...")
Low — confusing stale progress
Acceptance Criteria
On database-changed event, flush any pending writes before clearing state (sharedNodeStore.flushAllPending())
Clear the SharedNodeStore node cache (sharedNodeStore.clearAll())
Clear ReactiveStructureTree — no clear() method exists yet, so either add one or re-instantiate
Reset collections data (collectionsData.reset()) and reload from new database (collectionsData.loadCollections())
Reset tab state to default (resetTabState() — resets to single Daily Journal tab)
Clear any in-flight status bar messages (statusBar store)
Verify domain event forwarder is emitting events from the new database after switch (should already work — just verify)
Implementation Guide
Where to implement
File:src/lib/components/layout/app-shell.svelte
The database-changed listener is at approximately line 298-302:
// CURRENT (just logs):unlistenDatabaseChanged=listen('database-changed',(event)=>{log.info('Database changed to:',event.payload);});
What to implement
Replace with a handler that resets all cached state:
unlistenDatabaseChanged=listen('database-changed',async(event)=>{log.info('Database changed, resetting frontend state...',event.payload);// 1. Flush any pending writes to OLD database before clearingawaitsharedNodeStore.flushAllPending();// 2. Clear node cache (old database nodes)sharedNodeStore.clearAll();// 3. Clear structure tree (old parent→child relationships)// NOTE: ReactiveStructureTree has no clear() method yet — // you'll need to add one, or find another way to reset it.// It's imported as `structureTree` in app-shell.// 4. Reset and reload collections from new databasecollectionsData.reset();awaitcollectionsData.loadCollections();// 5. Reset tabs to default (old tabs reference non-existent node IDs)resetTabState();// 6. Reload settings (updates activeDatabasePath in UI)awaitloadSettings();// 7. Clear status bar (remove stale progress messages)statusBar.clear();// or similar — check available methodslog.info('Frontend state reset complete for new database');});
The domain event forwarder is already restarted on the backend — future events will come from the new database. This issue is about clearing existing cached state so the UI doesn't show stale data from the old database.
Embedding processor: if a switch happens mid-queue, unprocessed nodes remain stale-flagged in the old database. When that database is opened again, the processor picks them up. No frontend work needed for this.
Context
PR #899 implemented the
AppServicescontainer for hot-swappable database connections (Issue #894). The backend correctly switches databases at runtime — services are atomically replaced, MCP server and domain event forwarder are restarted with the newNodeService.However, the frontend
database-changedevent handler only logs the event. It does not reset cached state from the old database, causing stale data to persist in the UI after a switch.Problem
When the user switches databases, these frontend caches still hold data from the old database:
SharedNodeStoreReactiveStructureTreecollectionsDataAcceptance Criteria
database-changedevent, flush any pending writes before clearing state (sharedNodeStore.flushAllPending())SharedNodeStorenode cache (sharedNodeStore.clearAll())ReactiveStructureTree— noclear()method exists yet, so either add one or re-instantiatecollectionsData.reset()) and reload from new database (collectionsData.loadCollections())resetTabState()— resets to single Daily Journal tab)loadSettings()— updatesactiveDatabasePathdisplay)statusBarstore)Implementation Guide
Where to implement
File:
src/lib/components/layout/app-shell.svelteThe
database-changedlistener is at approximately line 298-302:What to implement
Replace with a handler that resets all cached state:
ReactiveStructureTree — needs a clear() method
File:
src/lib/stores/reactive-structure-tree.svelte.tsThis store currently has no
clear()orreset()method. You'll need to add one that:Look at the existing
snapshot()andrestore()methods for patterns on how to reset internal state.Available APIs (already exist)
SharedNodeStoreclearAll()SharedNodeStoreflushAllPending()collectionsDatareset()collectionsDataloadCollections()resetTabState()loadSettings()Imports needed in app-shell.svelte
Most stores are already imported. You may need to add:
loadSettingsfrom$lib/stores/settingsReactiveStructureTreeinstance (check how it's currently referenced)Testing
Notes