Skip to content

feat(events): backend reconciliation replacing frontend optimistic updates#41

Merged
pythoninthegrass merged 1 commit intomainfrom
pythoninthegrass/reconcile-events
Apr 13, 2026
Merged

feat(events): backend reconciliation replacing frontend optimistic updates#41
pythoninthegrass merged 1 commit intomainfrom
pythoninthegrass/reconcile-events

Conversation

@pythoninthegrass
Copy link
Copy Markdown
Collaborator

Summary

  • Add LibraryReconcileEvent with authoritative stats (total_tracks, total_duration, revision) emitted after every library mutation (delete, scan, dedup, favorite toggle, watcher)
  • Replace all LibraryUpdatedEvent::deleted(...) emissions with reconcile events that query DB stats post-transaction
  • Frontend handleLibraryReconcile handler applies backend-provided totals instead of computing them locally, eliminating count divergence and phantom tracks
  • Add _removeFromView to library store for optimistic visual removal without recomputing totals (reconcile event provides authoritative numbers)
  • 7 Rust unit tests + 13 Vitest tests covering reconcile event serialization, delta application, and authoritative total override

Test plan

  • cargo build compiles with no warnings
  • cargo test — 737 tests pass
  • npx vitest run — 112 relevant tests pass (13 reconcile + 49 library + 50 queue)
  • Manual: delete tracks, verify totals update from backend stats
  • Manual: scan folder, verify reconcile event fires and section refreshes
  • Manual: trigger dedup, verify removed tracks disappear with correct totals

🤖 Generated with Claude Code

…mistic updates

Add LibraryReconcileEvent with authoritative stats (total_tracks,
total_duration, revision) emitted after every library mutation. Replace
LibraryUpdatedEvent::deleted calls in delete, purge, dedup, scan, favorite,
and watcher flows. Frontend applies backend-provided totals instead of
computing them locally, eliminating count divergence and phantom tracks.

- Add LibraryReconcileEvent struct with delete/scan_complete/dedup/favorite
  factory methods and emit_library_reconcile on EventEmitter trait
- Modify library_delete_track(s), library_delete_all, library_purge_missing,
  run_backfill_and_dedup to emit reconcile events with DB stats + revision
- Modify scan_paths_to_library and watcher to emit reconcile on completion
- Modify favorites_add/remove to emit reconcile with affected_sections
- Add _removeFromView to library store (filters view without recomputing totals)
- Add handleLibraryReconcile handler in events.js with queue cleanup
- Remove deleted-action branch from createLibraryUpdatedHandler
- Remove fetchTracks from handleScanComplete (reconcile handles it)
- Update context-menu-actions to use _removeFromView for optimistic UI
- Add 7 Rust unit tests and 13 Vitest tests for reconcile event handling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pythoninthegrass pythoninthegrass merged commit 980c9ba into main Apr 13, 2026
3 of 5 checks passed
@pythoninthegrass pythoninthegrass deleted the pythoninthegrass/reconcile-events branch April 13, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant