{"record":{"id":"8176b1e641da09a0","repo":"argoproj/argo-workflows","slug":"unable-to-delete-failed-workflows-of-cronworkflow","errorCode":null,"errorMessage":"unable to delete Failed Workflows of CronWorkflow '%s': %w","messagePattern":"unable to delete Failed Workflows of CronWorkflow '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/cron/operator.go","lineNumber":446,"sourceCode":"\t\t}\n\t}\n\n\tworkflowsToKeep := int32(3)\n\tif woc.cronWf.Spec.SuccessfulJobsHistoryLimit != nil && *woc.cronWf.Spec.SuccessfulJobsHistoryLimit >= 0 {\n\t\tworkflowsToKeep = *woc.cronWf.Spec.SuccessfulJobsHistoryLimit\n\t}\n\terr := woc.deleteOldestWorkflows(ctx, successfulWorkflows, int(workflowsToKeep))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to delete Successful Workflows of CronWorkflow '%s': %w\", woc.cronWf.Name, err)\n\t}\n\n\tworkflowsToKeep = int32(1)\n\tif woc.cronWf.Spec.FailedJobsHistoryLimit != nil && *woc.cronWf.Spec.FailedJobsHistoryLimit >= 0 {\n\t\tworkflowsToKeep = *woc.cronWf.Spec.FailedJobsHistoryLimit\n\t}\n\terr = woc.deleteOldestWorkflows(ctx, failedWorkflows, int(workflowsToKeep))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to delete Failed Workflows of CronWorkflow '%s': %w\", woc.cronWf.Name, err)\n\t}\n\treturn nil\n}\n\nfunc (woc *cronWfOperationCtx) deleteOldestWorkflows(ctx context.Context, jobList []v1alpha1.Workflow, workflowsToKeep int) error {\n\tif workflowsToKeep >= len(jobList) {\n\t\treturn nil\n\t}\n\n\tsort.SliceStable(jobList, func(i, j int) bool {\n\t\treturn jobList[i].Status.FinishedAt.After(jobList[j].Status.FinishedAt.Time)\n\t})\n\n\tfor _, wf := range jobList[workflowsToKeep:] {\n\t\terr := woc.wfClient.Delete(ctx, wf.Name, v1.DeleteOptions{})\n\t\tif err != nil {\n\t\t\tif apierrors.IsNotFound(err) {\n\t\t\t\twoc.log.WithField(\"workflow\", wf.Name).Info(ctx, \"Workflow was already deleted\")","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/cron/operator.go#L428-L464","documentation":"Same mechanism as the successful-jobs pruning error but for failed child workflows: the controller keeps spec.failedJobsHistoryLimit failed workflows (default 1) and the deleteOldestWorkflows call failed. The error is wrapped with the CronWorkflow name and returned from enforceHistoryLimit.","triggerScenarios":"A non-NotFound error is returned while deleting the oldest failed workflows of the CronWorkflow during a sync tick — k8s API delete failure, permission denial, or an internal error in the pruning loop.","commonSituations":"Controller RBAC missing workflow delete verbs, failed workflows carrying finalizers, or transient API server errors during heavy load.","solutions":["Read the wrapped cause in the controller log to identify the exact API error","Grant the controller RBAC delete rights on argoproj.io/workflows","Remove blocking finalizers from stale failed workflows","Increase failedJobsHistoryLimit if you simply have too many old failed workflows and want less churn"],"exampleFix":"// before\nspec:\n  failedJobsHistoryLimit: 0   # aggressive pruning, fails loudly on every tick\n// after\nspec:\n  failedJobsHistoryLimit: 3","handlingStrategy":"retry","validationCode":"kubectl auth can-i delete workflows.argoproj.io -n <ns> \\\n  --as=system:serviceaccount:<controller-ns>:workflow-controller","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Grant workflow delete RBAC to the controller's service account","Set failedJobsHistoryLimit explicitly rather than relying on the default","Periodically clean permanently stuck failed workflows to avoid repeated prune errors","Check wrapped cause in logs before assuming a controller bug"],"tags":["kubernetes","cronworkflow","rbac","history-limit","argo-workflows"],"backgroundTag":"workflow-deletion-failed","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"}