Repository navigation
Closed
Labels
Description
Overview
Implement OptimisticOperationManager to handle fire-and-forget operations with automatic rollback on failure, per architecture doc section 5.
Background
- Current operations wait for backend confirmation (slower UX)
- Architecture doc describes fire-and-forget pattern with rollback
- Structural changes should feel instant (<10ms perceived latency)
- Rollback provides safety when backend transactions fail
Implementation Tasks
OptimisticOperationManager Service
Create src/lib/services/optimistic-operation-manager.svelte.ts:
class OptimisticOperationManager {
async executeStructuralChange(
optimisticUpdate: () => void,
backendOperation: () => Promise<void>,
rollback: () => void,
): Promise<void> {
// Take snapshot for rollback
const snapshot = structureTree.snapshot();
try {
// Apply optimistic change immediately (UI updates)
optimisticUpdate();
// Fire-and-forget: Persist to backend
// Don't await - let LIVE SELECT confirm
backendOperation().catch(error => {
// Backend failed - rollback + notify
structureTree.restore(snapshot);
eventBus.emit({
type: 'error:operation-failed',
message: 'Failed to update hierarchy',
error,
canRetry: true,
action: () => this.executeStructuralChange(optimisticUpdate, backendOperation, rollback)
});
});
} catch (error) {
// Optimistic update failed - rollback
structureTree.restore(snapshot);
throw error;
}
}
}
export const operationManager = new OptimisticOperationManager();Integration with Operations
- Update
indentNode()to use operation manager - Update
outdentNode()to use operation manager - Update
createNode()to use operation manager - Update
deleteNode()to use operation manager
Example Usage
async function handleIndent(nodeId: string) {
await operationManager.executeStructuralChange(
// Optimistic: Update local structure immediately
() => structureTree.moveNode(nodeId, newParent),
// Backend: Persist (fire-and-forget)
async () => {
await backend.moveNode(nodeId, newParent);
// LIVE SELECT confirms success
},
// Rollback: Restore previous state
() => {
// Snapshot already taken by operation manager
}
);
}Acceptance Criteria
- OptimisticOperationManager service created
-
executeStructuralChange()method handles optimistic updates + rollback - All structural operations (indent/outdent/create/delete) use operation manager
- Failed operations automatically roll back
- Error events emitted for UI notification
- Operations feel instant (<10ms perceived latency)
- Tests verify rollback works correctly
Dependencies
- Part of Workstream E (Operations Refactor)
- Should be implemented after Delete obsolete cache management code from SharedNodeStore #557 (cache cleanup)
Related Issues
- Prerequisite for Implement OptimisticOperationManager for fire-and-forget operations #580 (Error toast UI)
- Part of architecture doc section 5 (Fire-and-Forget with Rollback)
Activity
Refactor BaseNodeViewer to use dual reactive stores (#572)
malibio commentedon Nov 21, 2025
Test Baseline
Before starting implementation:
Failed tests:
Starting implementation with this baseline to ensure no new test regressions.
Implement OptimisticOperationManager for fire-and-forget operations
Implement OptimisticOperationManager for fire-and-forget operations (#…
Document multi-tab/pane reactivity investigation (closes #631)
Investigate multi-tab/pane reactivity with LIVE SELECT updates (#637)
Refactor BaseNodeViewer to use dual reactive stores (#572)
Implement OptimisticOperationManager for fire-and-forget operations (#…
Investigate multi-tab/pane reactivity with LIVE SELECT updates (#637)
Refactor BaseNodeViewer to use dual reactive stores (#572)
Implement OptimisticOperationManager for fire-and-forget operations (#…
Investigate multi-tab/pane reactivity with LIVE SELECT updates (#637)
Refactor BaseNodeViewer to use dual reactive stores (#572)
Implement OptimisticOperationManager for fire-and-forget operations (#…
Split the base-node-viewer god-component (#1577)