Skip to content

fix: resolve affected <path> for disambiguated file labels (#4698) - #4713

Closed
Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/4698-affected-file-node
Closed

Deepjyoti-Sarmah wants to merge 2 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/4698-affected-file-node

Conversation

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4698. graphify affected <path> answered No unique node match for <path> for a file whose basename is shared with another file and that has a second node on L1, for example a module docstring.

A path query matches every node in the file, so resolution ends in _prefer_file_node. Three of its passes pick the file node:

  1. the label equals the query basename and sits on L1
  2. the file node is the only node on L1
  3. the label equals the basename

#2032 relabels colliding basenames to their shortest unique path suffix (alpha/hooks.py), which retires passes 1 and 3. The rationale pass creates one node per docstring at the docstring's own line, so a docstring on line 1 puts a second node on L1 and retires pass 2. A one-line top-level definition does the same. Either precondition alone is harmless. Both together resolve to None.

The fact the resolver needs is already in the graph: a file node's label is a path form of its own source_file. _is_file_node_label encodes exactly that and build/analyze already use it.

 graphify/affected.py
   _prefer_file_node()
     pass 1: label equals the basename and is on L1
+    pass 2: label names this node's own source_file
+            (_is_file_node_label, imported lazily from graphify.build)
+            checked before the "only node on L1" fallback
     pass 3: only node on L1
     pass 4: label equals the basename

No graph schema change and no re-extraction. The relabelled node is already in graph.json; only the lookup changes.

Before (v8, the issue's repro):

$ graphify affected app/alpha/hooks.py
No unique node match for app/alpha/hooks.py
$ echo $?
0

After:

$ graphify affected app/alpha/hooks.py
Affected nodes for alpha/hooks.py
Relations: calls, indirect_call, references, imports, imports_from, dynamic_import, re_exports, inherits, extends, implements, uses, mixes_in, embeds, defines, requires
Depth: 2
- main.py [imports_from] app/main.py:L1
- handle() [calls] app/main.py:L5

The same graph resolves both files by path:

app/alpha/hooks.py                  -> alpha/hooks.py
app/beta/hooks.py                   -> beta/hooks.py
./app/alpha/hooks.py                -> alpha/hooks.py
/abs/path/app/alpha/hooks.py        -> alpha/hooks.py
alpha/hooks.py   (the label)        -> alpha/hooks.py
app_alpha_hooks  (the node id)      -> alpha/hooks.py
hooks.py         (ambiguous)        -> still no unique match

Type of change

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

Verification & Invariants

A path seed resolves to the node that names the file: the L1 node whose label is the file's basename or a trailing path suffix of its own source_file. Extra L1 nodes do not change the result. When two nodes both claim that shape, resolution still refuses to guess.

  • 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. No cache schema change, no extractor change. A revert restores the miss on the next run, and an existing graph.json works without a rebuild.

Blast Radius: path seed resolution.

resolve_seed is shared by the affected CLI and the serve/MCP lookup path, so both gain the fix. The new pass runs only when a path query already matched more than one node, and it compares the label to that node's own source_file, so it cannot bind to another file. Single-file graphs, unique basenames, and node-id seeds take the same path as before. The full-suite failure set is identical to v8.

Limitations

  • Exit code: affected still prints the failure to stdout and exits 0 when nothing matches. That is a separate defect and is not fixed here.
  • Docstring text: a docstring whose text is literally a path suffix of the file (for example alpha/hooks.py) and lands on L1 would compete with the file node. Two candidates still return no match rather than guessing.
  • Graphs before File nodes labelled by basename (index.ts) break name lookup and blind discovery in directory-per-entrypoint repos #2032: a label that is still the bare basename resolves through the existing pass, unchanged.
  • Not attempted: marking file nodes explicitly at extraction time, which would remove the heuristic entirely. This PR keeps the read-side predicate.

How was this tested?

New tests in tests/test_affected_path_file_node.py build the exact node shapes and run the issue's repro end to end through python -m graphify update and graphify affected. None of them calls a private helper.

Test v8 This PR
disambiguated label plus a docstring rationale on L1 fail pass
disambiguated label plus a one-line definition on L1 fail pass
absolute-path seed with root= resolves the same node fail pass
two nodes claiming the same path form still return no match pass pass
end to end: shared basename with a docstring lists main.py fail pass
control: comment instead of a docstring, definition below L1 pass pass
pytest tests/test_affected_path_file_node.py (v8)          -> 4 failed, 2 passed
pytest tests/test_affected_path_file_node.py (this branch) -> 6 passed
pytest test_affected_cli.py test_affected_defines.py test_affected_member_seed.py \
       test_affected_overrides.py test_explain_cli.py test_explain_same_file_tie.py \
       test_js_dynamic_import_affected.py test_lookup_exit_codes.py \
       test_query_seed_order.py test_query_seeds.py        -> 111 passed
pytest test_serve.py test_analyze.py                       -> 232 passed, 1 skipped
pytest test_build.py                                       -> 97 passed
pytest -q -p no:randomly (full suite, serial)              -> v8:      39 failed, 7988 passed, 361 skipped
                                                              this PR:  39 failed, 7994 passed, 361 skipped
                                                              (failure sets identical)

The pass-count difference is the six new tests. The 39 failures are the same environment failures on v8 and on this branch.

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

…Labs#4698)

A path query matches every node in the file, so resolution ends in
_prefer_file_node. Two of its passes compare the label to the bare
basename, which Graphify-Labs#2032's disambiguation rewrote to a unique path suffix
(alpha/hooks.py); the third pass trusts L1 uniqueness, which a module
docstring (a rationale node on line 1) or a one-line top-level
definition also occupies.

Accept a label that names its own source_file, using the
_is_file_node_label predicate build/analyze already share. Runs before
the L1 fallback, so extra L1 nodes no longer decide the result.
…phify-Labs#4698)

Pins the resolver against the node shapes Graphify-Labs#2032 and the rationale pass
produce, plus end-to-end runs of the issue's repro and the comment
control that was never broken.
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 23, 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.10 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 reviewed this change.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).

Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.


Graphify review — findings

Fixes graphify affected <path> reporting "No unique node match" for a file whose basename is shared with another module (e.g. alpha/hooks.py and beta/hooks.py). _prefer_file_node now picks the single L1 node whose label is a path form of its own source_file, which covers the shortest-unique-suffix labels from #2032, and it does this before the generic L1 fallback. That fallback was ambiguous whenever a module docstring or a one-line definition also landed on line 1. If two L1 nodes both look like the file node, resolution still returns no match rather than guessing. Tests cover the docstring, one-line-definition and absolute-path cases at the graph level, plus end-to-end CLI runs on the issue's repro.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 387 functions depend on the 40 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: resolve_seed() — 21 callers, 4 callees
  • new: test_affected_cli_resolves_shared_basename_with_docstring() — 0 callers, 6 callees

Verification — 387 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 143 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

24 of 444 test file(s) selected (5%) via static blast radius.

  • tests/test_affected_cli.py — impact
  • tests/test_affected_defines.py — impact
  • tests/test_affected_member_seed.py — impact
  • tests/test_affected_overrides.py — impact
  • tests/test_affected_path_file_node.py — impact, changed-test
  • tests/test_benchmark.py — impact
  • tests/test_benchmark_raw_graph.py — impact
  • tests/test_benchmark_real_query.py — impact
  • tests/test_corrupt_graph_json.py — impact
  • tests/test_indirect_call_nested_closure_shadow.py — impact
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_js_dynamic_import_affected.py — impact
  • tests/test_js_dynamic_imports.py — impact
  • tests/test_mcp_graph_view_cache.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_scala_self_type.py — impact
  • tests/test_serve.py — impact
  • tests/test_terraform.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.

Formal verification

No difference found (not proven): No behavior difference found in \_prefer\_file\_node (not a proof).

The verifier ran both versions of \_prefer\_file\_node on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 1 grounded finding(s) anchored inline below; 1 more finding(s) on lines outside this diff (see the check run).

return matches[0]


def test_affected_cli_resolves_shared_basename_with_docstring(tmp_path):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — test_affected_cli_resolves_shared_basename_with_docstring()

fans out to 6 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

@safishamsi

Copy link
Copy Markdown
Member

Landed in 0.9.95, cherry-picked to preserve your authorship. graphify affected <path> resolves a path whose file-node label was disambiguated by the shared-basename suffix pass. Thanks @Deepjyoti-Sarmah. Live on PyPI: https://pypi.org/project/graphifyy/0.9.95/

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.

affected <path> returns 'No unique node match' for a file with a shared basename and a module docstring

2 participants