Repository navigation
Description
Summary
In Rust code, when a file imports a symbol from an external crate (e.g. use serde_json::Value;), the AST extractor links the import to any local symbol that happens to have the same name, including an enum variant in an unrelated crate. The edge is marked EXTRACTED, so it looks certain. Downstream this produces phantom import cycles, inflated god nodes and wrong cross-community bridges.
Minimal reproduction
a/src/lib.rs
pub enum Field {
Value(String),
}
b/src/lib.rs
use serde_json::Value;
pub fn get(v: &Value) -> Option<&Value> {
v.get("x")
}
from graphify.extract import extract
from pathlib import Path
r = extract([Path("a/src/lib.rs"), Path("b/src/lib.rs")], cache_root=Path("."))Output (relevant edges):
imports_from b_src_lib -> a_src_lib_field_value | a/src/lib.rs L2 | EXTRACTED
references b_src_lib_get -> a_src_lib_field_value | a/src/lib.rs L2 | EXTRACTED (x2)
Expected: serde_json::Value is not defined in the corpus, so no edge to Field::Value. At most, an external/unresolved reference node, or an edge marked AMBIGUOUS.
Actual: b "imports" the variant Field::Value from a, with confidence EXTRACTED.
Impact on a real workspace
On a ~30-crate Cargo workspace (graph has 2376 nodes), the import cycle report listed 6 cycles. Checking each edge against the source showed that 5 of the 6 cycles do not exist:
| Reported edge | Actual source line |
|---|---|
types/src/lib.rs → plugin/src/http.rs::Value |
use serde_json::{Map, Value}; |
plugin/src/proxy.rs → plugin/src/http.rs::Value |
use serde_json::Value; |
server/src/api/mod.rs → plugin/src/http.rs::Response |
use axum::response::{IntoResponse, Response}; |
plugin/src/lib.rs → server/src/api/mod.rs::Config |
use osiris_types::{CollectionResult, Config, Manifest}; |
Several of these cycles are impossible: Cargo rejects cyclic crate dependencies, and e.g. the types crate does not depend on plugin at all. The Value(String) variant became the #2 god node (89 edges) and a top "cross-community bridge" in the suggested questions, almost entirely from serde_json::Value imports.
The last case is slightly different. osiris_types::Config is a crate-qualified path to a crate in the same workspace, yet it resolves to a different crate's Config struct. So the crate path segment seems to be ignored even when it names a local crate.
Suggested fix
- Use the path prefix of a
useitem when resolving it. A path rooted at an external crate (serde_json::,axum::,std::) should not resolve to a corpus symbol, and a path rooted at a workspace crate should resolve only within that crate's files. - Never resolve an imported type to an enum variant.
- If resolution falls back to a name-only match, mark the edge
INFERREDorAMBIGUOUS, notEXTRACTED. - Optionally, use
Cargo.tomldependencies as a sanity check: drop any cross-crate edge whose target crate is not a dependency of the source crate.
Related
- Rust: private/test-scoped fns collapse into unrelated enum-variant/production-fn nodes of the same bare name, manufacturing false god nodes #2774: same bare-name collision family, but for call/function nodes rather than
useimports. - Rust extractor: lossy structure and name-only call resolution (generic impls, traits, mods, use-lists, receivers) #4285: covers lossy
use-list parsing (dropped items), not resolution of the imported path to a wrong local symbol.
Environment
- graphify 0.9.86 (installed via the
graphifyCLI) - Python 3.10.21
- Linux (CachyOS)
Activity
github-actions commentedon Oct 23, 2026
Thanks for opening this issue, @efe-clk. A maintainer will take a look soon.
If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.
To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.
sadqyl727-ai commentedon Oct 23, 2026
fix(rust): scope a `use` to the crate it names (#4699, #4712)
fix: schema 27 + adapt #4726 to _method_of + close #4748 false-skip
safishamsi commentedon Oct 26, 2026
Fixed in v0.9.96 via #4712, now on PyPI (pip install graphifyy==0.9.96). A use of an external crate item no longer resolves to an unrelated same-named local symbol. Thanks for the report, @efe-clk.
Merge v8 into fix/python-imported-module-decorators
fix(rust): keep a `use crate::` import inside its own crate (#5240)