graphiti icon indicating copy to clipboard operation
graphiti copied to clipboard

Fix: Prevent oscillation in label propagation algorithm

Open ZLBillShaw opened this issue 1 month ago • 0 comments

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:

  1. Asynchronous Updates: Process nodes in randomized order each iteration, breaking systematic oscillation patterns
  2. Maximum Iteration Limit: Set MAX_ITERATIONS = 100 to guarantee termination
  3. Oscillation Detection: Track recent state history and detect when the algorithm enters a cycle
  4. Deterministic Tie-Breaking: Improved sorting for consistent results across runs

ZLBillShaw avatar Nov 28 '25 02:11 ZLBillShaw