Repository navigation
fix(serve): resolve an exact node id before ranking (#5343) - #5344
Ayushraj06-bit wants to merge 1 commit into
Conversation
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.
|
Thanks for the pull request, @Ayushraj06-bit. 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.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify code review 
Review completed · 811a20a7d8f5
Tip
Merge confidence: 5/5 · Looks safe to merge · 🟠 High impact
No issues reported
The resolver now checks for an exact node ID before ranked label and source-path matches.
Full summary
The resolver now checks for an exact node ID before ranked label and source-path matches. That shared behavior affects CLI explanations, section lookup, and the get_node and get_neighbors tools.
Code graph and static checks · 971 functions depend on this change
Impact & health
Impact — 971 functions depend on the 485 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_resolve_single_node()— 26 callers, 3 callees
Formal checks — 971 functions this change can affect weren't formally checked in this review. Formal checks are informational only.
Gate & verification
✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 740 function(s) in the blast radius were not formally verified this run
Test selection
28 of 593 test file(s) selected (5%) via static blast radius.
tests/test_4874_jvm_resolution.py— impacttests/test_affected_cli.py— impacttests/test_affected_path_file_node.py— impacttests/test_affected_seed_reference_forms.py— impacttests/test_benchmark.py— impacttests/test_benchmark_raw_graph.py— impacttests/test_benchmark_real_query.py— impacttests/test_confidence_score_output.py— impacttests/test_edge_also_seen.py— impacttests/test_explain_same_file_tie.py— impacttests/test_extract.py— impacttests/test_file_label_disambiguation.py— impacttests/test_graph_context_cache_reload.py— impacttests/test_markdown_sections.py— impacttests/test_mcp_graph_view_cache.py— impacttests/test_path_cli.py— impacttests/test_path_confidence.py— impacttests/test_path_type_member.py— impacttests/test_query_induced_edges.py— impacttests/test_query_mcp_direction.py— impacttests/test_query_names_its_graph.py— impacttests/test_query_seed_order.py— impacttests/test_query_seeds.py— impacttests/test_query_source_first.py— impacttests/test_serve.py— impact, changed-testtests/test_serve_http.py— impacttests/test_terraform.py— impacttests/test_truncation_full_answer.py— impact
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.
Every flagged function
_resolve_single_node()ingraphify/serve.py:2276· 26 callers, 3 callees: 26 callers depend on it (afferent coupling)
What does this PR do?
Fixes #5343.
get_nodeandget_neighborscould not reach a node by its exact id when that id tokenizes like its own source path. With the graph from the issue,get_node({"node_id": "docs_example-skill_SKILL.md"})returneddocs_example_skill_skill, andget_neighborson the same id showed noreferencesedge. Querying the shared label is refused as ambiguous with "Retry with the full node id.", and retrying with the full id returned the wrong node.Both tools (and
explain, andsections.py) resolve through_resolve_single_node, which ranks_find_node_tiersmatches.docs_example-skill_SKILL.mdtokenizes to the same words asdocs/example-skill/SKILL.md, so both nodes from that file land in the source-path tier, ahead of the exact-id check._tier_refusaltreats a file-path tier as "the file node followed by its members", so it isn't refused, and the L1 node wins on graph order.A node id names exactly one node, so
_resolve_single_nodenow returns the query as-is when it is a node id, before ranking. Label queries go through the same tiers as before, so the shared label above is still refused as ambiguous.I kept the change to the shared resolver rather than reordering the tiers in
_find_node_tiers: that would not help here (the other node from the same file stays in the source-path tier), and it would change ranking forquery,affectedandpathtoo. #3055 makes the same exact-id-first choice for thepathendpoints; this PR doesn't touch those.Type of change
Verification & Invariants
Invariant: a query that is exactly a node id resolves to that node, which is what the ambiguity refusals already tell callers to do. The one behavior change: an exact id now resolves even when it would also have tied with other nodes in the exact or source-path tier. Ids are unique, so that tie was never a real ambiguity.
Limitation: the match is exact and case-sensitive, like node ids themselves. A lowercased or partial id still goes through the ranked tiers as before.
How was this tested?
The issue's graph, through the real MCP tools (
_build_http_app+ TestClient), on v8340268a7:New test
test_resolve_single_node_takes_an_exact_node_id_before_ranking:(Windows 11, Python 3.11.9.)
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (No fragments touched.)