Skip to content

_find_node substring match collapses src == tgt, making graphify path return 0 hops #828

Closed

Description

@lynn0315

graphify version: 0.7.15 (also reproduces on 0.5.2 — unchanged)


Symptom

In some codebases with prefix-style class names (Tab, TabbedActivity, TabUI, …), graphify path "Foo" "FooBar" almost always returns 0 hops. The source and target labels both match the same substring candidate node, so src == tgt.

Reproducer

In any codebase with classes like Foo and FooBar indexed:

graphify path "Foo" "FooBar"
→ 0 hops  ("Foo" is a prefix of FooBar → both src and tgt match the FooBar node, src == tgt)

Suspected root cause

serve.py:235 — _find_node is a single-stage substring match:

def _find_node(G: nx.Graph, label: str) -> list[str]:
    term = _strip_diacritics(label).lower()
    return [nid for nid, d in G.nodes(data=True)
            if term in (d.get("norm_label") or ...) or term == nid.lower()]

Only term in label — no precedence for exact / prefix matches, and no ambiguity signal back to the caller when multiple nodes match.

_score_nodes (serve.py:54), used by _tool_query_graph and _tool_shortest_path for src/tgt scoring, is also substring-based (plus matching against source_file, plus lexicographic tie-breaking), so the path/query endpoint selection has the same fuzziness.


Environment

  • Production Android browser fork (Chromium-derived), Java + Kotlin
  • 19,668 nodes / 50,881 edges (after graphify update .)
  • Many prefix-style class names (Tab*, UrlBar*, Toolbar*)

For context, the 0.5.2 → 0.7.15 cross-file resolver fix (is_member_call skip + ambiguous skip) reduced top boilerplate INFERRED target counts in this codebase by ~69% (.get() 736 → 208, .getInstance() 478 → 84, .getContext() 475 → 141). That fix lands cleanly; the _find_node substring issue is independent and unchanged.


Possible directions

(Up to the maintainer; happy to send a PR. One possible direction:)

  • Try exact match first → fall back to substring
  • If substring has ≥ 2 candidates, signal ambiguity to the caller (or return empty)
  • Apply the same staging to _score_nodes

Impact

In some codebases with prefix-style naming, graphify path returns 0 hops on most calls. query and explain may also start BFS from an incorrect node.


Companion issues

Two more issues found in the same measurement run (filed separately so they can be triaged independently):

  • BFS direction: build.py supports directed=True but the option is not exposed via CLI; serve.py BFS uses G.neighbors()
  • BFS god-node transit: degree-p99+ hubs are freely traversed

Activity

  1. changed the title [-][BUG] `_find_node` substring match collapses `src == tgt`, making `graphify path` return 0 hops[/-] [+]`_find_node` substring match collapses `src == tgt`, making `graphify path` return 0 hops[/+] on May 12, 2026
  2. added a commit that references this issue on May 12, 2026
  3. safishamsi commented on May 12, 2026

    @safishamsi
    Member

    Fixed in v0.7.16 — _score_nodes now uses three-tier precedence (exact 1000 / prefix 100 / substring 1). graphify path and the MCP tool now emit a clear error when source and target resolve to the same node instead of silently returning 0 hops.

  4. added a commit that references this issue on May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions