Skip to content

Conversation

@ralsina
Copy link
Owner

@ralsina ralsina commented Nov 25, 2025

Summary

Implements comprehensive multi-instance synchronization for ToCry, allowing multiple instances to share the same data directory and synchronize changes in real-time using Sepia's file system change hooks.

Features

  • Zero-Configuration Multi-Instance Mode: Automatically enabled by default (except in demo mode)
  • Real-Time Synchronization: File system changes instantly propagate between instances
  • Thread-Safe Cache Coordination: Mutex-protected cache invalidation across instances
  • WebSocket Broadcasting: Real-time updates to connected clients
  • Echo Loop Prevention: Updated to Sepia 0.2.0 with proper internal/external event distinction
  • Comprehensive Testing: Both integration and shell script tests validate functionality

Technical Implementation

  • Build Configuration: Updated static builds to use -Dinotify flag for proper file system monitoring
  • Sepia Integration: Leverages Sepia's native file change hooks and watcher system
  • Simplified Coordination: Uses Sepia's built-in generation system instead of custom version tracking
  • Conflict Resolution: Optimistic locking with debouncing to prevent echo loops
  • CLI Simplification: Removed unnecessary flags - multi-instance is now default behavior

Key Changes

  • scripts/build_static.sh: Updated to use -Dinotify for both AMD64 and ARM64 builds
  • Makefile: Updated build targets with proper inotify support
  • src/conflict_resolution.cr: New MultiInstanceCoordinator for coordinating file changes
  • src/board_manager.cr: Enhanced with thread-safe cache invalidation
  • src/main.cr: Simplified configuration - multi-instance enabled by default
  • src/initialization.cr: Integrated file system watcher initialization
  • shard.lock: Updated to Sepia 0.2.0 with echo loop prevention

Testing

  • Shell Script Tests: test_multi_instance.sh validates basic multi-instance functionality
  • Integration Tests: Playwright-based tests verify synchronization between instances
  • Unit Tests: All existing tests pass with new functionality

Test Plan

  • Multiple instances can create and share boards
  • File system changes propagate between instances
  • Cache invalidation works correctly across instances
  • WebSocket broadcasts reach all connected clients
  • Echo loops are prevented by Sepia 0.2.0
  • Static builds include proper file system monitoring
  • Demo mode gracefully disables file watching
  • All existing functionality remains intact

Breaking Changes

None. Multi-instance mode is enabled by default with zero configuration required.

Migration Guide

No migration needed. Existing installations will automatically gain multi-instance capabilities when upgraded.

🤖 Generated with Claude Code

ralsina and others added 4 commits November 25, 2025 13:13
…ia file change hooks

This major feature enables real-time synchronization between multiple ToCry instances
sharing the same data directory using Sepia's new file system watching capabilities.

Key improvements:
- Real-time file system monitoring using Sepia's watcher hooks with -Dinotify
- Thread-safe cache coordination across multiple instances
- Optimistic locking with version tracking for conflict prevention
- WebSocket-based event broadcasting for real-time updates
- Comprehensive CLI configuration with --multi-instance and --no-file-watching flags
- Updated static builds to support inotify file system watching

Technical changes:
- Added FileChangeHandler for Sepia event processing with debouncing
- Enhanced BoardManager with thread-safe cache invalidation using Mutex
- Implemented ConflictResolver with version tracking and merge strategies
- Updated build system (Makefile, build_static.sh) to use -Dinotify flag
- Added multi-instance configuration logic to main.cr and initialization.cr
- Created comprehensive integration tests for multi-instance scenarios

All tests passing, including unit tests, integration tests, and E2E tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…on system

Replaced redundant custom version tracking with Sepia's built-in object generations,
simplifying the multi-instance coordination while maintaining the same functionality.

Key changes:
- Replaced ConflictResolver with streamlined MultiInstanceCoordinator
- Removed custom .version files in favor of Sepia's native generation tracking
- Simplified conflict detection to rely on cache invalidation and file watching
- Integrated debouncing infrastructure directly into MultiInstanceCoordinator
- Removed redundant FileChangeHandler class
- Updated initialization to use simplified MultiInstanceCoordinator

The refactored approach relies on:
- Sepia's native object generations for automatic versioning
- File system watching with cache invalidation for real-time sync
- Event debouncing to prevent echo loops
- WebSocket broadcasting for client updates

All tests pass (JavaScript, Crystal, and E2E), confirming the simplified approach
maintains full multi-instance synchronization capabilities.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove --multi-instance and --no-file-watching CLI flags
- Enable multi-instance coordination by default in all modes except demo
- Simplify configuration logic by removing unnecessary flags
- Update test scripts to work with default multi-instance behavior
- File watching now only disabled in demo mode

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Updated Sepia to version 0.2.0 which includes proper echo loop prevention
in the file system watcher. This eliminates potential infinite loops when
Sepia performs file operations that would trigger its own watcher events.

Benefits:
- Cleaner multi-instance coordination
- No internal event spam
- More robust synchronization between instances
- Eliminates need for debouncing workarounds

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 participants