{"record":{"id":"08dd4128bd8e28cc","repo":"argoproj/argo-workflows","slug":"dependency-cycle-detected-s-s","errorCode":null,"errorMessage":"dependency cycle detected: %s->%s","messagePattern":"dependency cycle detected: (.+?)->(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apis/workflow/v1alpha1/validation_utils.go","lineNumber":90,"sourceCode":"}\n\n// validateNoCycles validates that a dependency graph has no cycles by doing a Depth-First Search\n// depGraph is an adjacency list, where key is a node name and value is a list of its dependencies' names\nfunc validateNoCycles(depGraph map[string][]string) error {\n\tvisited := make(map[string]bool)\n\tvar noCyclesHelper func(currentName string, cycyle []string) error\n\tnoCyclesHelper = func(currentName string, cycle []string) error {\n\t\tif _, ok := visited[currentName]; ok {\n\t\t\treturn nil\n\t\t}\n\t\tdepNames, ok := depGraph[currentName]\n\t\tif !ok {\n\t\t\treturn nil\n\t\t}\n\t\tfor _, depName := range depNames {\n\t\t\tfor _, name := range cycle {\n\t\t\t\tif depName == name {\n\t\t\t\t\treturn fmt.Errorf(\"dependency cycle detected: %s->%s\", strings.Join(cycle, \"->\"), name)\n\t\t\t\t}\n\t\t\t}\n\t\t\tcycle = append(cycle, depName)\n\t\t\terr := noCyclesHelper(depName, cycle)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tcycle = cycle[0 : len(cycle)-1]\n\t\t}\n\t\tvisited[currentName] = true\n\t\treturn nil\n\t}\n\tnames := make([]string, 0)\n\tfor name := range depGraph {\n\t\tnames = append(names, name)\n\t}\n\t// sort names here to make sure the error message has consistent ordering\n\t// so that we can verify the error message in unit tests","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/pkg/apis/workflow/v1alpha1/validation_utils.go#L72-L108","documentation":"validateNoCycles performs a DFS over the template dependency graph (an adjacency list of template/step names to their dependencies). It returns this error when following dependencies leads back to a node already on the current path, i.e. the graph contains a cycle, which would make scheduling impossible.","triggerScenarios":"Submitting or validating a Workflow whose templates' `dependencies` fields form a loop, e.g. A depends on B and B depends on A; triggered via Validate / DAG validation whenever noCyclesHelper finds a depName already present in the current cycle path.","commonSituations":"Hand-editing dependencies in a large DAG; auto-generated DAGs where an index off-by-one wraps around; adding a new edge that accidentally closes a loop.","solutions":["Read the cycle from the error message (A->B->...->A) and remove or reverse one dependency edge","Draw the DAG and check for the reported loop before adding new dependencies","Refactor the cyclic group by splitting one template so the dependency is one-directional"],"exampleFix":"# before\nA:\n  dependencies: [B]\nB:\n  dependencies: [A]\n# after\nA: {}\nB:\n  dependencies: [A]","handlingStrategy":"validation","validationCode":"func hasCycle(graph map[string][]string) bool {\n    var visit func(string, []string) bool\n    visit = func(n string, path []string) bool {\n        for _, p := range path {\n            if p == n { return true }\n        }\n        for _, d := range graph[n] {\n            if visit(d, append(path, n)) { return true }\n        }\n        return false\n    }\n    for n := range graph {\n        if visit(n, nil) { return true }\n    }\n    return false\n}","typeGuard":"null","tryCatchPattern":"if err := wf.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"dependency cycle detected\") {\n        cycle := strings.TrimPrefix(err.Error(), \"dependency cycle detected: \")\n        log.Printf(\"fix DAG cycle: %s\", cycle)\n    }\n    return err\n}","preventionTips":["Keep dependency edges strictly forward-ordered by design","Validate DAGs in CI with argo lint","Reject auto-generated edges that point backwards"],"tags":["validation","dag","dependency-cycle"],"backgroundTag":"dependency-cycle-detected","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}