From 811a20a7d8f5773137ba60e4eee73bbfcff74b19 Mon Sep 17 00:00:00 2001 From: Ayushraj06-bit Date: Thu, 19 Nov 2026 23:15:19 +0530 Subject: [PATCH] fix(serve): resolve an exact node id before ranking (#5343) get_node and get_neighbors (and explain) resolve through _resolve_single_node, which ranks _find_node_tiers matches. An id that tokenizes like its own source path, such as docs_example-skill_SKILL.md for docs/example-skill/SKILL.md, lands in the source-path tier next to that file's L1 node, and a file-path tier is taken as precedence rather than a tie, so the L1 node won and the requested node was unreachable. The ambiguity refusal for the shared label tells the caller to retry with the full node id, which then returned the wrong node. A node id names exactly one node, so return it before ranking. Label queries are unchanged. --- graphify/serve.py | 6 ++++++ tests/test_serve.py | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/graphify/serve.py b/graphify/serve.py index 22e44640bd..e1604b47b0 100644 --- a/graphify/serve.py +++ b/graphify/serve.py @@ -2289,7 +2289,13 @@ def _resolve_single_node(G: nx.Graph, label: str) -> tuple[str | None, str | Non in the middle of an unrelated label (`MailController` -> `EmailController`), which is a search hit, so it comes back as a near miss with suggestions instead of a different node presented as the answer (#3917). + + A node id names exactly one node, so it resolves before any ranking: the + refusals tell the caller to retry with the id, and an id that tokenizes + like a source path must not lose to that file's node (#5343). """ + if label in G: + return label, None source_exact, exact, prefix, substring = _find_node_tiers(G, label) if not (source_exact or exact or prefix): if not substring: diff --git a/tests/test_serve.py b/tests/test_serve.py index c0e9a8e1b7..11422c0f8d 100644 --- a/tests/test_serve.py +++ b/tests/test_serve.py @@ -1884,6 +1884,24 @@ def test_resolve_single_node_still_takes_a_prefix_shorthand(): assert _resolve_single_node(G, "email") == ("mail", None) +def test_resolve_single_node_takes_an_exact_node_id_before_ranking(): + """An id that tokenizes like its source path lost to that file's L1 node, so + the "Retry with the full node id" advice itself failed (#5343).""" + from graphify.serve import _resolve_single_node + + G = nx.MultiDiGraph() + G.add_node("docs_example_skill_skill", label="example-skill/SKILL.md", + source_file="docs/example-skill/SKILL.md", source_location="L1") + G.add_node("docs_example-skill_SKILL.md", label="example-skill/SKILL.md", + source_file="docs/example-skill/SKILL.md") + + for nid in G: + assert _resolve_single_node(G, nid) == (nid, None) + nid, err = _resolve_single_node(G, "example-skill/SKILL.md") + assert nid is None + assert err is not None and err.startswith("Ambiguous:") + + def test_resolve_single_node_prefers_an_exact_name_over_a_substring(): from graphify.serve import _resolve_single_node