{"record":{"id":"ef3bd9e281b78b3b","repo":"hashicorp/nomad","slug":"scalingpoliciesbyjob-lookup-failed-v","errorCode":null,"errorMessage":"ScalingPoliciesByJob lookup failed: %v","messagePattern":"ScalingPoliciesByJob lookup failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/state/state_store.go","lineNumber":5764,"sourceCode":"\treturn nil\n}\n\n// updateJobScalingPolicies upserts any scaling policies contained in the job and removes\n// any previous scaling policies that were removed from the job\nfunc (s *StateStore) updateJobScalingPolicies(index uint64, job *structs.Job, txn *txn) error {\n\n\tws := memdb.NewWatchSet()\n\n\tscalingPolicies := job.GetScalingPolicies()\n\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","sourceCodeStart":5746,"sourceCodeEnd":5782,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/state/state_store.go#L5746-L5782","documentation":"Wraps an error from ScalingPoliciesByJobTxn while reconciling scaling policies during job update. It means the memdb iterator over scaling policies for the job's namespace/ID failed. Without this lookup Nomad cannot determine which existing policies to delete.","triggerScenarios":"UpsertJob (job update with scaling policy reconciliation) when ScalingPoliciesByJobTxn returns a memdb lookup/iteration error for the job's namespace and ID.","commonSituations":"Internal memdb read failure during job submission with scaling policy blocks; rare, tied to state store health.","solutions":["Check the wrapped inner error for the memdb cause","Retry the job submission; the raft txn aborted atomically","Verify scaling policy table health via Nomad operator debug/endpoint if recurring"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"ScalingPoliciesByJob lookup failed\") {\n    // nothing persisted; resubmit job\n    return retryWithBackoff(func() error { _, _, err := jobs.Register(job, nil); return err })\n}","preventionTips":["Keep scaling policy blocks well-formed in job specs","Retry job submissions on server-side state errors","Monitor server health before bulk job updates"],"tags":["nomad","state-store","scaling-policies"],"backgroundTag":"state-store-txn-lookup-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"}