Skip to content

fix(serve): resolve an exact node id path endpoint before ranking (#5361) - #5373

Closed
Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/5361-path-exact-id
Closed

Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/5361-path-exact-id

Conversation

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #5361. If you pass graphify path (or the shortest_path MCP tool) an exact node id, it now resolves to that node. Before, another node whose label tokenizes to the same words made the endpoint ambiguous. The refusal then told the caller to retry with the full node id, which they had already passed.

The issue's fixture, on v8 b582ad40:

$ graphify path "demo::src_alpha_prepare" "demo::src_beta_finish" --graph graph.json
Ambiguous: 'demo::src_alpha_prepare' matches 2 nodes in different files.
  alpha.py
    id: demo::src_alpha_prepare
  notes.md
    id: decoy
Retry with path::symbol ... or the full node id.          (exit 3)

With this PR it prints Shortest path (1 hops): and prepare() --calls [EXTRACTED]--> finish().

Why they tie: _find_node_tiers puts both nodes in the exact tier.

query "demo::src_alpha_prepare"
  demo::src_alpha_prepare   nid_norm == norm_query           -> exact
  decoy                     label "demo src alpha prepare"
                            == term (tokens of the query)    -> exact

Two exact hits in different files are refused by _tier_refusal. #5343 fixed the same case for explain / get_node / get_neighbors by checking if label in G before ranking in _resolve_single_node. _resolve_path_endpoint is the sibling resolver and was missed. This PR adds the same two-line check there:

if query in G:
    return query, [], None

The other fix I considered was moving the check into _find_node_tiers, so every caller gets it. That also passed every test I ran. I didn't use it because it changes keyword query/--seed ranking as well, which this issue doesn't ask for. The narrow version uses the same rule #5343 already uses.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: a string that is a node's id names exactly that node. Only queries that are not a node id go through ranking and the ambiguity checks.

  • 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.

Merge Danger

Door: two-way. Reverting f545ab5c restores v8's behaviour. No cache or schema change.

Blast Radius: small.

  • It only changes path endpoints that are literally a node id. Those used to be refused whenever another node's label normalized to the same id, and now they resolve.
  • Label, path::symbol, file-path and scored endpoints take the same route as before.

Limitations

How was this tested?

There are three new tests in tests/test_path_cli.py, on the issue's fixture plus a second prepare() in gamma.py:

test_path_exact_node_id_beats_a_label_that_normalizes_to_it                 CLI: 1 hop, prepare() -> finish()
test_shortest_path_tool_exact_node_id_beats_a_label_that_normalizes_to_it   MCP tool: same
test_path_label_shared_across_files_is_still_ambiguous                      "prepare()" still exits 3 and lists both ids
tree new tests
v8 b582ad40 2 failed, 1 passed (the guard)
f545ab5c 3 passed

Full suite, with v8 and this branch run at the same time in the same venv:

tree failed passed
v8 b582ad40 0 11760
f545ab5c 0 11763

ruff check graphify/serve.py tests/test_path_cli.py -> All checks passed!

Not tested: Windows.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill fragments touched.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables). (No extraction change.)
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages. (No trailer in the commit messages.)

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 21, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Deepjyoti-Sarmah. 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.

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor Author

Duplicate of #5367.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify code review View in Graphify

Review completed · f545ab5cf6e2

Tip

Merge confidence: 5/5 · Looks safe to merge · 🟠 High impact
No issues reported

Path endpoint resolution now returns a graph node immediately when the query exactly matches its ID, before considering label matches or ambiguity.

Full summary

Path endpoint resolution now returns a graph node immediately when the query exactly matches its ID, before considering label matches or ambiguity. The CLI and shortest-path tool both use this resolver.

Code graph and static checks · 913 functions depend on this change

Impact & health

Impact — 913 functions depend on the 280 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: main() — 129 callers, 3 callees
  • worse: _shortest_path_text() — 28 callers, 7 callees

Formal checks — 913 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: 779 function(s) in the blast radius were not formally verified this run

Test selection

28 of 607 test file(s) selected (5%) via static blast radius.

  • tests/test_4874_jvm_resolution.py — impact
  • tests/test_affected_cli.py — impact
  • tests/test_affected_path_file_node.py — impact
  • tests/test_affected_seed_reference_forms.py — impact
  • tests/test_benchmark.py — impact
  • tests/test_benchmark_raw_graph.py — impact
  • tests/test_benchmark_real_query.py — impact
  • tests/test_confidence_score_output.py — impact
  • tests/test_edge_also_seen.py — impact
  • tests/test_explain_same_file_tie.py — impact
  • tests/test_extract.py — impact
  • tests/test_file_label_disambiguation.py — impact
  • tests/test_graph_context_cache_reload.py — impact
  • tests/test_markdown_sections.py — impact
  • tests/test_mcp_graph_view_cache.py — impact
  • tests/test_path_cli.py — impact, changed-test
  • tests/test_path_confidence.py — impact
  • tests/test_path_type_member.py — impact
  • tests/test_query_induced_edges.py — impact
  • tests/test_query_mcp_direction.py — impact
  • tests/test_query_names_its_graph.py — impact
  • tests/test_query_seed_order.py — impact
  • tests/test_query_seeds.py — impact
  • tests/test_query_source_first.py — impact
  • tests/test_serve.py — impact
  • tests/test_serve_http.py — impact
  • tests/test_terraform.py — impact
  • tests/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

  • main() in graphify/__main__.py:808 · 129 callers, 3 callees: 129 callers depend on it (afferent coupling)
  • _shortest_path_text() in graphify/serve.py:2739 · 28 callers, 7 callees: fans out to 7 callees (efferent coupling); 28 callers depend on it (afferent coupling)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

path rejects an exact node ID when another label normalizes to it

1 participant