Skip to content

fix(path): let an exact node id resolve before tier matching - #5367

Closed
Arav-Arun wants to merge 1 commit into
Graphify-Labs:v8from
Arav-Arun:fix/path-exact-node-id-5361
Closed

Arav-Arun wants to merge 1 commit into
Graphify-Labs:v8from
Arav-Arun:fix/path-exact-node-id-5361

Conversation

@Arav-Arun

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #5361.

An endpoint that is an exact node id was refused as ambiguous when another node's label tokenized to the same words. The refusal recommended retrying with the full node id, which is what had just been supplied. Give an id the same precedence _resolve_single_node already gives it for explain (#5343): if the query is a node key, it resolves outright, and only a genuine label tie is refused.

Reproduction

On 0.9.113, with the fixture from the issue:

graphify path "demo::src_alpha_prepare" "demo::src_beta_finish" --graph graph.json

exits 3 with Ambiguous: 'demo::src_alpha_prepare' matches 2 nodes in different files. With this change it prints the one-hop route prepare() --calls [EXTRACTED]--> finish() and exits 0.

Why the tier match could not do it

_search_tokens("demo::src_alpha_prepare") and the decoy label "demo src alpha prepare" split into the same words, so _find_node_tiers put both nodes in the exact tier across two files, and _tier_refusal fired. The id is a unique graph key, so no other interpretation of the query can name a different node: resolving it outright cannot guess.

A case-mismatched id (DEMO::SRC_...) still goes through the tiers, the same limitation _resolve_single_node's label in G has.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Other (please describe):

How has this been tested?

  • New regression tests in tests/test_path_cli.py:
    • the issue's fixture, parametrized over both endpoints as ids, id as source only, and id as target only
    • a guard test: a label genuinely naming two nodes in different files is still refused with exit 3
    • the MCP shortest_path tool shares the resolver and gets the same id precedence
  • Verified the new tests fail on unfixed v8 with the issue's exact refusal message and pass with the change.
  • tests/test_path_cli.py 30/30, and the resolver-adjacent suites (test_serve.py, test_path_confidence.py, test_path_type_member.py, test_affected_path_file_node.py) 265/265.
  • Full suite on latest v8 with and without the change: same failures both ways (pre-existing, in the terraform/csharp/pascal extractors), so this change introduces no regressions.

A node id whose tokens also match another node's label was refused as
ambiguous, with a message recommending the very id that was supplied.
Give an id the same precedence _resolve_single_node already gives it
for explain, so it resolves outright and only a genuine label tie is
refused.

Fixes #5361
@github-actions

Copy link
Copy Markdown

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

@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 · 0d4cb97bf659

Note

Merge confidence: 5/5 · Nothing blocking · 2 possible issues to check · 🟠 High impact
2 possible issues not confirmed

Path endpoint resolution now returns an exact graph node ID before checking label and path matches.

Full summary

Path endpoint resolution now returns an exact graph node ID before checking label and path matches. The tests cover that precedence in the CLI and MCP tool while preserving refusals for ambiguous labels.

No confirmed issues. We found 2 possible issues we couldn't confirm; see below.

Not confirmed (2 possible issues)

Leads worth a look; we didn't double-check these. They don't change the score.

Not confirmed · The MCP shortest_path test forces directed and multigraph flags that the sibling test does not, so it may load a different graph shape than Inspect source

Detailed review · not confirmed

The new MCP test rebuilds the graph with directed and multigraph set to True. The earlier MCP test in the same file loads the raw JSON as-is. If the decoy fixture's JSON sets those flags differently, this test exercises a graph the real loader never produces.

Line 610 builds the graph with json_graph.node_link_graph(raw, edges="links"), while line 673 merges in directed and multigraph overrides. The two tests therefore construct graphs differently, and only one of them matches the fixture as written.

  • The _write_nodes output and the serve loader's graph construction were not visible, so it is unknown whether the flags already match the override.

  • Found by the per-file sweep; not double-checked.

Not confirmed · The ambiguity test's docstring describes a decoy node that this test never builds, so it misstates what is covered. Inspect source

Detailed review · not confirmed

The docstring of test_path_still_refuses_genuinely_ambiguous_label says the decoy's label still names one node, but that test's graph has no decoy. The text describes a different test.

The graph at lines 651-657 contains only a_prepare, b_prepare and finish, and the test queries prepare() and finish directly. No node with the label demo src alpha prepare exists in that test, so the docstring's reference to the decoy's label is wrong.

  • The rest of the test body was not visible, so the exact assertions beyond line 666 were not checked.

  • Reference checks do not establish safe deletion for dynamic or external consumers.

  • Found by the per-file sweep; not double-checked.

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)

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

I reproduced #5361 independently and reached the same fix, so here's some extra verification for this approach:

  • I ran the full suite on v8 b582ad40 with and without the two-line check: 0 failures both ways (11760 → 11763 passed with three equivalent tests).
  • I also tried putting if label in G inside _find_node_tiers, so every lookup gets it. The resolver suites pass that way too, but it also changes how query/--seed rank keywords. Keeping it in _resolve_path_endpoint, as here, matches MCP get_neighbors can resolve an exact node ID to a different file node #5343's scope. 👍

I'm closing my duplicate #5373 in favour of this one.

safishamsi added a commit that referenced this pull request Nov 21, 2026
…batch

Fold the Rust (#5380), C# (#5376) and PHP (#5362) AST-output changes into
the unreleased _AST_CACHE_SCHEMA = 51 entry (alongside the GHSA-g6c9-j4vm-mwq4
bash change already there), so cached Rust/C#/PHP extractions re-run on the
next build. Document the #5229 Python import-binding limitation (plain-module
re-exports are left unresolved rather than chased) in ARCHITECTURE.md, and add
the 0.9.115 changelog entries for the batch.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.115 via an authorship-preserving cherry-pick, so your commit keeps its credit. The exact-id-before-tier-matching fix (and the MCP shortest_path path) is shipped. Thanks @Arav-Arun!

@safishamsi safishamsi closed this Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

3 participants