You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python AST import edges to in-repo modules emit bare module names, silently dropping real dependencies #2280
Version: first observed on graphifyy 0.9.17, re-verified still present on 0.9.29 Platform: Windows 11, Python 3.11
Summary
The Python AST extractor emits import edges whose endpoint is the bare module name. For external modules (os, math, yaml) that is correct: they were never nodes, and the edge is dropped at build time. But for modules inside the scanned repo, the node exists under its fully-qualified id, the bare-name endpoint matches nothing, and the edge is silently dropped. A real intra-repo dependency vanishes from the graph.
Reproduction
A repo with ha/pyscript/solar_coordinator.py importing sibling modules:
Extraction produces nodes like ha_pyscript_modules_solar_allocator, and edges whose targets are solar_allocator / ev_actuator / hws_intent. Those targets match no node id, so build_from_json drops all of them. Re-tested on 0.9.29: all three bare endpoints still appear.
25 external (stdlib/third-party), which is correct behaviour, not a defect
4 in-repo module names, silently losing 7 real edges. The importing file's own module structure is missing from the graph
20 from a separate JS id defect (reported separately)
Suggested fix (validated locally)
We wrote a post-pass resolver and learned two things the hard way:
Matching by id suffix alone fabricates dependencies. Our first attempt bound solar_allocator to an unrelated node whose id happened to end in _solar_allocator. The reliable predicate is: candidate node's Path(source_file).stem == module_name.
Node ids legitimately repeat across extraction passes (AST and semantic reuse the same id with different source_file values), so the index must be id to list of nodes, qualifying if any entry has the matching stem. A dict keyed by id keeps the last writer and can shadow the real module node with a doc-mention node.
Exactly one qualifying candidate wins; zero or several stays unresolved. Conservative on purpose: a fabricated edge is worse than a missing one.
Related: #949 (same-basename import-target ambiguity in update), #2191 (diagnostics counting external refs as dangling; splitting the dangling count into external vs in-repo would have surfaced this class immediately).
changed the title [-]Python AST import edges to in-repo modules emit bare module names — real dependencies silently dropped[/-][+]Python AST import edges to in-repo modules emit bare module names, silently dropping real dependencies[/+]on Jul 29, 2026
Ran the full pipeline on a ~158-file repo (130 code, 28 docs, mostly Python + some SQL). diagnose_extraction reported:
raw_edges: 5507
dangling_endpoint_edges: 473
valid_candidate_edges: 5034
final graph: 1994 nodes, 4847 edges
Same symptom as described here: Node 1987 (id='langgraph') and similar bare-name endpoints for in-repo imports don't resolve to the fully-qualified node id, so the edge is silently dropped at build time. Health check surfaces the count but not which edges, so tracking down the affected files currently requires manual diffing of raw vs valid edge lists.
Not blocking (graph is still usable), but the dropped-edge rate here is noticeably higher (~9% of raw edges) than the ~7/49 dangling-name ratio reported in the original issue, for whatever that's worth as a second data point.
Still present on 0.9.55 (current latest on PyPI), macOS 15 / Python 3.13, uv-installed. Third data point after 0.9.29 and 0.9.30, and the first non-Windows one.
While reproducing this I found the severity splits cleanly by import form, which may be useful for scoping the fix.
Minimal repro
Three flat sibling modules, no packages, no __init__.py:
from db import find_user — the bare-name imports_from edge dangles as described, but the extractor also emits a fully-qualified imports --> src_db_find_user plus a calls --> src_db_find_user. The dependency still reaches the graph through the symbol level; what is lost is the module-to-module edge. Cosmetic in a dependency sense, but it does inflate the dangling count and trip the health warning.
import db — strictly worse. The imports --> db edge dangles and there is no symbol-level fallback, so src_plain ends up with zero edges to src_db. Note also that db.find_user(email) produces no calls edge at all: src_plain_lookup --calls--> src_db_find_user is absent from the output above. So it is not only the import edge that is lost — the attribute call that depends on the import binding goes with it, and the two files are fully disconnected.
The original report's repro (import solar_allocator) is the second form, which matches "a real intra-repo dependency vanishes" exactly. For the first form the current title slightly overstates it, since the symbol edges survive.
Note on the suggested fix
The Path(source_file).stem == module_name post-pass proposed in the issue body would resolve the dangling module endpoint in both cases. It would not by itself restore the missing src_plain_lookup --calls--> src_db_find_user edge, since that one is never emitted rather than emitted-and-dropped — that looks like a separate gap in the call resolver for mod.attr() when the binding comes from a plain import. Possibly the same root cause as #3272, though that one is scoped to packages with __init__.py and an importer outside the package tree, whereas this repro is a flat directory.
Fourth data point, and a third import form: from package import submodule (src layout). Seen on the hosted service (graphify.com MCP, pipeline production-v1) rather than the CLI, on a private ~25-module Python repo; re-index at a newer commit did not change it.
Shape
src/pkg/__init__.py # empty
src/pkg/store.py # def value_asof(conn, sid, period, asof): ...
src/pkg/freeze.py # from pkg import baselines, store
# ... return store.value_asof(conn, sid, period, asof)
jobs/pull.py # from pkg import ingest, store
Observed
graphify_file_neighbors("src/pkg/store.py") → 0 neighbour files, although 3 library modules and 3 job scripts import it.
graphify_callers("value_asof", strict_calls=false) → 0 callers, although it is called as store.value_asof(...).
No Python file has any cross-file imports/calls edge to another in-repo module. Test → function calls edges do survive (tests call functions by bare name after from pkg.freeze import find_release).
The TypeScript half of the same repo resolves fully, so it is Python-specific.
Why it is worse than the from db import find_user case
Here the imported name is a module, not a symbol, so there is no symbol-level fallback edge; and every use is an attribute call store.fn(), which (per the comment above) emits no calls edge. Net effect matches the import db case: importing and imported files are fully disconnected. In a codebase that consistently uses from pkg import module + module.fn(), the Python dependency graph is effectively empty.
Resolving from <pkg> import <name> to <pkg>/<name>.py when that file exists (before treating <name> as a symbol of <pkg>/__init__.py), and binding <name>.attr() calls through it, would cover this form.
Activity
[-]Python AST import edges to in-repo modules emit bare module names — real dependencies silently dropped[/-][+]Python AST import edges to in-repo modules emit bare module names, silently dropping real dependencies[/+]fengindustry-afk commentedon Jul 30, 2026
Corroborating on 0.9.30 (Windows 11, Python + SQL mixed repo, uv tool install):
Ran the full pipeline on a ~158-file repo (130 code, 28 docs, mostly Python + some SQL).
diagnose_extractionreported:Same symptom as described here:
Node 1987 (id='langgraph')and similar bare-name endpoints for in-repo imports don't resolve to the fully-qualified node id, so the edge is silently dropped at build time. Health check surfaces the count but not which edges, so tracking down the affected files currently requires manual diffing of raw vs valid edge lists.Not blocking (graph is still usable), but the dropped-edge rate here is noticeably higher (~9% of raw edges) than the ~7/49 dangling-name ratio reported in the original issue, for whatever that's worth as a second data point.
ElkaineDev commentedon Sep 6, 2026
Still present on 0.9.55 (current latest on PyPI), macOS 15 / Python 3.13,
uv-installed. Third data point after 0.9.29 and 0.9.30, and the first non-Windows one.While reproducing this I found the severity splits cleanly by import form, which may be useful for scoping the fix.
Minimal repro
Three flat sibling modules, no packages, no
__init__.py:extract(collect_files(root / "src"), cache_root=root)yields nodessrc_db, src_db_find_user, src_fromimport, src_fromimport_lookup, src_plain, src_plain_lookupand these edges:The two cases differ in impact
from db import find_user— the bare-nameimports_fromedge dangles as described, but the extractor also emits a fully-qualifiedimports --> src_db_find_userplus acalls --> src_db_find_user. The dependency still reaches the graph through the symbol level; what is lost is the module-to-module edge. Cosmetic in a dependency sense, but it does inflate the dangling count and trip the health warning.import db— strictly worse. Theimports --> dbedge dangles and there is no symbol-level fallback, sosrc_plainends up with zero edges tosrc_db. Note also thatdb.find_user(email)produces nocallsedge at all:src_plain_lookup --calls--> src_db_find_useris absent from the output above. So it is not only the import edge that is lost — the attribute call that depends on the import binding goes with it, and the two files are fully disconnected.The original report's repro (
import solar_allocator) is the second form, which matches "a real intra-repo dependency vanishes" exactly. For the first form the current title slightly overstates it, since the symbol edges survive.Note on the suggested fix
The
Path(source_file).stem == module_namepost-pass proposed in the issue body would resolve the dangling module endpoint in both cases. It would not by itself restore the missingsrc_plain_lookup --calls--> src_db_find_useredge, since that one is never emitted rather than emitted-and-dropped — that looks like a separate gap in the call resolver formod.attr()when the binding comes from a plainimport. Possibly the same root cause as #3272, though that one is scoped to packages with__init__.pyand an importer outside the package tree, whereas this repro is a flat directory.Happy to test a patch against either import form.
rikokardamow commentedon Oct 28, 2026
Fourth data point, and a third import form:
from package import submodule(src layout). Seen on the hosted service (graphify.com MCP, pipelineproduction-v1) rather than the CLI, on a private ~25-module Python repo; re-index at a newer commit did not change it.Shape
Observed
graphify_file_neighbors("src/pkg/store.py")→ 0 neighbour files, although 3 library modules and 3 job scripts import it.graphify_callers("value_asof", strict_calls=false)→ 0 callers, although it is called asstore.value_asof(...).imports/callsedge to another in-repo module. Test → functioncallsedges do survive (tests call functions by bare name afterfrom pkg.freeze import find_release).Why it is worse than the
from db import find_usercaseHere the imported name is a module, not a symbol, so there is no symbol-level fallback edge; and every use is an attribute call
store.fn(), which (per the comment above) emits nocallsedge. Net effect matches theimport dbcase: importing and imported files are fully disconnected. In a codebase that consistently usesfrom pkg import module+module.fn(), the Python dependency graph is effectively empty.Resolving
from <pkg> import <name>to<pkg>/<name>.pywhen that file exists (before treating<name>as a symbol of<pkg>/__init__.py), and binding<name>.attr()calls through it, would cover this form.