graphiti
graphiti copied to clipboard
Fix: Prevent oscillation in label propagation algorithm
Summary
Fixed infinite loop bug in label propagation algorithm caused by synchronous updates leading to oscillation in certain graph structures.
Type of Change
- [x] Bug fix
- [ ] New feature
- [ ] Performance improvement
- [ ] Documentation/Tests
Objective
The previous implementation of the label propagation algorithm in community_operations.py used synchronous updates where all nodes update their community labels simultaneously. This approach can cause oscillation in certain graph topologies (e.g., bipartite graphs, regular graphs), where nodes continuously swap between two or more community assignments without ever converging, resulting in infinite loops.
Root Cause:
- Synchronous updates create systematic patterns that can cause nodes to oscillate
- No termination guarantee for non-convergent graphs
- No mechanism to detect or break out of oscillation cycles
Solution:
- Asynchronous Updates: Process nodes in randomized order each iteration, breaking systematic oscillation patterns
-
Maximum Iteration Limit: Set
MAX_ITERATIONS = 100to guarantee termination - Oscillation Detection: Track recent state history and detect when the algorithm enters a cycle
- Deterministic Tie-Breaking: Improved sorting for consistent results across runs