Repository navigation
fix(extract): keep a symbol that spells a sibling's file id (#4449) - #4452
Deepjyoti-Sarmah wants to merge 1 commit into
Conversation
…s own node (Graphify-Labs#4449) extract() renames each file's old file-level id (its path with the extension, esquema_x_sql for x.sql) to the canonical one, on every node, edge endpoint and raw call that spells it. A symbol of another file can spell it too: const sql in x.mjs, so it took the file node's id and was dropped by dedup. The rename now follows only the file that minted the key, wherever another file's own symbol carries the same id; a file that only refers to the owner renames as before, so every key nobody contests behaves exactly as today. Swift extension nids and Objective-C field-table keys follow the same rule; the Objective-C path has no test that reaches it.
|
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 extract() renaming a symbol to a same-stem sibling's file id, so const sql in x.mjs no longer takes the id of x.sql and the x.mjs file node keeps its own label. Each old file-level id is now tied to the input files that minted it, and a key that another file's own symbol also spells is treated as contested. A contested key is renamed only on the minting file's items and on items that merely refer to it, across nodes, edges, raw calls, Swift extensions and ObjC field tables. Uncontested keys rename exactly as before, but the contested-key scan resolves every node's path and the ObjC remap is rebuilt per file when any key is contested, so both add cost on large inputs.
No blocking issues surfaced. 3 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3026 functions depend on the 347 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 957 callers, 58 callees - worse:
extract_js()— 93 callers, 7 callees - new:
_run()— 11 callers, 3 callees
Verification — 3026 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: 2789 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
193 of 419 test file(s) selected (46%) via static blast radius.
tests/test_affected_overrides.py— impacttests/test_astro_extraction.py— impacttests/test_astro_import_ids.py— impacttests/test_blade_extractor.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_c_include_resolution.py— impacttests/test_cache.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_cjs_module_extension.py— impacttests/test_cobol_extractor.py— impacttests/test_cpp_method_declarations.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cpp_template_type_params.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_enum_members.py— impacttests/test_csharp_field_generic_args.py— impacttests/test_csharp_foreach_loop_variable.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_chain_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_tuple_type_refs.py— impacttests/test_csharp_type_resolution.py— impacttests/test_csharp_underscore_collisions.py— impacttests/test_csharp_var_call_return_type.py— impacttests/test_csharp_verbatim_interpolation.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_ejs_extractor.py— impacttests/test_elixir_defdelegate.py— impacttests/test_elixir_import_resolution.py— impacttests/test_elixir_keyword_def_calls.py— impacttests/test_elixir_qualified_calls.py— impacttests/test_elixir_unqualified_call_scope.py— impacttests/test_erlang_extractor.py— impacttests/test_ext_tagged_id_clash.py— impact, changed-testtests/test_extract.py— impacttests/test_extract_cache_location.py— impacttests/test_extract_path_memo.py— impact- … and 143 more
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.
Docs that may be stale (advisory)
docs/superpowers/plans/2026-05-04-incremental-updates-dedup.md§ Task 4: Incremental updates — semantic cache + manifest in __main__.py (lines 603-911): references changed symbols_run
Formal verification
No difference found (not proven): No behavior difference found in extract (not a proof).
The verifier ran both versions of extract 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; 2 more finding(s) on lines outside this diff (see the check run).
| return path | ||
|
|
||
|
|
||
| def _run(root: Path, files: dict[str, str], monkeypatch, *, absolute: bool = False) -> dict: |
There was a problem hiding this comment.
_run()
11 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
Eight community PRs: Windows MCP-stdio hang (#4441), Rust use->declaration (#4443), JS/TS file-scope callback param shadowing (#4457), sibling-file-id symbol retention (#4452), TS class-field receiver scoping (#4297), Ollama /api/chat num_ctx (#4414), cluster label retention on majority overlap (#4451), and an ingest symlink test fix (#4442). AST cache schema bumped to 16. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in 0.9.91 as c29950f (cherry-picked with your authorship preserved, so it shows on your contributions). Thanks @Deepjyoti-Sarmah! Released to PyPI: https://pypi.org/project/graphifyy/0.9.91/ |
What does this PR do?
Fixes #4449.
When a JS file and a file with another extension share a stem in one folder (
x.mjsplusx.sql) and the.mjsdeclares a variable named like the sibling's extension (const sql = ...), the.mjsfile node ends up labelledsql.graphify explain "x.mjs"finds nothing.extract()renames each file's old file-level id (its path with the extension:esquema_x_sqlforesquema/x.sql) to the canonical one (esquema_x). It did that on every node, edge endpoint and raw call that spells the string, whichever file it belonged to. The JS variablesqlis minted{stem}_{name}, which is alsoesquema_x_sql. So it was renamed too, salted next to the file node, and dedup dropped one of the two.This PR renames a key only for the file that minted it, and only when another file's own symbol carries the same id. Every other key renames exactly as before.
A key is contested only when a node of a different file carries it as one of that file's own symbol ids. For a contested key, an item is renamed if its file minted the key, kept if its file holds a node with that id, and renamed otherwise. Which file an item belongs to: a node, its
source_file; an edge source, the edge'ssource_file; an edge target, thetarget_filestamp if there is one, else the edge'ssource_file; araw_callscaller_nid, the record'ssource_file. Paths are compared resolved. Swift extensionnids and Objective-C field-table keys follow the same rule.The later
ext_id_remappass already has an ownership guard (owned_ids, from #2231 and #2243). The first pass lacked it.Before / after
The issue's repro,
graphify extract . --code-only:Tests,
tests/test_ext_tagged_id_clash.py:The same cause hit other pairs. Each is a test:
x.ts+x.css(export const css = ...):csstook the file node's id, and nothing was salted becausex.csshas no nodes.x.js+x.js.map(const js_map): the variable was renamed to the id ofx.js.map, a node that does not exist.x.py+x.sql(def sql()): the function was lost and itscallsedge started at the file node.x.swift+x.sqlwithstruct sqlandextension sql: without the Swift hunk the fix would delete both file nodes, so the hunk is required, and a test covers it.Merge danger
Door: two-way. No stored format changes. Reverting is one commit.
Blast radius: narrow. The rename changes only for a key that a node of another file also carries as its own symbol id; every other key takes the old path.
graph.jsonuntil it is re-extracted..mjs,.js,.tsand similar are never in the AST cache (_JS_CACHE_BYPASS_SUFFIXES).all_nodesbefore the rename loop, dictionary lookups and memoized path resolution.graphify/extract.py.Not covered
if contested:), and the 5 existing objc tests pass with it.uses utilnext toutil.js) already end on a node that does not exist after salting, with or without this bug. A contested key now behaves like an uncontested one there. That dangling edge is not repaired.const jsinx.js,def py()inz.py) is lost. The same file owns the key, so this rename fix does not touch it. It needs its own issue.sampleintests/fixtures/sample.lpk, a Lazarus unit reference minted withsample.pas's old id. Before this fix it collided with the lpk's own file node; now it keeps its own id and its edge follows. Other languages and extractors were not scanned.graphify extract ., only siblings of a supported type (such as.sql) trigger the bug.collect_filesskips.cssand.map, so those two pairs need an explicitextract([...])call.Type of change
Verification & Invariants
Invariant: a symbol is never renamed because of a file it does not belong to, and everything that refers to a file node still ends on that file node.
The issue repro runs with relative and absolute paths: three distinct ids for the file node, the variable and the
x.sqlfile node.After
build(), the labelsx.mjs,sqlandx.sqlall exist.With
import raw from "./x.sql"inx.mjs:imports_fromends on thex.sqlfile node,containsandcallsend on the variable, and there is no self-loop.An unstamped Pascal import on a contested key ends exactly where the same edge ends with no clashing variable.
Controls from the issue (
const db,const sql = 1, no sibling, a sibling with another stem), and a Lazarus stub from a different stem, keep their ids.Gating only the node rename, and leaving edge endpoints on the old id-only rule, was tried and does not work: it leaves a
contains x.mjs -> x.mjsself-loop and acallsedge that starts at the file node.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.
How was this tested?
Run with
PYTHONPATH=/var/tmp/wt-4449and the repo venv's Python, so the code under test is this branch and not an editable install of another checkout.graphify.__file__was checked to be inside the worktree.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (No fragments changed.)