Repository navigation
fix: resolve affected <path> for disambiguated file labels (#4698) - #4713
Deepjyoti-Sarmah wants to merge 2 commits into
Conversation
…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.
|
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. |
There was a problem hiding this comment.
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— impacttests/test_affected_defines.py— impacttests/test_affected_member_seed.py— impacttests/test_affected_overrides.py— impacttests/test_affected_path_file_node.py— impact, changed-testtests/test_benchmark.py— impacttests/test_benchmark_raw_graph.py— impacttests/test_benchmark_real_query.py— impacttests/test_corrupt_graph_json.py— impacttests/test_indirect_call_nested_closure_shadow.py— impacttests/test_indirect_dispatch.py— impacttests/test_indirect_dispatch_assign_return.py— impacttests/test_indirect_dispatch_getattr.py— impacttests/test_js_dynamic_import_affected.py— impacttests/test_js_dynamic_imports.py— impacttests/test_mcp_graph_view_cache.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_scala_self_type.py— impacttests/test_serve.py— impacttests/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): |
There was a problem hiding this comment.
test_affected_cli_resolves_shared_basename_with_docstring()
fans out to 6 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
|
Landed in 0.9.95, cherry-picked to preserve your authorship. |
What does this PR do?
Fixes #4698.
graphify affected <path>answeredNo unique node match for <path>for a file whose basename is shared with another file and that has a second node onL1, 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:L1L1#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 onL1and retires pass 2. A one-line top-level definition does the same. Either precondition alone is harmless. Both together resolve toNone.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_labelencodes exactly that andbuild/analyzealready 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 basenameNo 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):
After:
The same graph resolves both files by path:
Type of change
Verification & Invariants
A path seed resolves to the node that names the file: the
L1node whose label is the file's basename or a trailing path suffix of its ownsource_file. ExtraL1nodes do not change the result. When two nodes both claim that shape, resolution still refuses to guess.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.jsonworks without a rebuild.Blast Radius: path seed resolution.
resolve_seedis shared by theaffectedCLI and theserve/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 ownsource_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
affectedstill prints the failure to stdout and exits 0 when nothing matches. That is a separate defect and is not fixed here.alpha/hooks.py) and lands onL1would compete with the file node. Two candidates still return no match rather than guessing.How was this tested?
New tests in
tests/test_affected_path_file_node.pybuild the exact node shapes and run the issue's repro end to end throughpython -m graphify updateandgraphify affected. None of them calls a private helper.root=resolves the same nodemain.pyThe 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
uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no skill fragments touched.)