Skip to content

Rust: use of an external crate item resolves to an unrelated same-named local symbol (false imports_from edges, phantom import cycles) #4699

Closed

Description

@efe-clk

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 use item 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 INFERRED or AMBIGUOUS, not EXTRACTED.
  • Optionally, use Cargo.toml dependencies as a sanity check: drop any cross-crate edge whose target crate is not a dependency of the source crate.

Related

Environment

  • graphify 0.9.86 (installed via the graphify CLI)
  • Python 3.10.21
  • Linux (CachyOS)

Activity

  1. github-actions commented on Oct 23, 2026

    @github-actions

    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.

  2. sadqyl727-ai commented on Oct 23, 2026

    @sadqyl727-ai
  3. safishamsi commented on Oct 26, 2026

    @safishamsi
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions