graphify icon indicating copy to clipboard operation
graphify copied to clipboard

Community labeling mismatch: small utility-function communities get swapped with unrelated business pipeline names

Open andaviga opened this issue 3 months ago • 1 comments

Bug: cluster-only / label reproducibly corrupts labels of small communities

Environment

  • graphify 0.9.35
  • Python 3.12.3
  • Ubuntu (venv, pip install)
  • Backend: claude (via pip install anthropic)

Steps to reproduce

  1. graphify /opt/ert-etl → generates initial graph.json (218 nodes, 468 edges, 25 communities, no labeling yet)
  2. graphify label /opt/ert-etl --backend claude → labeling runs successfully (cost: 1822 input / 221 output tokens)
  3. Result: small communities (3-4 nodes) containing isolated utility functions get labeled with completely unrelated business pipeline names

Concrete example

Community ID Actual node content Generated label (wrong)
11 get_engine() + rationale (SQLAlchemy connection utility) "Accounts Payable Open Pipeline"
13 upload_sharepoint() + rationale "Accounts Receivable Upload Pipeline"
14 get_token() + rationale "Monthly Production KG Pipeline"
15 db_utils.py rationale "Machine Accounting Cost Pipeline"

These names ("Accounts Payable", "Accounts Receivable", etc.) belong to other communities in the same graph — they don't look like random hallucinations, they look like correct labels from OTHER communities applied to the wrong one.

Reproducibility

  • I ran graphify cluster-only /opt/ert-etl (no --backend, no new labeling) a second time.
  • Message shown: [graphify] community set changed since labeling (25 saved labels, 25 communities now; renamed 2 community(ies) by their hub)
  • The same mismatch pattern repeated, and a manual fix I made to .graphify_labels.json was automatically reverted on the next run.
  • Suspicion: Leiden clustering is not deterministic across runs (same graph, no code changes), and the "renamed by hub" mechanism that tries to reconcile old community IDs with new ones fails specifically for small/generic communities (singleton utility functions), possibly due to hub conflicts between similarly-sized communities.

Impact

  • graphify label without a "hard reset" flag always tries to reconcile with the existing .graphify_labels.json, so there's no way to generate fully fresh labels without manually editing/deleting the cache.
  • This makes labeling unreliable for graphs with multiple small utility communities (shared library modules), which is a common pattern in ETL/backend projects.

Suggestion

  • A graphify label --fresh (or --no-reconcile) flag that completely ignores .graphify_labels.json and labels from scratch would help.
  • Investigate whether pinning a seed for Leiden clustering (e.g. --seed N) would stabilize results across cluster-only runs.

andaviga avatar Aug 07 '26 18:08 andaviga

Adjacent observation that argues for shrinking the surface this bug lives on: the tiny communities that get mislabeled here are often ones that should not be labeled at all.

Env: graphifyy 0.9.39, macOS, 116-file corpus → 1272 nodes, 2707 edges, 72 communities, labeled through the skill's Step 5 (host agent, not --backend claude).

Two things stood out:

  1. Hand-labeling 72 communities is the slowest human step in the pipeline. Every other step is seconds of compute; this one is a single serial pass where a person reads member lists and writes 72 names. It is also the step with the least leverage per unit of effort, because of (2).

  2. 15 of the 72 were then dropped from the report as "thin" (<3 nodes). GRAPH_REPORT.md:

## Communities (72 total, 15 thin omitted)
...
- **15 thin communities (<3 nodes) omitted from report** — run `graphify query` to explore isolated nodes.

So ~21% of the labeling effort produced names that the primary artifact never shows. The tail was things like a 2-node sync-upstream.sh + its script-entry node, or a single integrations/__init__.py. Naming those is not a judgement call anyone benefits from — the member name is the label.

Relevance to this issue: the swapped labels reported here are concentrated in exactly that 3-4 node band. Any of these would cut both the burden and the blast radius:

  • Auto-name below a size threshold — a community of ≤N nodes takes its hub node's label verbatim (deterministic, unswappable, no model call).
  • Auto-merge below the threshold into the nearest neighbouring community by edge weight, so the count shrinks before labeling.
  • Label the top-K only and leave the tail auto-named, which also bounds labeling cost on large graphs.

Any of the three would have removed 15 of my 72 labels — and, in this issue's reproducer, would have taken communities 11/13/14/15 (get_engine(), upload_sharepoint(), get_token(), db_utils.py rationale — all 3-4 nodes) out of the model's hands entirely, since each one's hub name is already the obvious label.

Not proposing this as a fix for the mismatch itself — the "renamed by hub" / saved-label reconciliation path clearly has a real ordering bug that would still need fixing for the large communities. Just noting that the cheapest correct label for a 3-node community is the one it already contains.

cdtatarevich avatar Aug 16 '26 17:08 cdtatarevich