{"record":{"id":"d045d4b5de99b03c","repo":"hashicorp/nomad","slug":"job-q-in-namespace-q-doesn-t-exist-to-be-deregis","errorCode":null,"errorMessage":"job %q in namespace %q doesn't exist to be deregistered","messagePattern":"job %q in namespace %q doesn't exist to be deregistered","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/fsm.go","lineNumber":917,"sourceCode":"\t\t\treturn fmt.Errorf(\"DeleteJob failed: %w\", err)\n\t\t}\n\n\t\t// We always delete from the periodic launch table because it is possible that\n\t\t// the job was updated to be non-periodic, thus checking if it is periodic\n\t\t// doesn't ensure we clean it up properly.\n\t\tn.state.DeletePeriodicLaunchTxn(index, namespace, jobID, tx)\n\t\treturn nil\n\t}\n\n\t// Get the current job and mark it as stopped and re-insert it.\n\tws := memdb.NewWatchSet()\n\tcurrent, err := n.state.JobByIDTxn(ws, namespace, jobID, tx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"JobByID lookup failed: %w\", err)\n\t}\n\n\tif current == nil {\n\t\treturn fmt.Errorf(\"job %q in namespace %q doesn't exist to be deregistered\", jobID, namespace)\n\t}\n\n\tstopped := current.Copy()\n\tstopped.Stop = true\n\tif submitTime != 0 {\n\t\tstopped.SubmitTime = submitTime\n\t}\n\n\t// Disable scaling policies to avoid monitoring stopped jobs\n\tscalingPolicies := stopped.GetScalingPolicies()\n\tfor _, policy := range scalingPolicies {\n\t\tpolicy.Enabled = false\n\t}\n\n\tif err := n.state.UpsertJobTxn(index, nil, stopped, tx); err != nil {\n\t\treturn fmt.Errorf(\"UpsertJob failed: %w\", err)\n\t}\n","sourceCodeStart":899,"sourceCodeEnd":935,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/fsm.go#L899-L935","documentation":"When deregistering a job, the FSM looks up the current job to mark it stopped. If the job does not exist at all (JobByIDTxn returns nil, nil), it returns this explicit 'doesn't exist to be deregistered' error. The deregistration apply fails because there is nothing to stop.","triggerScenarios":"handleJobDeregister receives a deregistration for a namespace/jobID with no job record — e.g. duplicate deregistration, deregister sent to the wrong namespace, or the job was already purged.","commonSituations":"Double-submitting a job stop via API/UI, deregistering with a wrong --namespace flag, automation that lost track of whether the job was already removed, and jobs already purged with purge=true earlier.","solutions":["Verify the job ID and namespace: `nomad job status -namespace <ns> <jobID>`; correct the namespace if wrong.","Treat this as idempotent success if the desired end state is 'job gone' — the job is already deregistered.","Check whether the job was already purged earlier; re-register the job if it should exist.","Fix automation/tooling to only deregister jobs it owns or to check existence first."],"exampleFix":"// before\n_, _, err := client.Jobs().Deregister(jobID, false, nil)\n// after\nq := &nomad.QueryOptions{Namespace: ns}\nif _, _, err := client.Jobs().Info(jobID, q); err == nil {\n    _, _, err = client.Jobs().Deregister(jobID, false, q)\n}","handlingStrategy":"validation","validationCode":"q := &nomad.QueryOptions{Namespace: ns}\nif _, _, err := client.Jobs().Info(jobID, q); err != nil {\n    // job does not exist in this namespace; nothing to deregister\n    return nil\n}","typeGuard":"func jobExists(client *nomad.Client, ns, jobID string) bool {\n    _, _, err := client.Jobs().Info(jobID, &nomad.QueryOptions{Namespace: ns})\n    return err == nil\n}","tryCatchPattern":"err := deregister(jobID)\nif err != nil && strings.Contains(err.Error(), \"doesn't exist to be deregistered\") {\n    // treat as idempotent success\n}","preventionTips":["Always pass the correct --namespace when deregistering","Check job existence before deregister in scripts","Make deregistration flows idempotent"],"tags":["nomad","raft","fsm","job-not-found"],"backgroundTag":"job-not-found","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"}