Skip to content

fix(cluster): keep a community label when membership overlap stays a majority (#2298) - #4451

Closed
SrijanSriv wants to merge 1 commit into
Graphify-Labs:v8from
SrijanSriv:fix/2298-community-label-majority
Closed

SrijanSriv wants to merge 1 commit into
Graphify-Labs:v8from
SrijanSriv:fix/2298-community-label-majority

Conversation

@SrijanSriv

Copy link
Copy Markdown
Contributor

What does this PR do?

Keep a saved community label when the nodes it still shares are a strict majority of both the previous membership and the current membership.

remap_communities_to_previous already puts the old community id on the overlapping community. After that, cluster-only in graphify/cli.py and _rebuild_code in graphify/watch.py kept the label only when community_member_sigs matched exactly. One added node changed the digest, so the hub name replaced the saved name even though the community count stayed the same. With no .sig file, a changed community count dropped every label, including communities whose members did not change.

label_still_applies (next to remap_communities_to_previous) keeps the equal-signature fast path. Otherwise the label stays only when overlap * 2 > len(saved) and overlap * 2 > len(current).

Related to #2298. A label run and a later update can still emit different community counts; this PR only stops discarding a label whose overlap is a strict majority.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

A saved label stays on the community that still contains a strict majority of its previous members, and for which those shared nodes are a strict majority of the current set. An equal membership signature still keeps the label. A one-node fragment of a large community does not, even when remap reuses the old id.

  • Read the CONTRIBUTING.md guide.

  • Reproduced the issue and identified the invariant.

  • Made the smallest fix necessary.

  • Added a regression test (if bug fix) or isolated boundary test.

  • Kept the PR description synchronized with the final implementation.

  • Documented any limitations / unsupported cases explicitly.

  • Reproduced on v8 at 041771b: tests/test_labeling.py::test_cluster_only_keeps_label_on_majority_membership_overlap failed with assert 'auth_hub' == 'Auth Engine'. stderr: 2 saved labels, 2 communities now; renamed 1.

  • Decoy: a 200-node community split into singletons must not keep Big Service. Remap puts the old id on exactly one singleton. A fix that keeps every remapped id fails this.

  • Left alone: cluster(), community_member_sigs, Leiden randomness, and the order that writes labels before the .sig file.

  • Limitations: a 50/50 split keeps neither name. A community that more than doubles does not keep the name, because the overlap is not a strict majority of the new set. If no current community holds a majority, the hub name still fills the gap. This does not force label and update to emit the same community count.

How was this tested?

Python 3.13.3. Python 3.10 was not available in this environment.

PYTHONPATH=/Users/srijansrivastava/graphify-worktrees/2298-community-label-majority \
  /Users/srijansrivastava/graphify-worktrees/3581-reclone-manifest/.venv/bin/python -m pytest \
  tests/test_labeling.py::test_cluster_only_keeps_label_on_majority_membership_overlap -q --tb=short
# before the fix, on unmodified cli.py/watch.py/cluster.py at 041771b:
# FAILED tests/test_labeling.py::test_cluster_only_keeps_label_on_majority_membership_overlap
# AssertionError: assert 'auth_hub' == 'Auth Engine'

PYTHONPATH=/Users/srijansrivastava/graphify-worktrees/2298-community-label-majority \
  /Users/srijansrivastava/graphify-worktrees/3581-reclone-manifest/.venv/bin/python -m pytest \
  tests/test_labeling.py::test_cluster_only_keeps_label_on_majority_membership_overlap \
  tests/test_labeling.py::test_cluster_only_keeps_unchanged_label_when_count_changes \
  tests/test_watch.py::test_rebuild_keeps_label_on_majority_overlap \
  tests/test_labeling.py::test_cluster_only_heals_persisted_placeholder_but_reuses_genuine \
  tests/test_watch.py::test_rebuild_code_drops_labels_whose_community_changed \
  tests/test_community_hub_labels.py -q
# after the fix: 13 passed, 1 warning in 0.73s

/Users/srijansrivastava/graphify-worktrees/3581-reclone-manifest/.venv/bin/python -m ruff check \
  graphify/cluster.py graphify/cli.py graphify/watch.py tests/test_labeling.py tests/test_watch.py
# All checks passed

pyright on graphify/cluster.py, graphify/cli.py, and graphify/watch.py reports pre-existing errors (unresolved graspologic imports, msvcrt on this platform, cli.py complexity). None are on label_still_applies.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

…majority (Graphify-Labs#2298)

A one-node membership change failed the exact signature check and replaced the saved name with the hub label. Keep the name when the shared nodes are a strict majority of both the saved set and the current set.

Related to Graphify-Labs#2298
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 14, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @SrijanSriv. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 2 changed function(s) (2 not verified).

Formal verification. PR-changed functions: 0/2 verified (0 proven, 0 may-equivalent, 0 distinguished) · 2 not verified (1 vacuous, 1 unsupported).

Not verified on this run: dispatch\_command (vacuous: never exercised), \_rebuild\_code (unsupported).


Graphify review — findings

Fixes saved community labels being thrown away when a re-cluster changes membership slightly: a label now survives if the shared nodes are a strict majority of both the saved and the current member sets (#2298). Adds label_still_applies in cluster.py, used by both the cluster-only CLI path and _rebuild_code in watch.py. An identical membership signature still keeps the label, so a one-node fragment of a large community no longer inherits the old name just because remap reused its id. Without a signature sidecar, a changed community count used to drop every label. It now keeps only those with majority overlap, and an equal count still hub-fills only the missing ones. Labels that fail the check are renamed by their current hub, as before.

No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1212 functions depend on the 693 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _rebuild_code() — 182 callers, 60 callees
  • worse: dispatch_command() — 2 callers, 133 callees

Verification — 1212 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 1130 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

72 of 418 test file(s) selected (17%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_agents_platform.py — impact
  • tests/test_analyze.py — impact
  • tests/test_build.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_cli_export.py — impact
  • tests/test_cloud_cta.py — impact
  • tests/test_cluster.py — impact
  • tests/test_cluster_ambiguous_scale.py — impact
  • tests/test_cluster_exclude_hubs.py — impact
  • tests/test_codebuddy.py — impact
  • tests/test_community_hub_labels.py — impact
  • tests/test_compact_graph_json.py — impact
  • tests/test_confidence.py — impact
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • tests/test_devin.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_qualified_calls.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_explain_cli.py — impact
  • tests/test_explain_same_file_tie.py — impact
  • tests/test_export.py — impact
  • tests/test_export_direction.py — impact
  • tests/test_external_stub_endpoints.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_global_add_tag_inference.py — impact
  • tests/test_god_nodes_cli.py — impact
  • tests/test_hollow_chunks_arm_shrink_guard.py — impact
  • tests/test_hook_guard_token_match.py — impact
  • tests/test_hook_out_of_project_paths.py — impact
  • tests/test_hook_strict.py — impact
  • tests/test_incomplete_build_guard.py — impact
  • tests/test_incremental_unscanned_placeholders.py — impact
  • tests/test_install.py — impact
  • tests/test_install_references.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_kotlin_grammar.py — impact
  • tests/test_labeling.py — impact, changed-test
  • tests/test_language_override_lifecycle.py — impact
  • tests/test_lookup_exit_codes.py — impact
  • tests/test_lost_saved_semantic_nodes.py — impact
  • tests/test_markdown_code_spans.py — impact
  • tests/test_merge_chunks_validation.py — impact
  • tests/test_multigraph_diagnostics.py — impact
  • tests/test_no_cluster_undeclared_endpoints.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_opencode_plugin_refresh.py — impact
  • tests/test_partial_cache.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_pipeline.py — impact
  • … and 22 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

Could not verify: Could not verify dispatch\_command.

The verifier did not have enough to check dispatch\_command, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 40 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly SystemExit — names the real obstacle, not a sampling gap)

Could not verify: Could not verify \_rebuild\_code.

The verifier did not have enough to check \_rebuild\_code, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: nondeterministic output (both versions disagreed with themselves on the witness) — not a behaviour change; a function whose output is not a function of its inputs (random / time / uuid / os.urandom, or state carried across calls) cannot be soundly distinguished by execution, so this tier abstains for the whole function

· 2 more finding(s) on lines outside this diff (see the check run).

safishamsi added a commit that referenced this pull request Oct 14, 2026
Eight community PRs: Windows MCP-stdio hang (#4441), Rust use->declaration
(#4443), JS/TS file-scope callback param shadowing (#4457), sibling-file-id
symbol retention (#4452), TS class-field receiver scoping (#4297), Ollama
/api/chat num_ctx (#4414), cluster label retention on majority overlap (#4451),
and an ingest symlink test fix (#4442). AST cache schema bumped to 16.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in 0.9.91 as a058755 (cherry-picked with your authorship preserved, so it shows on your contributions). Thanks @SrijanSriv! Released to PyPI: https://pypi.org/project/graphifyy/0.9.91/

@safishamsi safishamsi closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants