{"record":{"id":"fd20deaac327c80a","repo":"diem/diem","slug":"ipe-cyclic-dependency-found-after-resolution","errorCode":null,"errorMessage":"IPE: Cyclic dependency found after resolution {:?}","messagePattern":"IPE: Cyclic dependency found after resolution (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"language/tools/move-package/src/compilation/build_plan.rs","lineNumber":25,"sourceCode":"};\nuse anyhow::Result;\nuse petgraph::algo::toposort;\nuse std::{collections::BTreeMap, io::Write};\n\n#[derive(Debug, Clone)]\npub struct BuildPlan {\n    root: PackageName,\n    sorted_deps: Vec<PackageName>,\n    resolution_graph: ResolvedGraph,\n}\n\nimpl BuildPlan {\n    pub fn create(resolution_graph: ResolvedGraph) -> Result<Self> {\n        let mut sorted_deps = match toposort(&resolution_graph.graph, None) {\n            Ok(nodes) => nodes,\n            Err(err) => {\n                // Is a DAG after resolution otherwise an error should be raised from that.\n                anyhow::bail!(\"IPE: Cyclic dependency found after resolution {:?}\", err)\n            }\n        };\n\n        sorted_deps.reverse();\n\n        Ok(Self {\n            root: resolution_graph.root_package.package.name,\n            sorted_deps,\n            resolution_graph,\n        })\n    }\n\n    pub fn compile<W: Write>(&self, writer: &mut W) -> Result<CompiledPackage> {\n        let package_root = &self.resolution_graph.package_table[&self.root];\n        let project_root = &package_root.package_path;\n        let mut compiled: BTreeMap<PackageName, CompiledPackage> = BTreeMap::new();\n        for package_ident in &self.sorted_deps {\n            let resolved_package = self.resolution_graph.get_package(package_ident);","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/diem/diem/blob/fc4714a8ea273b6efe8b13dbce72ea60aad9a16c/language/tools/move-package/src/compilation/build_plan.rs#L7-L43","documentation":"BuildPlan::create runs a topological sort (petgraph toposort) over the resolved package dependency graph and bails if it contains a cycle. Since resolution should reject cycles earlier, hitting this is flagged as an internal error (IPE = internal programmer error), but it still means the package graph has a circular dependency.","triggerScenarios":"Calling BuildPlan::create with a ResolvedGraph whose `graph` contains a dependency cycle — e.g. package A depends on B and B depends on A.","commonSituations":"Hand-edited Move.toml files creating mutual [dependencies], git dependency pins updated to versions that reference each other, or a bug/edge case in dependency resolution that let a cycle through.","solutions":["Inspect your Move.toml files and remove the circular dependency (A→B and B→A cannot both hold); restructure shared code into a third package","Run `move package update-deps` / re-resolve dependencies after edits so the resolution graph is rebuilt cleanly","Check transitive deps: the cycle may be between dependencies, not your own packages — inspect the cycle nodes listed in the error message","If you believe resolution should have caught this, file a bug with the package manifests; the resolver is expected to reject cycles with a proper error"],"exampleFix":"// before (Move.toml)\n# pkg_a: [dependencies] pkg_b = { local = \"../pkg_b\" }\n# pkg_b: [dependencies] pkg_a = { local = \"../pkg_a\" }\n// after\n# pkg_a: [dependencies] pkg_b = { local = \"../pkg_b\" }\n# pkg_b: (no dependency on pkg_a; move shared types into pkg_common)","handlingStrategy":"validation","validationCode":"// Before creating a build plan, ensure the resolution graph is acyclic:\nuse petgraph::algo::is_cyclic_directed;\nfn ensure_acyclic(graph: &petgraph::graphmap::DiGraphMap<Package, ()>) -> Result<(), String> {\n    if is_cyclic_directed(graph) { Err(\"dependency graph contains a cycle\".into()) } else { Ok(()) }\n}","typeGuard":"fn is_dag(graph: &petgraph::Graph<String, ()>) -> bool {\n    !petgraph::algo::is_cyclic_directed(graph)\n}","tryCatchPattern":"let sorted_deps = toposort(&resolution_graph.graph, None)\n    .map_err(|err| anyhow::anyhow!(\"IPE: Cyclic dependency found after resolution {:?} — check Move.toml for circular [dependencies]\", err))?;","preventionTips":["Never hand-edit [dependencies] into mutual references; factor shared code into a common package","Re-run dependency resolution after manifest edits","Audit transitive deps of third-party packages for cycles","Treat this as a resolver bug if resolution succeeded — report with the manifests"],"tags":["dependency-graph","move-package","topological-sort"],"backgroundTag":"cyclic-dependency","analyzedSha":"fc4714a8ea273b6efe8b13dbce72ea60aad9a16c","analyzedAt":"2026-09-04T21:07:05.890Z","contentChangedAt":"2026-09-04T21:07:05.890Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}