Skip to content

fix(community): bound label propagation iterations to guarantee termi…#1631

Open
MrNirmata wants to merge 3 commits into
getzep:mainfrom
MrNirmata:fix/bound-label-propagation-iterations
Open

fix(community): bound label propagation iterations to guarantee termi…#1631
MrNirmata wants to merge 3 commits into
getzep:mainfrom
MrNirmata:fix/bound-label-propagation-iterations

Conversation

@MrNirmata

Copy link
Copy Markdown

…nation

label_propagation() ran a while True loop that only exited on full convergence. Synchronous (Jacobi-style) label propagation is not guaranteed to converge: on symmetric or tie-heavy graphs the assignment can settle into a period-two oscillation and flip between two states forever, so the loop never terminates. build_communities() then hangs, pinning a CPU with no progress and no error.

Cap the propagation at MAX_LABEL_PROPAGATION_ITERATIONS (1000) and return the latest assignment when it has not converged, logging a warning. Graphs that do converge are unaffected: the no_change early-exit still fires exactly as before, so results are identical for every converging input.

Add unit tests for a small non-convergent graph that previously hung, the non-convergence warning, and a separable graph that still converges to the expected communities.

Summary

Brief description of the changes in this PR.

Type of Change

  • Bug fix
  • New feature
  • Performance improvement
  • Documentation/Tests

Objective

For new features and performance improvements: Clearly describe the objective and rationale for this change.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • All existing tests pass

Breaking Changes

  • This PR contains breaking changes

If this is a breaking change, describe:

  • What functionality is affected
  • Migration path for existing users

Checklist

  • Code follows project style guidelines (make lint passes)
  • Self-review completed
  • Documentation updated where necessary
  • No secrets or sensitive information committed

Related Issues

Closes #[issue number]

…nation

label_propagation() ran a `while True` loop that only exited on full
convergence. Synchronous (Jacobi-style) label propagation is not
guaranteed to converge: on symmetric or tie-heavy graphs the assignment
can settle into a period-two oscillation and flip between two states
forever, so the loop never terminates. build_communities() then hangs,
pinning a CPU with no progress and no error.

Cap the propagation at MAX_LABEL_PROPAGATION_ITERATIONS (1000) and return
the latest assignment when it has not converged, logging a warning.
Graphs that do converge are unaffected: the `no_change` early-exit still
fires exactly as before, so results are identical for every converging
input.

Add unit tests for a small non-convergent graph that previously hung, the
non-convergence warning, and a separable graph that still converges to
the expected communities.
@zep-cla-assistant

zep-cla-assistant Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@MrNirmata

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA behalf on myself, e-mail: mrnirmata@gmail.com

zep-cla-assistant Bot added a commit that referenced this pull request Jul 6, 2026
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