{"record":{"id":"d202ee9e16586ed7","repo":"hashicorp/nomad","slug":"deletescalingpolicies-of-removed-policies-failed","errorCode":null,"errorMessage":"DeleteScalingPolicies of removed policies failed: %v","messagePattern":"DeleteScalingPolicies of removed policies failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/state/state_store.go","lineNumber":5774,"sourceCode":"\tnewTargets := map[string]bool{}\n\tfor _, p := range scalingPolicies {\n\t\tnewTargets[p.JobKey()] = true\n\t}\n\t// find existing policies that need to be deleted\n\tdeletedPolicies := []string{}\n\titer, err := s.ScalingPoliciesByJobTxn(ws, job.Namespace, job.ID, txn)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"ScalingPoliciesByJob lookup failed: %v\", err)\n\t}\n\tfor raw := iter.Next(); raw != nil; raw = iter.Next() {\n\t\toldPolicy := raw.(*structs.ScalingPolicy)\n\t\tif !newTargets[oldPolicy.JobKey()] {\n\t\t\tdeletedPolicies = append(deletedPolicies, oldPolicy.ID)\n\t\t}\n\t}\n\terr = s.DeleteScalingPoliciesTxn(index, deletedPolicies, txn)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"DeleteScalingPolicies of removed policies failed: %v\", err)\n\t}\n\n\terr = s.UpsertScalingPoliciesTxn(index, scalingPolicies, txn)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"UpsertScalingPolicies of policies failed: %v\", err)\n\t}\n\n\treturn nil\n}\n\n// updateJobSubmission stores the original job source and variables associated that the\n// job structure originates from. It is up to the job submitter to include the source\n// material, and as such sub may be nil, in which case nothing is stored.\nfunc (s *StateStore) updateJobSubmission(index uint64, sub *structs.JobSubmission, namespace, jobID string, version uint64, txn *txn) error {\n\t// critical that we operate on a copy; the original must not be modified\n\t// e.g. in the case of job gc and its last second version bump\n\tsub = sub.Copy()\n","sourceCodeStart":5756,"sourceCodeEnd":5792,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/state/state_store.go#L5756-L5792","documentation":"Wraps an error from DeleteScalingPoliciesTxn when removing scaling policies whose targets no longer exist in the updated job. Deletion happens inside the same raft transaction as the job update, so any failure aborts the whole registration.","triggerScenarios":"UpsertJob where deletedPolicies is non-empty (job removed a scaling policy block for a task/group) and DeleteScalingPoliciesTxn fails, e.g. memdb delete error or missing row.","commonSituations":"Editing a job to remove scaling policy blocks; failure indicates state store write issues rather than user error.","solutions":["Inspect the wrapped inner error","Resubmit the job; nothing was persisted so retry is safe","If persistent, snapshot/restore the server state"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"DeleteScalingPolicies of removed policies failed\") {\n    // txn aborted atomically; resubmit the job plan\n    return retryJobSubmission(job)\n}","preventionTips":["Retry the full job update rather than partial policy ops","Snapshot server state regularly","Avoid external mutations to Nomad data directories"],"tags":["nomad","state-store","scaling-policies"],"backgroundTag":"state-store-txn-delete-failed","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"}