Repository navigation
fix(cluster): keep a community label when membership overlap stays a majority (#2298) - #4451
SrijanSriv wants to merge 1 commit into
Conversation
…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
|
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. |
There was a problem hiding this comment.
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— impacttests/test_agents_platform.py— impacttests/test_analyze.py— impacttests/test_build.py— impacttests/test_cache_stale_import_target.py— impacttests/test_cli_export.py— impacttests/test_cloud_cta.py— impacttests/test_cluster.py— impacttests/test_cluster_ambiguous_scale.py— impacttests/test_cluster_exclude_hubs.py— impacttests/test_codebuddy.py— impacttests/test_community_hub_labels.py— impacttests/test_compact_graph_json.py— impacttests/test_confidence.py— impacttests/test_dedup_shrink_refuses_force_write.py— impacttests/test_devin.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_explain_cli.py— impacttests/test_explain_same_file_tie.py— impacttests/test_export.py— impacttests/test_export_direction.py— impacttests/test_external_stub_endpoints.py— impacttests/test_extract_cli.py— impacttests/test_global_add_tag_inference.py— impacttests/test_god_nodes_cli.py— impacttests/test_hollow_chunks_arm_shrink_guard.py— impacttests/test_hook_guard_token_match.py— impacttests/test_hook_out_of_project_paths.py— impacttests/test_hook_strict.py— impacttests/test_incomplete_build_guard.py— impacttests/test_incremental_unscanned_placeholders.py— impacttests/test_install.py— impacttests/test_install_references.py— impacttests/test_java_member_calls.py— impacttests/test_kotlin_grammar.py— impacttests/test_labeling.py— impact, changed-testtests/test_language_override_lifecycle.py— impacttests/test_lookup_exit_codes.py— impacttests/test_lost_saved_semantic_nodes.py— impacttests/test_markdown_code_spans.py— impacttests/test_merge_chunks_validation.py— impacttests/test_multigraph_diagnostics.py— impacttests/test_no_cluster_undeclared_endpoints.py— impacttests/test_no_dedup_flag.py— impacttests/test_opencode_plugin_refresh.py— impacttests/test_partial_cache.py— impacttests/test_path_cli.py— impacttests/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).
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]>
|
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/ |
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_previousalready puts the old community id on the overlapping community. After that,cluster-onlyingraphify/cli.pyand_rebuild_codeingraphify/watch.pykept the label only whencommunity_member_sigsmatched 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.sigfile, a changed community count dropped every label, including communities whose members did not change.label_still_applies(next toremap_communities_to_previous) keeps the equal-signature fast path. Otherwise the label stays only whenoverlap * 2 > len(saved)andoverlap * 2 > len(current).Related to #2298. A
labelrun and a laterupdatecan still emit different community counts; this PR only stops discarding a label whose overlap is a strict majority.Type of change
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_overlapfailed withassert '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, Leidenrandomness, and the order that writes labels before the.sigfile.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
labelandupdateto emit the same community count.How was this tested?
Python 3.13.3. Python 3.10 was not available in this environment.
pyrightongraphify/cluster.py,graphify/cli.py, andgraphify/watch.pyreports pre-existing errors (unresolved graspologic imports,msvcrton this platform,cli.pycomplexity). None are onlabel_still_applies.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments.