This commit introduces comprehensive metrics collection for the sync service. It includes tracking state transitions, operation counts, data volumes, performance indicators, and error events. The changes also add a new CLI command to view sync metrics and integrate metrics into the sync service's core functionality.
Co-authored-by: ijamespine <ijamespine@me.com>
Adds closure table rebuilding after backfill completes to ensure entry_closure and tag_closure are properly populated for hierarchical queries.
- Rebuild entry_closure after backfill (safety measure)
- Add rebuild_tag_closure_table() to reconstruct tag hierarchy from tag_relationships
- Add per-entry closure rebuild in entry apply_state_change()
Without this, synced entries only have self-references in entry_closure and cannot be queried for descendants, breaking subtree operations and location scoping.
Fixes FK violations during library sync setup when devices have identical slugs. Implements deterministic collision resolution where the newer/joining device always renames itself with a -2 suffix, stored in device.json overrides.
- Add device info to CreateSharedLibraryRequest for pre-registration
- Add device_slug to CreateSharedLibraryResponse for resolved slug communication
- Add create_library_with_id_and_initial_device() to pre-register requesting device
- Update ensure_device_registered() to use per-library slug system
- Add collision detection to RegisterDeviceRequest message handler
- Add collision detection to Device::apply_state_change() for sync backfill
- Preserve existing slugs on device updates to avoid breaking references
- Implement execute_share_local() and execute_join_remote() with proper registration
Flow: requesting device is pre-registered before library creation, so the joining device detects the collision and stores an override in its device.json. Both libraries end up with consistent slug assignments and bidirectional sync works.
Replace confusing RegisterOnly action with clearer ShareLocalLibrary and JoinRemoteLibrary actions. Add placeholder for future MergeLibraries.
- Remove RegisterOnly from LibrarySyncAction enum
- Add ShareLocalLibrary (share your library to remote device)
- Add JoinRemoteLibrary (join existing remote library)
- Add MergeLibraries stub for future implementation
- Update CLI with three-option menu instead of two
- Simplify CLI arg parsing for new actions
The new UX is clearer: users choose to either share their library or join a remote one, instead of the ambiguous "register only" concept.
Devices can now have different slugs in different libraries without breaking other libraries. This is stored in device.json's library_slug_overrides map.
- Add library_slug_overrides HashMap to DeviceConfig
- Add slug_for_library() to get effective slug for a library context
- Add set_library_slug() to store library-specific overrides
This enables consistent device addressing across shared libraries while preserving global slug for non-shared libraries.