{"record":{"id":"1ee133777d972342","repo":"hashicorp/nomad","slug":"namespace-q-contains-at-least-one-non-terminal-jo","errorCode":null,"errorMessage":"namespace %q contains at least one non-terminal job %q. All jobs must be terminal in namespace before it can be deleted","messagePattern":"namespace %q contains at least one non-terminal job %q\\. All jobs must be terminal in namespace before it can be deleted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/state/state_store.go","lineNumber":7145,"sourceCode":"\t\tif ns.Name == structs.DefaultNamespace {\n\t\t\treturn fmt.Errorf(\"default namespace can not be deleted\")\n\t\t}\n\n\t\t// Ensure that the namespace doesn't have any non-terminal jobs\n\t\titer, err := s.jobsByNamespaceImpl(nil, name, txn, SortDefault)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tfor {\n\t\t\traw := iter.Next()\n\t\t\tif raw == nil {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tjob := raw.(*structs.Job)\n\n\t\t\tif job.Status != structs.JobStatusDead {\n\t\t\t\treturn fmt.Errorf(\"namespace %q contains at least one non-terminal job %q. \"+\n\t\t\t\t\t\"All jobs must be terminal in namespace before it can be deleted\", name, job.ID)\n\t\t\t}\n\t\t}\n\n\t\tvIter, err := s.csiVolumesByNamespaceImpl(txn, nil, name, \"\")\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\trawVol := vIter.Next()\n\t\tif rawVol != nil {\n\t\t\tvol := rawVol.(*structs.CSIVolume)\n\t\t\treturn fmt.Errorf(\"namespace %q contains at least one CSI volume %q. \"+\n\t\t\t\t\"All CSI volumes in namespace must be deleted before it can be deleted\", name, vol.ID)\n\t\t}\n\n\t\tvarIter, err := s.getVariablesByNamespaceImpl(txn, nil, name)\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":7127,"sourceCodeEnd":7163,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/state/state_store.go#L7127-L7163","documentation":"DeleteNamespace refuses to remove a namespace that still contains at least one job whose status is not \"dead\". Nomad requires every job in the namespace to be terminal before the namespace can be deleted, and the error names the offending job ID.","triggerScenarios":"DELETE /v1/namespace/<name> (or `nomad namespace delete`) while any job in that namespace is pending/running; only dead jobs are acceptable.","commonSituations":"Deleting a namespace during tenant offboarding while periodic/system jobs still live there; a job stuck in pending preventing cleanup; forgotten parameterized/dispatched jobs.","solutions":["Stop all jobs in the namespace (`nomad job stop -namespace <ns> <job>`) and wait for status to become dead, then retry deletion.","Purge stopped jobs with `nomad job stop -purge` to clear them, then delete the namespace.","Identify the job named in the error and inspect why it is non-terminal (e.g., periodic or system jobs must be disabled/purged first)."],"exampleFix":"# before\nnomad namespace delete team-a\n# after\nnomad job stop -namespace team-a -purge <job-id>\nnomad namespace delete team-a","handlingStrategy":"validation","validationCode":"jobs, _, _ := client.Jobs().List(&nomad.QueryOptions{Namespace: ns})\nfor _, j := range jobs {\n    if j.Status != \"dead\" {\n        return fmt.Errorf(\"job %s in %s is %s; stop it first\", j.ID, ns, j.Status)\n    }\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"non-terminal job\") {\n    // extract job ID from the message and stop/purge it before retrying\n}","preventionTips":["Stop and purge all jobs (including periodic/system jobs) before deleting a namespace.","Automate namespace teardown: stop jobs, wait for dead, purge, then delete."],"tags":["nomad","state-store","namespace","job-lifecycle"],"backgroundTag":"namespace-not-empty","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}