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
{{ message }}
Repository navigation
Implement PersistenceCoordinator for Dependency-Based Persistence #240
Step 2 (4-5 days): Implement full PersistenceCoordinator
Follow the implementation plan in the issue
Question 2: Which API Design to Implement?
Answer: Implement the Combined Approach from persistence-layer.md
This is the hybrid recommended by the frontend-architect agent:
// API to implement:classPersistenceCoordinator{persist(nodeId: string,operation: ()=>Promise<void>,options: {mode: 'immediate'|'debounce',debounceMs?: number,// Default 500msdependencies?: Array<|string// Node ID|(()=>Promise<void>)// Lambda function |{nodeIds: string[]}// Batch>}): void;isPersisted(nodeId: string): boolean;// ReactiveisPending(nodeId: string): boolean;// ReactivewaitForPersistence(nodeIds: string[],timeoutMs?: number): Promise<Set<string>>;}
Key design choices:
✅ Use mode: 'immediate' | 'debounce' (simple, clear)
✅ Use dependencies array (declarative, flexible)
✅ Use SvelteMap for reactive state (Svelte 5 native)
✅ Return void, not handles (Svelte's reactivity manages observability)
Ignore: The flush strategies approach (elegant-persistence-solution.md) - it's more complex than needed.
Question 3: Test Mode for Database Operations
Answer: Yes! Add a test mode that mocks persistence.
classPersistenceCoordinator{privatetestMode=false;privatemockPersistence: Map<string,boolean>=newMap();/** * Enable test mode (skips actual database calls) */enableTestMode(): void{this.testMode=true;}privateasyncexecutePersistence(nodeId: string,operation: ()=>Promise<void>): Promise<void>{if(this.testMode){// Mock persistence - just mark as completeawaitnewPromise(resolve=>setTimeout(resolve,10));// Simulate asyncthis.mockPersistence.set(nodeId,true);return;}// Real persistenceawaitqueueDatabaseWrite(nodeId,operation);}// For tests: check if mock persistence happenedgetMockPersistedNodes(): string[]{returnArray.from(this.mockPersistence.keys());}// For tests: reset stateresetTestState(): void{this.mockPersistence.clear();this.persistenceStatus.clear();}}
Usage in tests:
beforeEach(()=>{persistenceCoordinator.enableTestMode();persistenceCoordinator.resetTestState();});test('coordinates dependencies correctly',async()=>{persistenceCoordinator.persist('parent',async()=>{},{mode: 'immediate'});persistenceCoordinator.persist('child',async()=>{},{mode: 'immediate',dependencies: ['parent']});awaitsleep(50);// Verify order without hitting databaseconstpersisted=persistenceCoordinator.getMockPersistedNodes();expect(persisted).toEqual(['parent','child']);});
The goal is to eliminate the saveNodeImmediately backdoor by providing declarative dependency management. All persistence should go through ONE path with different mode and dependencies options.
Activity
malibio commentedon Oct 12, 2025
Dependencies Analysis
Status: This issue is foundational and blocks other test failures.
Current Blocker: Debug Logging
Debug logging added in
shared-node-store.ts:292-293causes database writes in tests where DB isn't initialized, causing 24+ test failures.Quick fix needed: Remove debug logging before implementing full solution.
Blocked Issues
Dependency Graph
Recommendation
Implement PersistenceCoordinator first (4-5 days) rather than patching individual tests. This:
Implementation Order
See
docs/architecture/persistence-layer.mdfor complete architecture design.Add architecture documentation for PersistenceCoordinator and debug s…
malibio commentedon Oct 12, 2025
Implementation Guidance for AI Agent
Question 1: Quick Fix vs Full Implementation
Answer: Do BOTH in sequence:
Step 1 (15 minutes): Remove debug logging first
shared-node-store.ts"Remove debug logging blocking tests (#240)"Step 2 (4-5 days): Implement full PersistenceCoordinator
Question 2: Which API Design to Implement?
Answer: Implement the Combined Approach from
persistence-layer.mdThis is the hybrid recommended by the frontend-architect agent:
Key design choices:
mode: 'immediate' | 'debounce'(simple, clear)dependenciesarray (declarative, flexible)SvelteMapfor reactive state (Svelte 5 native)void, not handles (Svelte's reactivity manages observability)Ignore: The flush strategies approach (elegant-persistence-solution.md) - it's more complex than needed.
Question 3: Test Mode for Database Operations
Answer: Yes! Add a test mode that mocks persistence.
Usage in tests:
Implementation Order (Recommended)
Phase 1: Quick Fix (15 min)
Phase 2: Core PersistenceCoordinator (1-2 days)
Phase 3: Refactor SharedNodeStore (1 day)
Phase 4: Refactor BaseNodeViewer (1 day)
Phase 5: Tests & PR (1 day)
Key Files Reference
Read these for context:
docs/architecture/persistence-layer.md← Primary API specpackages/desktop-app/src/lib/services/shared-node-store.ts← Current implementationpackages/desktop-app/src/lib/design/components/base-node-viewer.svelte← Watcher usageCreate:
packages/desktop-app/src/lib/services/persistence-coordinator.svelte.tspackages/desktop-app/src/tests/services/persistence-coordinator.test.tsFinal Note
The goal is to eliminate the saveNodeImmediately backdoor by providing declarative dependency management. All persistence should go through ONE path with different
modeanddependenciesoptions.Good luck! 🚀
Remove debug logging blocking tests (#240)
Remove debug logging from base-node-viewer.svelte (#240)
Implement PersistenceCoordinator for Dependency-Based Persistence (#242)
Implement PersistenceCoordinator with dependency tracking (#240)
malibio commentedon Oct 12, 2025
Progress Update
✅ Completed (40-50% of Issue)
Quick Fix - PR #242 (Merged)
shared-node-store.ts(lines 292-293)base-node-viewer.svelte(line 190)Core Implementation - PR #243 (Draft)
persistence-coordinator.svelte.ts(590 lines)🔄 Remaining Work (50-60% of Issue)
1. Refactor SharedNodeStore (~1 day)
saveNodeImmediately()backdoor methodupdateNodeContentDebounced()methodpendingContentSavesmaptauriNodeServicecalls withpersistenceCoordinator.persist()2. Refactor BaseNodeViewer (~1 day)
pendingContentSavePromisesmapwaitForNodeSavesIfPending()function3. Update Existing Tests (~1 day)
4. Final Validation
📁 Files Changed
packages/desktop-app/src/lib/services/persistence-coordinator.svelte.ts(NEW)packages/desktop-app/src/tests/services/persistence-coordinator.test.ts(NEW)🔗 Branch
feature/issue-240-persistence-coordinator📊 Estimated Time Remaining
2-3 days of implementation work + testing/validation
Refactor SharedNodeStore to delegate persistence to PersistenceCoordi…
Apply code review fixes for PersistenceCoordinator (#240)
Implement PersistenceCoordinator for Dependency-Based Persistence (#243)
Add architecture documentation for PersistenceCoordinator and debug s…
Implement PersistenceCoordinator for Dependency-Based Persistence (#242)
Implement PersistenceCoordinator for Dependency-Based Persistence (#243)
Add architecture documentation for PersistenceCoordinator and debug s…
Implement PersistenceCoordinator for Dependency-Based Persistence (#242)
Implement PersistenceCoordinator for Dependency-Based Persistence (#243)
Add architecture documentation for PersistenceCoordinator and debug s…
Implement PersistenceCoordinator for Dependency-Based Persistence (#242)
Implement PersistenceCoordinator for Dependency-Based Persistence (#243)
Add Collaboration view: roster + member management (#240) (#1474)